L
L
LordOftheCode2021-09-22 10:35:41
Python
LordOftheCode, 2021-09-22 10:35:41

3 handler not working in python bot?

I am writing a bot, I need to collect information from the user
In the first handler I get the number 1 or 2
In the second handler I write the number 1 or 2 to a variable, after receiving the information and writing it to the variable, the code cannot reach handler 3
Question why? How can this be fixed?

@dp.message_handler(commands=["start"])
async def echo(message: types.Message):
    await message.answer("Выберите предмет.")
    await message.answer("1 - Русский  |  2 - Алгебра")
    
    @dp.message_handler(content_types=['text'])
    async def echo1(message: types.Message):
        logger.info(message.text)
        predmet = message.text
 
        @dp.message_handler(content_types=['text'])
        async def echo2(message: types.Message):
            await message.answer("Введите номер задания.")
            logger.debug(message.text)
            nomer = message.text

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stefan, 2021-09-22
@LordOftheCode

It does not work because your message is intercepted by the second handler, because it is higher when the response is resolved, how to fix it: write normal code, use FSM for the chain of actions, and never nest handlers in each other

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question