简体   繁体   English

python-telegram-bot 中的错误

[英]Eror in python-telegram-bot

I tried to create a bot in telegram with python, but it doesnt work.我试图用 python 在电报中创建一个机器人,但它不起作用。 My code is below:我的代码如下:

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

And There is a error from error_log decorator:并且 error_log 装饰器有一个错误:

No error handlers are registered, logging exception.没有注册错误处理程序,记录异常。 Traceback (most recent call last): File "c:\users\Parsa\anaconda3\lib\site-packages\telegram\ext\dispatcher.py", line 442, in process_update handler.handle_update(update, self, check, context) File "c:\users\Parsa\anaconda3\lib\site-packages\telegram\ext\handler.py", line 160, in handle_update return self.callback(update, context) File "", line 4, in start chat_id = update.message.chat_id AttributeError: 'CallbackContext' object has no attribute 'message'回溯(最近一次调用):文件“c:\users\Parsa\anaconda3\lib\site-packages\telegram\ext\dispatcher.py”,第 442 行,在 process_update handler.handle_update(update, self, check, context ) 文件“c:\users\Parsa\anaconda3\lib\site-packages\telegram\ext\handler.py”,第 160 行,在 handle_update return self.callback(update, context) 文件“”,第 4 行,在 start chat_id = update.message.chat_id AttributeError: 'CallbackContext' object has no attribute 'message'

What should Ido?我应该怎么办?

I think you have the definition of start wrong.我认为你有开始错误的定义。 Try this:尝试这个:

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

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

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