【问题标题】:Telegram bot sending message to itself but not in a public group电报机器人向自己发送消息但不在公共组中
【发布时间】:2020-01-16 20:38:43
【问题描述】:

我用@botfather 制作了一个电报机器人,并将该机器人提升为公共组的管理员。每当我尝试从 python 代码发送消息时,它总是将消息发送给自己,我的意思是在私人聊天中而不是在公共组中。

编写代码的快照:

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()

如何让机器人在群组中发送消息,而不是发送给它自己?

我在这里遗漏了什么还是需要修改一些设置?

EDIT(Solved) : 聊天组始终为负数。查找该号码以获取该组的聊天 ID。

【问题讨论】:

    标签: python telegram telegram-bot


    【解决方案1】:

    您应该向群组chat_id 发送消息。您似乎正在向您的机器人本身或您自己发送消息。为什么?因为组或超组的chat_id- 负号开头。例如:-1001331798505 是我的 supergroupchat_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

    这是supergroup

    的一个例子
     {
       "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

    【讨论】:

    • 谢谢。问题在于聊天 ID。现在工作正常。再次感谢。
    • 很高兴能帮上忙 ^_^
    猜你喜欢
    • 2017-05-11
    • 2022-01-27
    • 2017-03-19
    • 2016-03-11
    • 1970-01-01
    • 2019-03-13
    • 2017-09-01
    • 2016-05-03
    • 2020-08-25
    相关资源
    最近更新 更多