0

How to make Return buttons in aiogram with FSM


class AdminConsole(StatesGroup):
    menuEntry = State()
    menuChoice = State()
    choosenStudent = State()
    Saction = State()
    newName = State()
    newID = State()
    rmConfirmation = State()

@dp.message_handler(state=AdminConsole.menuEntry)
async def _AdminConsoleMenuEntry(message: types.Message) -> None:
    if message.from_user.id not in admins:
        await message.answer('ОШИБКА Недостаточно прав')
    if message.from_user.id in admins:
        await message.answer('Добро пожаловать в панель инструментов админа',
                             reply_markup=getKb().row('Управление студентами‍', 'Управление расписанием'))
        await AdminConsole.menuChoice.set()
@dp.message_handler(state=AdminConsole.menuChoice)
async def _AdminConsole2Menus(message: types.Message, state: FSMContext) -> None:
    async with state.proxy() as data:
        data['control_choice'] = message.text
        if data['control_choice'] == 'Управление студентами‍':
            kb = getKb()
            for student in StudentsUDBA().getAllStudents():
                kb.add(f'{student.NAME}')
            kb.add('Назад⬅️')
            await message.answer('Выберите студента для управления', reply_markup=kb)
            await AdminConsole.choosenStudent.set()
        if data['control_choice'] == 'Управление расписанием':
            pass

async def _AdminConsole2MenusM(message: types.Message, state: FSMContext) -> None:
    async with state.proxy() as data:
        data['control_choice'] = message.text
        if data['control_choice'] == 'Управление студентами‍':
            kb = getKb()
            for student in StudentsUDBA().getAllStudents():
                kb.add(f'{student.NAME}')
            kb.add('Назад⬅️')
            await message.answer('Выберите студента для управления', reply_markup=kb)
            await AdminConsole.choosenStudent.set()
        if data['control_choice'] == 'Управление расписанием':
            pass

That's my code, but I dont have an idea how to return to previous state and realize "Back" (Назад) buttons

I tryed to call funcs, but this didn't work. I need to come back to previous state and previous menu with (Назад) button

1 Answers1

0

I'm new to this topic, but I can tell you something. My bot have a class too and to go from menuEntry to menuChoice, you may use the method: YourClass.next() to go further down the class and YourClass.previous() to go back.

enter image description here

  • My class: class NewOrder(StatesGroup): type = State() name = State() desc = State() price = State() photo = State() – JustMax Jun 04 '23 at 11:13
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 04 '23 at 18:16