D
D
Dmitry2021-11-06 18:43:47
Python
Dmitry, 2021-11-06 18:43:47

How to pass the filter of the triggered handler to the function?

aigram library. Trying to understand how FSM works. In order not to repeat myself, I decided to create one function that reacts to all state filters.

How can I pass to the function which handler the code reacted to?

@dp.message_handler(Command('test'))
async def go_test(message: types.Message):
    await message.answer('Вопрос № 1\n Сколько будет 2 + 2 ?')
    await Test.q1.set()
    @dp.message_handler(state= Test.q1)
    @dp.message_handler(state=Test.q2)
    @dp.message_handler(state=Test.q3)

    async def answer_q(message: types.Message, state: FSMContext):
        answer = message.text
        await message.answer('Вы вошли в состояние',  [По идеи тут должен быть q1])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-06
@Vindicar

Well, probably see what is available in the state parameter?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question