D
D
Dmitry2022-04-12 21:53:42
Python
Dmitry, 2022-04-12 21:53:42

How to create FSM in aiogram correctly?

I need to set states to numbers that the user will enter. But I don't know in advance how many numbers will be entered. Two, three, maybe ten. How to implement fsm in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-04-13
@Meys313

Make one state that accepts numbers. Tired of accepting - we complete

class Form(StatesGroup):
    number = State()

@dp.message_handler(state=Form.number)
async def process_number(message: types.Message, state: FSMContext):
    if message.text != “0”:
        await message.reply(message.text)
    else:
        await state.finish()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question