Reputation: 23
I have a problem after transfer my tg-bot to new server. Absolutely no idea why I have error. It seems like I lost some python packets to install. In old server with identical parameters of OS I haven't any problems with this bot.
Sorry if my mistake childish. I try to google my error and haven't answers.
Code1:
def start(bot, update):
if update.message.from_user.username == AAA:
bot.sendMessage(chat_id=update.message.chat_id, text="Text_one")
else:
bot.sendMessage(chat_id=update.message.chat_id, text="Text_two")
...
updater = Updater(token=bot_token)
start_handler = CommandHandler('start', start)
updater.dispatcher.add_handler(start_handler)
Error1:
File "/usr/local/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 425, in process_update handler.handle_update(update, self, check, context)
File "/usr/local/lib/python3.7/site-packages/telegram/ext/handler.py", line 145, in handle_update return self.callback(update, context)
File "./bot.py", line 43, in start
if update.message.from_user.username == AAA:
AttributeError: 'CallbackContext' object has no attribute 'message'
Code2:
def rating(bot, update):
bot.send_sticker(chat_id,'some_sticker_id')
...
rating_handler = CommandHandler('rating', rating)
updater.dispatcher.add_handler(rating_handler)
Error2:
File "/usr/local/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 425, in process_update handler.handle_update(update, self, check, context)
File "/usr/local/lib/python3.7/site-packages/telegram/ext/handler.py", line 145, in handle_update return self.callback(update, context)
File "./bot.py", line 108, in rating
bot.send_sticker(chat_id, 'some_sticker_id')
AttributeError: 'Update' object has no attribute 'send_sticker'
Upvotes: 2
Views: 7983
Reputation: 13923
The handler signature is not correct:
def start(update, context):
context.bot.sendMessage(chat_id=update.message.chat_id, 'Text One')
updater.dispatcher.add_handler(CommandHandler('start', start))
Upvotes: 7