LordOftheCode2021-09-22 10:35:41
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?

async def echo(message: types.Message):
    await message.answer("Выберите предмет.")
    await message.answer("1 - Русский  |  2 - Алгебра")
    async def echo1(message: types.Message):
        predmet = message.text
        async def echo2(message: types.Message):
            await message.answer("Введите номер задания.")
            nomer = message.text

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Stefan, 2021-09-22

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