繁体   English   中英

电报群聊 ID 不适用于机器人

[英]Telegram group chat id not working for bot

我正在尝试使用pyTelegrambotApi构建一个电报机器人。 但是我在从机器人发送消息时遇到错误。 代码如下。

import telebot

@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
 
  bot.send_message(ID,"Thanks for adding me!!")

bot.infinity_polling()

这里的 ID 是我在类似问题中提到的使用 rawdatabot 获得的 id。 但这里的问题是它只响应我的命令。 当其他成员发出相同的命令时,该机器人不适用于其他成员。 有人可以在这里指出错误吗?

而不是 ID,使用message.chat.id它自动定义聊天 ID。 这意味着机器人会回复其所在位置的请求。

import telebot
from telebot.types import Message

bot = telebot.TeleBot('TOKEN')

@bot.message_handler(commands=['start', 'help'])
def send_welcome(message: Message):
  bot.send_message(message.chat.id, "Thanks for adding me!!")

bot.infinity_polling()

暂无
暂无

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

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