Search code examples
pythontelegramtelegram-botpython-telegram-bot

How to fix "_init__() got an unexpected keyword argument 'token'" error when using Updater class of python-telegram-bot?


I've been working on a Telegram bot using python for a while and everything was fine, but today I was starting to work on a new project but I got a lot of errors. So, I uninstalled it and installed it again and I tried a simple code like this below:

from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, filters, CallbackContext, ConversationHandler
from telegram import KeyboardButton

def main():
       
    updater = Updater(token="5934903868:AAGckQGHTbYwpAwdqGh9o5Zs2Hfdcb1PyZs")
    dispatcher = updater.dispatcher
    dispatcher.add_handler(CommandHandler('start', startCommand))
    updater.start_polling()
    updater.idle() 

if __name__ == '__main__':
    main() 

but I keep getting this error:

init_() got an unexpected keyword argument 'token'


Solution

  • It appears that you are currently utilizing version <=13.15 of the python-telegram-bot library. It's worth noting that this library has undergone significant changes in version 20.0. To ensure compatibility and access to new features, it's recommended to upgrade to version 20.0 by reviewing the release notes and the transition guide. If you wish to continue using your existing code, you can install version 13.15 via pip install python-telegram-bot==13.15. However, please be aware that this version is outdated and will no longer receive official support or bug fixes in the future. If you're starting a new project, it is suggested to use version 20.0.