TypeError with Updater initialization in python-telegram-bot - unexpected keyword argument issue

Getting an error when setting up my Telegram bot

I’m working on a Telegram bot project and keep running into this frustrating error:

TypeError: Updater.__init__() got an unexpected keyword argument 'use_context'

Here’s my current code:

import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, filters

def process_text(update, context):
    user_input = update.message.text
    
    if user_input == '/info':
        context.bot.send_message(chat_id=update.effective_chat.id, text="Here's some information about the bot.")
    elif user_input.startswith('/greet'):
        username = user_input.split()[1]
        context.bot.send_message(chat_id=update.effective_chat.id, text=f"Greetings, {username}!")
    else:
        context.bot.send_message(chat_id=update.effective_chat.id, text="I don't recognize that command.")

def welcome_user(update, context):
    context.bot.send_message(chat_id=update.effective_chat.id, text="Welcome! Your bot is ready to use.")

my_bot = telegram.Bot(token='my_token_here')
bot_updater = Updater(bot=my_bot, use_context=True)
bot_dispatcher = bot_updater.dispatcher
bot_dispatcher.add_handler(CommandHandler('start', welcome_user))
bot_dispatcher.add_handler(MessageHandler(filters.text, process_text))

bot_updater.start_polling()

I’m using python-telegram-bot version 20.3. Tried downgrading to earlier versions but the problem persists. What’s causing this and how can I resolve it?

You’re using old syntax with the new library version. Python-telegram-bot v20+ completely changed how things work. They ditched the Updater class and now you use Application instead. Here’s how to fix it: python from telegram.ext import Application, CommandHandler, MessageHandler, filters application = Application.builder().token('my_token_here').build() application.add_handler(CommandHandler('start', welcome_user)) application.add_handler(MessageHandler(filters.TEXT, process_text)) application.run_polling() Also heads up - filters.text is now filters.TEXT in newer versions. Context handling is built-in now so you don’t need to mess with that anymore. I ran into this exact same issue when I migrated my bot last year - check the docs for more examples of the new patterns.

You hit a breaking change from v20. They completely removed the Updater class. You’ll need to switch to the Application class instead. Do application = Application.builder().token('your_token').build(), then use application.add_handler() where you used dispatcher before. Change start_polling() to application.run_polling(). The context parameter’s automatic now - no need to specify it. Caught me off guard when I upgraded my bots last year too.

classic version mixup! in v20+, they ditched the use_context parameter completely - context is always on by default now. just change it to bot_updater = Updater(bot=my_bot) and drop the use_context part entirely.