Home>

How to transfer the user directly to the next step in the step-by-step function of the bot? I have one step-by-step loop in one file, and the Reply menu with the keyboard in another. I would like that when a key is pressed, the bot immediately proceeds to the execution of the loop, and does not wait for user input through register_next_step_handler.

Let me give you an example:

Main.py

def menu_step (message):
    markup= types.ReplyKeyboardMarkup (one_time_keyboard= True, resize_keyboard= True)
    markup.add ('Form 1', 'Form 2')
    markup.add ('Feedback')
    bot.send_message (message.chat.id, 'Choose Below', reply_markup= markup)
@ bot.message_handler (content_types= ['text'])
def statistics_step (message):
    if message.text.lower ()== 'profile 1':
        msg= bot.send_message (message.chat.id, 'HOW TO REMOVE THIS TEXT AND GO TO THE NEXT STEP IMMEDIATELY?')
        bot.register_next_step_handler (msg, Cycle.null_step)

Cycle.py

def null_step (message):
        msg= bot.send_message (message.chat.id, "Enter data 1")
        bot.register_next_step_handler (msg, one_step)
        # And further

You can, of course, shift the questionnaire one step and ask to enter data directly into Main.py, but not very nice. I would like another solution. I would like to Reply the keyboard.

  • Answer # 1

    Don't need to usebot.register_next_step_handler (msg, Cycle.null_step)(getting, in fact, 'user input'), but you must immediately call the function you need:

    @ bot.message_handler (content_types= ['text'])
    def statistics_step (message):
        if message.text.lower ()== 'profile 1':
            Cycle.null_step (message)