如何解决如何使用 Telethon 向我的频道发送消息
我正在尝试让我的 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 现在这对我来说真的是个大问题。
解决方法
首先测试您是否可以向另一个频道或用户发送消息。如果不能,则必须共享所有代码。
然后确保您在这种情况下使用的帐户是频道中的管理员。如果帐户是管理员,则不可能收到此错误。 还要检查管理员权限并确保启用发布消息。
在两者之间,使用频道用户名或频道数字 ID 代替“我的频道名称”。频道数字 ID 以 -100
开头,如 -1001212229355
。你最好使用数字ID。要找到这个,只需将您的一条频道消息转发到 https://t.me/userinfobot。
await client.send_message(entity='my channel name',message=message)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。