TypeError in Python Telegram Bot while using Updater

I’m developing a Telegram bot using Python, which connects to a Google Sheet to display data from a couple of different worksheets. Unfortunately, when executing the code, I encounter a TypeError that states Updater.__init__() is missing a required argument called update_queue. Here’s the code I’m working on:

# Bot implementation
import telegram
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from google.oauth2 import service_account
import gspread

# Bot token
BOT_TOKEN = 'your_bot_token_here'

# Google API settings
API_SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
CREDS_FILE = 'path/to/your/credentials.json'
document_id = 'your_spreadsheet_id'

# Setup Google Sheets authentication
credentials = service_account.Credentials.from_service_account_file(CREDS_FILE, scopes=API_SCOPES)

# Function to retrieve worksheet data
def fetch_worksheet_data(worksheet_name):
    client = gspread.authorize(credentials)
    spreadsheet = client.open_by_key(document_id)
    target_sheet = spreadsheet.worksheet(worksheet_name)
    return target_sheet.get_all_values()

# Handler for /start command
def handle_start(bot, update):
    buttons = [[InlineKeyboardButton("Reports", callback_data='reports')],
               [InlineKeyboardButton("Metrics", callback_data='metrics')]]
    markup = InlineKeyboardMarkup(buttons)
    update.message.reply_text('Select an option:', reply_markup=markup)

# Handler for button clicks
def handle_button_click(bot, update):
    query = update.callback_query
    selected_sheet = query.data
    sheet_data = fetch_worksheet_data(selected_sheet)
    formatted_data = '\n'.join(['\t'.join(row) for row in sheet_data])
    query.edit_message_text(text=formatted_data)

def run_bot():
    bot_updater = Updater(BOT_TOKEN)
    dispatcher = bot_updater.dispatcher

    dispatcher.add_handler(CommandHandler("start", handle_start))
    dispatcher.add_handler(CallbackQueryHandler(handle_button_click))

    bot_updater.start_polling()
    bot_updater.idle()

if __name__ == '__main__':
    run_bot()

The intention is for the bot to provide two buttons that upon being clicked will display the corresponding Google Sheet data, but I’m facing issues with this Updater error. Can anyone help me out?

you’re using old syntax with a newer python-telegram-bot version. drop the bot parameter from your handler functions - use handle_start(update, context) instead of handle_start(bot, update). when you need the bot instance inside functions, use context.bot. fixed the same issue for me last month.

The TypeError you’re encountering is likely due to incompatibilities between the version of the python-telegram-bot library you’re using and your current code structure. Starting from version 13.0, the update_queue argument was removed from the Updater class. To resolve this, you should modify your Updater initialization to only include the bot token. Additionally, update your command and callback handler functions to utilize update and context as parameters, discarding the bot parameter entirely. The context parameter will provide access to the bot instance and potentially streamline your function logic.

Your issue comes from API changes in newer versions of python-telegram-bot. Version 13+ changed how the Updater class works - it doesn’t use the update_queue argument anymore. I hit the same problem when I upgraded my bot. You’ve got two options: either downgrade to version 12.8 with pip install python-telegram-bot==12.8 to keep your current code, or update everything for v13+. If you go with the newer version, you’ll need to fix your handlers since they don’t automatically get the bot parameter anymore - just use the update parameter. Also check your imports because some modules moved around.