简体   繁体   English

使用 Python Telethon 向电报聊天发送消息时出错

[英]Error when sending a message to telegram chat using Python Telethon

from telethon import TelegramClient


client = TelegramClient('anon', api_id, api_hash)
async def main():
    await client.send_message(chat_id, 'Hello')


with client:
    client.loop.run_until_complete(main())

When I try to run the code I get an error:当我尝试运行代码时出现错误:

telethon.errors.rpcerrorlist.ChatIdInvalidError: Invalid object ID for a chat. telethon.errors.rpcerrorlist.ChatIdInvalidError:聊天的 object ID 无效。 Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels.确保传递正确的类型,例如确保请求是为聊天(而不是频道/巨型组)设计的,或者寻找更合适的其他类型\n使用巨型组和 AddChatUserRequest 的示例,它将失败,因为巨型组是渠道。 Use InviteToChannelRequest instead (caused by SendMessageRequest)改用 InviteToChannelRequest(由 SendMessageRequest 引起)

Chat's ID is correct, I checked.聊天的ID是正确的,我检查了。 What could be the problem?可能是什么问题呢?

yes you have to confirm from your chat id and make sure you passed the correct id of your chat.是的,您必须从您的聊天 ID 进行确认,并确保您传递了正确的聊天 ID。 you can use "@_Chat_ID" or use "htttp//t.me/Chat_link"您可以使用“@_Chat_ID”或使用“htttp//t.me/Chat_link”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM