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?