Let's say I have this code in Aiogram. I need that when the @dp.message(Text('Begin ')) handler is run, only the handlers that are inside this handler are checked. And when the user wrote End , then the handlers in @dp.message(Text('Begin ')) were no longer checked. And all that are outside this handler were checked
Minimal-reproducible-example:
import asyncio
import logging
from aiogram import Bot, Dispatcher, types
from aiogram.filters import Text
from aiogram.filters.command import Command
from aiogram.utils.keyboard import ReplyKeyboardBuilder
logging.basicConfig(level=logging.INFO)
bot = Bot(token="TOKEN")
dp = Dispatcher()
@dp.message(Command("start"))
async def cmd_start(message: types.Message):
builder = ReplyKeyboardBuilder()
builder.row(
types.KeyboardButton(text="Begin"),
)
await message.answer('Hello, press to button', reply_markup=builder.as_markup(resize_keyboard=True))
@dp.message(Text('Begin'))
async def new_client_services(message: types.Message):
builder = ReplyKeyboardBuilder()
builder.row(
types.KeyboardButton(text="End"),
)
await message.answer("Please write down all your items lying on the table one by one",
reply_markup=builder.as_markup(resize_keyboard=True))
@dp.message(Text('End'))
async def end_save_services(message: types.Message):
await message.reply("Excellent",
reply_markup=types.ReplyKeyboardRemove())
@dp.message()
async def with_puree(message: types.Message):
# add part mysql
await message.answer(f"Items {message.text} add✅\n")
@dp.message()
async def end_save_services(message: types.Message):
await message.reply("Please, push button")
async def main():
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
I foundthis question. This question has a similar problem but different