I tried to create a bot in telegram with python, but it doesnt work. 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:
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'
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()