Telegram 机器人向自己发送消息但不在 public 组中
Telegram bot sending message to itself but not in a public group
我用@botfather 制作了一个电报机器人,并将该机器人提升为 public 组的管理员。每当我尝试从 python 代码发送消息时,它总是将消息发送给自己,我的意思是在私人聊天中而不是在 public 组中。
所写代码的快照:
bot_token = 'XXXXXXXXXXXXXXXXXXX'
bot_chatID = '395014927'
bot_message = "Testing"
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&text=' + bot_message
response = requests.get(send_text)
response.json()
如何让机器人在群组中发送消息,而不是发送给它自己?
我是不是遗漏了什么或者我需要修改一些设置?
编辑(已解决): 聊天组始终为负数。查找该号码以获取该组的聊天 ID。
您应该向群组 chat_id
发送消息。看来您正在向您的机器人本身或您自己发送消息。为什么?因为组或超组的 chat_id
以 -
负号开头。例如:-1001331798505
是我的 超级组 的 chat_id
。
"ok": true,
"result": [{
"update_id": 751829615,
"message": {
"message_id": 5968,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "\u011e\u0105me",
"last_name": "\u01fever!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": -257326110,
"title": "This group is not Super Group",
"type": "group",
"all_member s_are_administrators": true
},
如你所见type:group
这是超群
的一个例子
{
"ok": true,
"result": [{
"update_id": 751829616,
"message": {
"message_id": 141,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "\u011e\u0105me",
"last_name": "\u01fever!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": -1001241538300,
"title": "this groups is supergroup",
"type": "supergroup"
},
"date": 1568644531,
"text": "A"
}
}]
}
如你所见type:supergroup
如果您不知道如何获取您的组的 ID,您可以阅读这篇文章link
我用@botfather 制作了一个电报机器人,并将该机器人提升为 public 组的管理员。每当我尝试从 python 代码发送消息时,它总是将消息发送给自己,我的意思是在私人聊天中而不是在 public 组中。
所写代码的快照:
bot_token = 'XXXXXXXXXXXXXXXXXXX'
bot_chatID = '395014927'
bot_message = "Testing"
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&text=' + bot_message
response = requests.get(send_text)
response.json()
如何让机器人在群组中发送消息,而不是发送给它自己?
我是不是遗漏了什么或者我需要修改一些设置?
编辑(已解决): 聊天组始终为负数。查找该号码以获取该组的聊天 ID。
您应该向群组 chat_id
发送消息。看来您正在向您的机器人本身或您自己发送消息。为什么?因为组或超组的 chat_id
以 -
负号开头。例如:-1001331798505
是我的 超级组 的 chat_id
。
"ok": true,
"result": [{
"update_id": 751829615,
"message": {
"message_id": 5968,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "\u011e\u0105me",
"last_name": "\u01fever!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": -257326110,
"title": "This group is not Super Group",
"type": "group",
"all_member s_are_administrators": true
},
如你所见type:group
这是超群
的一个例子 {
"ok": true,
"result": [{
"update_id": 751829616,
"message": {
"message_id": 141,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "\u011e\u0105me",
"last_name": "\u01fever!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": -1001241538300,
"title": "this groups is supergroup",
"type": "supergroup"
},
"date": 1568644531,
"text": "A"
}
}]
}
如你所见type:supergroup
如果您不知道如何获取您的组的 ID,您可以阅读这篇文章link