不会移动到 FSM 中的下一个状态,Aiogram
doesn't move to the next state in FSM, Aiogram
为什么它不移动到最后一个状态(LowPrice.result_without_photo)?例如,如果我在每个处理程序中使用 print,它会打印除最后一个之外的其他处理程序。
当然我不能移动到最后一个状态并在当前状态下写这个函数,但是这段代码简化了,例如,它有更多的行,这就是为什么我想使用一个单独的状态,只是为了让代码更具可读性
我的处理人员:
@dp.message_handler(Command("lowprice"))
async def choose_city(message: types.Message):
await message.answer('Write city')
await LowPrice.city.set()
@dp.message_handler(state=LowPrice.city)
async def hotels_quantity(message: types.Message, state: FSMContext):
answer = message.text
await state.update_data(city=answer)
await message.answer('How many hotels do I need to show you?')
await LowPrice.quantity_hotels.set()
@dp.message_handler(state=LowPrice.quantity_hotels)
async def if_need_photo(message: types.Message, state: FSMContext):
answer = message.text
await state.update_data(quantity_hotels=answer)
await message.answer('Do I need to show you hotel photos?')
await LowPrice.photo.set()
@dp.message_handler(state=LowPrice.photo)
async def get_answer_about_photo(message: types.Message, state: FSMContext):
answer = message.text
await state.update_data(if_photo_need=answer)
if answer == 'Yes':
await message.answer('How many photos to show?')
await LowPrice.quantity_photo.set()
elif answer == 'No':
await message.answer('Fine, I am starting to find hotels')
await LowPrice.result_without_photo.set()
@dp.message_handler(state=LowPrice.result_without_photo)
async def result_without_photo(message: types.Message, state: FSMContext):
data = await state.get_data()
city_id = get_id_city(data)
await message.answer(f'city ID{city_id}')
我的状态:
class LowPrice(StatesGroup):
start = State()
city = State()
date = State()
quantity_hotels = State()
photo = State()
result_without_photo = State()
quantity_photo = State()
因为用户需要写一些东西来帮助你在result_without_photo
函数中处理消息。
你确定你真的想要它吗?
似乎您只需要在 No
回答后执行 result_without_photo
的内容,而不是等待来自用户的另一次通信。
为什么它不移动到最后一个状态(LowPrice.result_without_photo)?例如,如果我在每个处理程序中使用 print,它会打印除最后一个之外的其他处理程序。
当然我不能移动到最后一个状态并在当前状态下写这个函数,但是这段代码简化了,例如,它有更多的行,这就是为什么我想使用一个单独的状态,只是为了让代码更具可读性
我的处理人员:
@dp.message_handler(Command("lowprice"))
async def choose_city(message: types.Message):
await message.answer('Write city')
await LowPrice.city.set()
@dp.message_handler(state=LowPrice.city)
async def hotels_quantity(message: types.Message, state: FSMContext):
answer = message.text
await state.update_data(city=answer)
await message.answer('How many hotels do I need to show you?')
await LowPrice.quantity_hotels.set()
@dp.message_handler(state=LowPrice.quantity_hotels)
async def if_need_photo(message: types.Message, state: FSMContext):
answer = message.text
await state.update_data(quantity_hotels=answer)
await message.answer('Do I need to show you hotel photos?')
await LowPrice.photo.set()
@dp.message_handler(state=LowPrice.photo)
async def get_answer_about_photo(message: types.Message, state: FSMContext):
answer = message.text
await state.update_data(if_photo_need=answer)
if answer == 'Yes':
await message.answer('How many photos to show?')
await LowPrice.quantity_photo.set()
elif answer == 'No':
await message.answer('Fine, I am starting to find hotels')
await LowPrice.result_without_photo.set()
@dp.message_handler(state=LowPrice.result_without_photo)
async def result_without_photo(message: types.Message, state: FSMContext):
data = await state.get_data()
city_id = get_id_city(data)
await message.answer(f'city ID{city_id}')
我的状态:
class LowPrice(StatesGroup):
start = State()
city = State()
date = State()
quantity_hotels = State()
photo = State()
result_without_photo = State()
quantity_photo = State()
因为用户需要写一些东西来帮助你在result_without_photo
函数中处理消息。
你确定你真的想要它吗?
似乎您只需要在 No
回答后执行 result_without_photo
的内容,而不是等待来自用户的另一次通信。