Skip to content

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

@garytann

Description

@garytann

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using?
  • 4.11.0
  1. What OS are you using?
  • Mac m1
  1. What version of python are you using?
  • python=3.8

Hi guys I have an issue with converting my telebot to an async telebot, I have a callback_query_handler that creates a menu for user to select an option

# Handler for creating user menu 
@bot.callback_query_handler(func=None, config=create_menu_factory.filter())
async def create_menu_callback(call: types.CallbackQuery):

    callback_data: dict = create_menu_factory.parse(callback_data=call.data)
    product_id = int(callback_data['create_menu_id'])
    menu = MENU[product_id] # i.e, {'id': '0', 'name': 'Create New user'}
    if (menu['id'] == '0'):
        msg = await bot.reply_to(call.message,f"Enter a name for the user")
        await bot.register_next_step_handler(msg, process_name_step)

and a function process_name_step() :

  • Spin up a menu keyboard
  • According to what the user selects, enter the information accordingly
  • Tried using states in this function, but not really familiar how it works
@bot.message_handler(state=MyStates.number)
async def process_contact_number_step(message):
    try:
        chat_id = message.chat.id
        # contact_number = message.text
        
        await bot.send_message(message.chat.id, 'Please select the following:', reply_markup=create_user_menu_keyboard())
        await bot.set_state(message.from_user.id, MyStates.number, message.chat.id)
        async with bot.retrieve_data(message.from_user.id, message.chat.id) as data:
            data['contact_number'] = message.text
        if chat_id in contact_num_dict:
            contact_num_dict[chat_id].append(data['contact_number'])
        else:
            contact_num_dict[chat_id] = data['contact_number']
        print(contact_num_dict) 
        
    except Exception as e:
        await bot.reply_to(message, 'broken')

Basically what I need is to create a menu > when user chooses an options it will lead to another menu > prompt user to enter the information > store the information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions