Issue with basic telegram bot setup

I’m working on a basic telegram bot using Python, but I’m encountering a problem when I try to run my script. After executing it, I see an error message regarding an unexpected keyword argument. Here’s my code so far:

import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters

# Configure logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)

def start_bot(update, context):
    """Respond to the /start command."""
    update.message.reply_text('Hello!')

def assist(update, context):
    """Respond to the /assist command."""
    update.message.reply_text('How can I help you?')

def echo_response(update, context):
    """Repeat the user’s message."""
    update.message.reply_text(update.message.text)

def log_errors(update, context):
    """Log any errors that occur."""
    logger.warning('Update "%s" caused error "%s"', update, context.error)

def start_bot_process():
    """Initialize the bot and start it."""
    updater_instance = Updater("YOUR_BOT_TOKEN", use_context=True)
    
dispatcher_instance = updater_instance.dispatcher
    
dispatcher_instance.add_handler(CommandHandler("start", start_bot))
    dispatcher_instance.add_handler(CommandHandler("assist", assist))
    dispatcher_instance.add_handler(MessageHandler(Filters.text, echo_response))
    dispatcher_instance.add_error_handler(log_errors)
    
    updater_instance.start_polling()
    updater_instance.idle()

if __name__ == '__main__':
    start_bot_process()

The error I’m receiving is:

Traceback (most recent call last):
  File "bot_example.py", line 44, in <module>
    start_bot_process()
  File "bot_example.py", line 24, in start_bot_process
    updater_instance = Updater("YOUR_BOT_TOKEN", use_context=True)
TypeError: __init__() got an unexpected keyword argument 'use_context'

Can anyone help me understand what might be going wrong? Thank you!

Had this exact problem last month after updating my telegram bot dependencies. You’re mixing old and new versions of python-telegram-bot. Version 20+ completely restructured the API - your code’s written for 13.x but you’ve got a newer version installed. Two options: downgrade to 13.15 with pip install python-telegram-bot==13.15 and your code works as-is, or migrate to the new API (means replacing Updater with Application plus other changes). I’d just downgrade for a quick fix since your code’s already structured for the older version.

check your version with pip list | grep python-telegram-bot. if it’s v20 or higher, you gotta remove the use_context parameter from Updater. just get rid of it and you’ll be fine!

This happens because python-telegram-bot changed everything in version 20+. You can drop the use_context parameter - it’s enabled by default now. You’ll also need to switch from Updater to Application, and change Filters to lowercase filters. Sure, you could downgrade to 13.x for a quick fix, but I’d update your code instead. You’ll avoid headaches down the road.

ur using an older version of python-telegram-bot. they removed use_context=True in newer versions - context is enabled by default now. just delete that parameter and ur good to go.

Telegram bot API changes are such a headache. Something always breaks with updates.

I got sick of version conflicts and manual deployments, so I switched to automating everything with Latenode. No more library updates or server babysitting.

Latenode handles Telegram API calls through a visual interface. Drag, drop, connect your bot token, set up commands. When Telegram updates their API, Latenode fixes compatibility automatically.

Migrated three bots this way and saved hours of debugging. You can hook up databases, send emails, or connect other services without coding.

Beats maintaining Python scripts and fighting dependency hell every few months.

Check it out: https://latenode.com