When I run this code:
from telegram.ext import *
import keys
print('Starting a bot....')
def start_commmand(update, context):
update.message.reply_text('Hello! Welcome To Store!')
if __name__ == '__main__':
updater = Updater(keys.token, True)
dp = updater.dispatcher
# Commands
dp.add.handler(CommandHandler('start', start_commmand))
# Run bot
updater.start_polling(1.0)
updater.idle()
I get this error:
Traceback (most recent call last):
File "C:UserspcPycharmProjectstelegrammain.py", line 11, in <module>
dp = updater.dispatcher
AttributeError: 'Updater' object has no attribute 'dispatcher'
I attempted to resolve this issue by updating the library but the error remained.
2
Answers
You probably found an example for v13, but since a few days the v20 for python-telegram-bot is out. Now you have to build your application differently and you have to use async functions.
This should work:
Also, here are some good examples for the python-telegram-bot library.
Check recent changelogs I found a bug fix for versions >= 20.0a0 where dispatcher is no longer used, but if you want to run your script in that version you need to install it
pip install python-telegram-bot==13.3