TypeError when initializing Updater in python-telegram-bot v20.0 - missing update_queue parameter

I’m encountering an unexpected error while trying to start my Discord bot with the latest version 20 of the python-telegram-bot library. The error message implies that an update_queue argument is missing, but I’m not certain what has changed in the latest version.

Here’s the error message that keeps appearing:

Traceback (most recent call last):
File "/home/user/projects/chatbot/main.py", line 89, in <module>
run_bot()
File "/home/user/projects/chatbot/main.py", line 82, in run_bot
botUpdater = Updater("BOT-API-KEY")
TypeError: __init__() missing 1 required positional argument: 'update_queue'

My current code looks like this:

def run_bot():
    # Setup database connection
    database = sqlite3.connect('user_data.db')
    cursor = database.cursor()
    cursor.execute("""CREATE TABLE IF NOT EXISTS messages (
                        user_id INTEGER,
                        content TEXT,
                        timestamp TIMESTAMP
                    )""")
    cursor.execute("""CREATE TABLE IF NOT EXISTS blocked_users (
                        user_id INTEGER
                    )""")
    database.commit()
    database.close()

    # List of admin user IDs
    admin_list = [123456789, 987654321]

    # Initialize bot updater and handlers
    botUpdater = Updater("API_TOKEN", use_context=True)
    dispatcher = botUpdater.dispatcher
    dispatcher.add_handler(CommandHandler("help", show_help))
    dispatcher.add_handler(CommandHandler("save", save_message))
    dispatcher.add_handler(CommandHandler("block", block_user))
    botUpdater.start_polling()
    botUpdater.idle()

This code worked well in previous versions, but now it throws this error. What steps should I take to resolve this?

btw uninstall the old version first - mixed installs cause issues for some people. Had this exact problem last week. Did pip uninstall python-telegram-bot then reinstalled v20. Also check your imports - they moved stuff around in the new version so imports might break even after switching to Application.

You’re encountering this issue because python-telegram-bot v20 has completely redesigned the Updater class, which no longer accepts a token string. Instead, you should use Application. Here’s how you can fix your code:

from telegram.ext import Application, CommandHandler

def run_bot():
    # Your database setup code remains unchanged
    
    # Create an Application instance
    application = Application.builder().token("API_TOKEN").build()
    
    # Add handlers directly to the application
    application.add_handler(CommandHandler("help", show_help))
    application.add_handler(CommandHandler("save", save_message))
    application.add_handler(CommandHandler("block", block_user))
    
    # Start the bot
    application.run_polling()

Also, note that the use_context=True parameter is no longer required since context is enabled by default in v20. Ensure you update your handler functions accordingly if they rely on the previous context structure.

Yeah, this is a super common issue when jumping from v13 to v20. The architecture got completely overhauled and the old Updater class constructor just doesn’t work anymore. You’ll need to switch to Application like others mentioned, but there’s more to it. All your handler functions need to be rewritten for the new async/await pattern v20 uses. Make your handlers async and throw await in front of any bot operations. So if you’ve got context.bot.send_message() in your show_help function, it needs to be await context.bot.send_message(). It’s a pain to migrate but v20 runs way better once you get everything sorted.