电报机器人向自己发送消息但不在公共组中 [英] Telegram bot sending message to itself but not in a public group

查看:53
本文介绍了电报机器人向自己发送消息但不在公共组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I made a telegram bot with @botfather and promoted the bot as admin of the public group. Whenever I try to send a message from the python code, it always sends the message to itself, I mean in the private chat and not in the public group.

所写代码的快照:

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

如何让聊天机器人在群内发送消息,而不是发送给自己?

How can I make the bot to send the message in the group, not to itself?

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

Am I missing something here or do I need to modify some settings?

EDIT(已解决): 聊天组始终为负数.查找该号码以获取该组的聊天 ID.

EDIT(Solved) : Chat group is always a negative number. Look for that number to get the chat id of that group.

推荐答案

您应该向群组 chat_id 发送消息.您似乎正在向您的机器人本身或您自己发送消息.为什么?因为组或超组的chat_id- 负号开头.例如:-1001331798505 是我超级组chat_id.

You should send message to the group chat_id. It seems you are sending message to your bot itself or yourself. why? because chat_id of group or supergroup starts with - negative sign. for example : -1001331798505 is chat_id of my supergroup.

  "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,您可以阅读此 链接

if you don't know how get ID of your groups you can read this link

这篇关于电报机器人向自己发送消息但不在公共组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆