属性错误: 'TeleBot'对象没有属性'chat'



我想创建一个变量,message.chat.id函数外例如像这样

bot = telebot.teleBot("token")
global message
message = bot.message.chat.id
@bot.message_handler(commands=["start"])
def welcome():
bot.send_message(message,"Welcome on here, pls describe yourself")

但是telebot属性错误消息参数是否总是必须在函数内部,不能在函数外部才能成为变量?

我认为这将是更合适的代码

bot = telebot.teleBot("token")
global message
message = message.chat.id
@bot.message_handler(commands=["start"])
def welcome(message):
global message
bot.send_message(message,"Welcome on here, pls describe yourself")

或者只使用bot.reply_to(消息,"Hello Bros"(您可以在这里找到完整的文档

最新更新