python电报机器人中的Eror
我试图用python在telegram中创建一个机器人,但它不起作用。我的代码如下:python电报机器人中的Eror,python,bots,telegram,telegram-bot,python-telegram-bot,Python,Bots,Telegram,Telegram Bot,Python Telegram Bot,我试图用python在telegram中创建一个机器人,但它不起作用。我的代码如下: from telegram.ext import Updater, CommandHandler updater = Updater(Token) def start(bot,update) : chat_id = update.message.chat_id bot.sendMessage(chat_id, 'Hello') start_command = CommandHandler('st
from telegram.ext import Updater, CommandHandler
updater = Updater(Token)
def start(bot,update) :
chat_id = update.message.chat_id
bot.sendMessage(chat_id, 'Hello')
start_command = CommandHandler('start' , start)
updater.dispatcher.add_handler(start_command)
updater.start_polling()
updater.idle()
错误日志装饰器中有一个错误:
未注册任何错误处理程序,记录异常。回溯(most)
最近调用(最后一次):文件
“c:\users\Parsa\anaconda3\lib\site packages\telegram\ext\dispatcher.py”,
第442行,正在更新
handler.handle\u更新(更新、自我、检查、上下文)文件“c:\users\Parsa\anaconda3\lib\site packages\telegram\ext\handler.py”,
第160行,在handle_update中
在开始处返回self.callback(更新,上下文)文件“”,第4行
chat\u id=update.message.chat\u id AttributeError:'CallbackContext'对象没有属性'message'
我该怎么办?我想你对开始错误的定义是正确的。试试这个:
from telegram.ext import Updater, CommandHandler
updater = Updater(Token)
def start(update, _) :
update.message.reply_text('Hello')
start_command = CommandHandler('start' , start)
updater.dispatcher.add_handler(start_command)
updater.start_polling()
updater.idle()
错误消息告诉您,
更新程序
实例更新
,没有属性消息
:更新。消息
不存在。根据教程,在update.effective\u chat.id
上有一个聊天id。谢谢你,我还有一个问题。如何找到其他方法的聊天室id
?