![](/img/trans.png)
[英]Python telegram bot - can the bot send the first message in chat?
[英]Send a message on telegram: "Forbidden: bot is not a member of the supergroup chat" or "Forbidden: bot is not a member of the channel chat"
我正在尝试通过电报聊天发送消息。 我希望仅使用官方 UI 完成电报设置,因为我希望它可能由最终用户完成。
这是我做的电报设置:
XXXXXXX_bot
:没问题TestChannel
XXXXXXX_bot
TestChannel
TestChannelChat
TestChannelChat
XXXXXXX_bot
这是频道管理员的设置:
在一天结束时,聊天/群组的设置在电报 UI 中如下所示:
我拨打了以下 http 电话:
GET https://api.telegram.org/botXXXXXXTOKENXXXXXXX/sendMessage?chat_id=@TestChannelChat&text=coucou
这给了我以下答案:
{
"ok": false,
"error_code": 403,
"description": "Forbidden: bot is not a member of the supergroup chat"
}
我还做了以下(绕过实际聊天,直接在频道中发布消息):
GET https://api.telegram.org/botXXXXXXTOKENXXXXXXX/sendMessage?chat_id=@TestChannel&text=coucou
这给了我以下答案:
{
"ok": false,
"error_code": 403,
"description": "Forbidden: bot is not a member of the channel chat"
}
一个简单的问题,作为一个机器人也意味着广播消息,我错过了它的设置的哪一部分?
您在使用 Telegram 机器人方面处于正确的轨道上。 但首先要了解chat_id
。
chat_id
是聊天用户名或聊天ID 。 您只能为公共聊天/群组设置用户名。 在您的情况下,您有一个私人组,并且没有用户名。 您传递给chat_id
的@TestChannelChat
值不属于您的聊天。 您必须传递聊天的id
或设置公共用户名并传递它。
如果您不知道如何查看聊天id
,请阅读此处: https://stackoverflow.com/a/38388851/10359385
用于发送帖子/消息您的私人聊天:
@dispatcher.message_handler(chat_type=[ChatType.SUPERGROUP])
async def send_chat_msg(message: types.Message):
await bot.send_message(f'Message in your private chat ', reply_markup=markup)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.