[Split] TypeError: Updater.__init__() got an unexpected keyword argument 'use_context'

Hi everyone Im new to this website, and im having a problem in python i cant solve i tried everything, Side Note this is meant to be a Telegram Reminder Bot, also im using pycharm, Here is the Error:

              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Updater.__init__() got an unexpected keyword argument 'use_context'

and heres my code:

from telegram.ext import Updater, CommandHandler, MessageHandler, CallbackContext
import telegram.ext.filters as filters
from telegram import Update
import logging


logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)


def start(update, context):
    update.message.reply_text("Welcome to Reminder Bot! Please enter what you want to be reminded of:")


def set_reminder(update, context):
    reminder_text = update.message.text
    update.message.reply_text("Great! Now, please enter when you want to be reminded (e.g., 2022-12-31 08:00):")


def set_reminder_time(update, context):
    reminder_time = update.message.text
    update.message.reply_text("Perfect! Lastly, please enter how often you want to be reminded (e.g., daily, weekly, monthly):")


def set_reminder_frequency(update, context):
    reminder_frequency = update.message.text
    update.message.reply_text("Reminder set successfully! You will be reminded accordingly.")


def unknown(update, context):
    update.message.reply_text("Sorry, I didn't understand that command.")

def main():

    updater = Updater("TOKEN", use_context=True)


    dp = updater.dispatcher

    # Add command handlers
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(MessageHandler(Filters.text & ~Filters.command, set_reminder))
    dp.add_handler(MessageHandler(Filters.text & ~Filters.command, set_reminder_time))
    dp.add_handler(MessageHandler(Filters.text & ~Filters.command, set_reminder_frequency))
    dp.add_handler(MessageHandler(Filters.command, unknown))

    # Start the Bot
    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
    main()

When pasting your code:

format_code

Your code has multiple functions with the argument parameter context without it actually being used within the functions. Was this a cut and paste error or is this parameter actually needed within the function definitions?

From the following website:

Have you attempted reviewing this website for reference and guidance?

*** BY THE WAY, TRY STARTING A NEW TOPIC FOR YOUR ISSUE AS IT APPEARS UNRELATED TO THIS ISSUE THAT YOU POSTED YOUR ISSUE TO ***

1 Like

By the way, there was someone else working on creating their first bot using the telegram.ext module much like you’re attempting to do now.

Try contacting this person: @sreeharsh

The issue is posted here:

Maybe they can advise you how they got theirs working.

I split this post off to a new topic, FYI, from this generically titled one:

…and gave it a basic title; @Soulfan_YT please feel free to edit it to be more specific as you wish.

Just to note,

I happened to see it as I’d previously replied to this issue, but next time please flag the post as “Off topic” so we can promptly topic split it. Thanks.

2 Likes

Ok, will do.

1 Like