首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:'TeleBot‘对象没有属性'chat’

AttributeError:'TeleBot‘对象没有属性'chat’
EN

Stack Overflow用户
提问于 2022-02-21 14:37:04
回答 1查看 234关注 0票数 1

--我想要创建一个变量,函数之外的message.chat.id,例如,如下所示的

代码语言:javascript
复制
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属性错误--消息参数总是必须在函数内部吗?它不能在函数之外成为变量吗?

EN

回答 1

Stack Overflow用户

发布于 2022-11-10 15:06:13

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

代码语言:javascript
复制
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(message,"Hello“),您可以找到完整的docs 这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71208123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档