一步式有限状态机 错误:Town() 不带参数
@weather_router.message(Command("weather"))
class Town(StatesGroup):
town = State()
async def town(message: Message, state: FSMContext):
await message.answer(f"{message.from_user.first_name}, введи город")
await state.set_state(Town.town)
async def townn(message: Message):
await message.answer(f"Ваш город\n{message.text}")
我希望机器人能够处理用户“town”并使用 FSM 通过短信将其发回给他
@weather_router.message(Town.town)
await state.clear()
添加到“townn”函数以清除 FSM 上下文代码:
class Town(StatesGroup):
town = State()
@weather_router.message(Command('weather'))
async def town(message: Message, state: FSMContext):
await state.set_state(Town.town)
await message.answer(f"{message.from_user.first_name}, введи город")
@weather_router.message(Town.town)
async def townn(message: Message, state: FSMContext):
await message.answer(f"Ваш город\n{message.text}")
await state.clear()