Hey everyone, I’m stuck with a weird error while trying to make a Telegram bot. I keep getting this message:
TypeError: Updater.__init__() missing 1 required positional argument: 'update_queue'
I’ve already tried reinstalling the libraries, but it still persists. Below is a revised version of my code for clarity:
import telegram
from telegram.ext import BotUpdater, CmdHandler, MessageProcessor
BOT_KEY = 'my_secret_bot_key'
def greet(update, context):
user = update.effective_user
update.message.reply_text(f'Hello {user.first_name}!')
def setup():
bot_updater = BotUpdater(BOT_KEY)
dispatcher = bot_updater.dispatcher
dispatcher.add_handler(CmdHandler('hello', greet))
dispatcher.add_handler(MessageProcessor(process_message))
bot_updater.start_polling()
bot_updater.idle()
if __name__ == '__main__':
setup()
Can anyone help me figure out why this issue is happening? I’m using Python 3.9. Thanks a lot!
I’ve run into this exact issue before when working on my own Telegram bot. The problem is likely stemming from using outdated or incorrect class names from the python-telegram-bot library. In more recent versions, they’ve changed some of the class names and structure.
Try updating your imports and class names like this:
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
# Then in your setup function:
updater = Updater(BOT_KEY, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler('hello', greet))
dispatcher.add_handler(MessageHandler(Filters.text, process_message))
This should resolve the ‘missing argument’ error you’re encountering. Make sure you’re using the latest version of python-telegram-bot (you can update it via pip if needed). If you’re still having issues after this, double-check your BOT_KEY and ensure your bot is properly registered with BotFather on Telegram.
hey alice, i had similar issue. make sure ur using latest python-telegram-bot version. try this:
from telegram.ext import Updater, CommandHandler, MessageHandler
updater = Updater(BOT_KEY)
dp = updater.dispatcher
dp.add_handler(CommandHandler(‘hello’, greet))
if that don’t work, check ur bot token again. good luck!
The error you’re encountering is typically due to using outdated class names or incorrect initialization in the python-telegram-bot library. I’d suggest updating your code to use the current class names and structure.
Replace ‘BotUpdater’ with ‘Updater’, ‘CmdHandler’ with ‘CommandHandler’, and ‘MessageProcessor’ with ‘MessageHandler’. Also, ensure you’re passing the ‘use_context=True’ parameter when initializing the Updater.
If issues persist after these changes, verify your bot token and check if you’re using the latest version of the library. You can update it using ‘pip install --upgrade python-telegram-bot’.
Remember to import Filters for message handling:
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
This should resolve your TypeError and get your bot up and running.