【发布时间】:2021-04-11 18:08:33
【问题描述】:
我正在尝试让我的 python 脚本向我的私人频道发送消息,但我收到此错误。
telethon.errors.rpcerrorlist.ChatWriteForbiddenError:你不能在这个聊天中写信(由SendMessageRequest引起)
我只是该频道的管理员,这是我用于发送消息的代码,当我尝试向自己发送消息时,它工作正常..
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
api_id = 'my api id'
api_hash = 'my api hash'
phone = 'my number'
username = 'my username'
# Create the client and connect
client = TelegramClient(username, api_id, api_hash)
client.start()
print("Client Created")
# Ensure you're authorized
if not client.is_user_authorized():
client.send_code_request(phone)
try:
client.sign_in(phone, input('Enter the code: '))
except SessionPasswordNeededError:
client.sign_in(password=input('Password: '))
async def send_mess(message):
await client.send_message(entity='my channel name', message=message)
while True:
some other code
if last_message != new_message:
with client:
client.loop.run_until_complete(send_mess(message=new_message))
last_message = new_message
我是否需要更改某些内容才能对我的脚本拥有管理员权限,或者问题出在哪里?我会为每一个答案感到高兴。给我一些好的示例代码:D 这对我来说真的是个大问题。
【问题讨论】:
-
三重检查这是您期望的聊天,并且是您期望的聊天机器人帐户
标签: python telegram telegram-bot python-telegram-bot telethon