TeleBot: "'AsyncTeleBot' object has no attribute 'register_next_step_handler'"

55 views Asked by At

i was working with telebot using async and I wanted the handler to listen for messages sent and instead got the error:

2024-02-16 14:32:29,204 (async_telebot.py:552 MainThread) ERROR - TeleBot: "'AsyncTeleBot' object has no attribute 'register_next_step_handler'"

Is there a valid attribute in AsyncTelebot similar to register_next_step_handler?

Note: I don't want to use https://pytba.readthedocs.io/en/latest/sync_version/index.html#telebot.TeleBot.register_next_step_handler from Telebot, but rather I want to use it from AsyncTelebot context.


@bot.callback_query_handler(func=lambda call: call.data == 'join_free_channel')
async def join_free_channel_callback(query):
    chat_id = query.message.chat.id
    await bot.edit_message_text(chat_id=chat_id, message_id=query.message.message_id,
                                text="Please provide your referral code:",
                                reply_markup=referral_link_keyboard)

    # Register the next step handler to await the referral code
    await bot.register_next_step_handler(query.message, process_join_free_channel)



def process_join_free_channel(message):
    chat_id = message.chat.id
    user_id = message.from_user.id
    referral_code = message.text.strip()
    print(referral_code)
    if referral_code_valid(user_id, referral_code, conn):
        # If the referral code is valid, add the user to the group
        try:
            bot.send_message(chat_id, 'You will be added to the group shortly!', reply_markup=referral_link_keyboard)
        except Exception as e:
            print(f"Error adding user to group: {e}")
    else:
        # If the referral code is not valid, prompt the user to enter a valid one
        bot.send_message(chat_id, 'Invalid referral code. Please enter a valid referral code.')
        # Call the function again to prompt the user for a new referral code
        bot.register_next_step_handler(message, process_join_free_channel)
`


i was expecting when a user sends the code, await bot.register_next_step_handler(query.message, process_join_free_channel) would take in the code


NB: i dont to use https://pytba.readthedocs.io/en/latest/sync_version/index.html#telebot.TeleBot.register_next_step_handler from Telebot rather i want to use it from AsyncTelebot context. thanks
0

There are 0 answers