I am creating a telegram bot and when I run the code to try it, it shows this error: Exception has occurred: TypeError Updater.init() got an unexpected keyword argument 'use_context'
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, filters
def handle_message(update, context):
message = update.message.text
# Implement your logic based on the message content
if message == '/help':
context.bot.send_message(chat_id=update.effective_chat.id, text="This is the help message.")
elif message.startswith('/sayhello'):
name = message.split()[1] # Extract the name from the command
context.bot.send_message(chat_id=update.effective_chat.id, text=f"Hello, {name}!")
else:
context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.")
def start_command(update, context):
# Send a welcome message
context.bot.send_message(chat_id=update.effective_chat.id, text="Hello! I'm your Telegram bot.")
bot = telegram.Bot(token='blabla')
updater = Updater(bot= bot, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler('start', start_command))
dispatcher.add_handler(MessageHandler(filters.text, handle_message))
updater.start_polling()
I am using version 20.3 of python-telegram-bot library. I tried downgading to 20.2 and mamyother versions, nothing worked.