可以使用AIPROMPOM PYTHON更改状态
我需要更改回调中的状态
@dp.callback_query_handler(text="ru", state=States.lang)
async def change_lang_ru(call: types.CallbackQuery, state: FSMContext):
global menu_keyboard
async with state.proxy() as data:
data['lang'] = 'ru'
await call.answer(text="Язык поменялся", show_alert=True)
print(States.all())
await States.menu.set()
实际上没有出现错误,但是下一个状态尚未开始,
INFO:aiogram.contrib.middlewares.logging:Received callback query [ID:1631380781948190838] from user [ID:379835437] for message [ID:123] in chat [private:379835437] with data: ru originally posted by user [ID:5151482169]
INFO:aiogram.contrib.middlewares.logging:Unhandled callback query [ID:1631380781948190838] from user [ID:379835437] for message [ID:123] in chat [private:379835437] with data: ru originally posted by user [ID:5151482169]
INFO:aiogram.contrib.middlewares.logging:Process update [ID:41723130]: [success] (in 6 ms)
这是我下一个状态的开始
@dp.message_handler(state=States.menu)
async def first_test_state_case_met(message: types.Message):
await message.reply('First!', reply=False)
,这些是我的状态,
class States(StatesGroup):
lang = State()
menu = State()
我在文档中找不到任何答案
I need to change state in callback handled
@dp.callback_query_handler(text="ru", state=States.lang)
async def change_lang_ru(call: types.CallbackQuery, state: FSMContext):
global menu_keyboard
async with state.proxy() as data:
data['lang'] = 'ru'
await call.answer(text="Язык поменялся", show_alert=True)
print(States.all())
await States.menu.set()
Actually no error appears but next state doesn't start
INFO:aiogram.contrib.middlewares.logging:Received callback query [ID:1631380781948190838] from user [ID:379835437] for message [ID:123] in chat [private:379835437] with data: ru originally posted by user [ID:5151482169]
INFO:aiogram.contrib.middlewares.logging:Unhandled callback query [ID:1631380781948190838] from user [ID:379835437] for message [ID:123] in chat [private:379835437] with data: ru originally posted by user [ID:5151482169]
INFO:aiogram.contrib.middlewares.logging:Process update [ID:41723130]: [success] (in 6 ms)
This is how my next state is supposed to start
@dp.message_handler(state=States.menu)
async def first_test_state_case_met(message: types.Message):
await message.reply('First!', reply=False)
And these are my states
class States(StatesGroup):
lang = State()
menu = State()
I could not find any answers on this in documentation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的例子中我有一个错误:
除此之外,所有其他状态都有效,但在 States 更改为菜单状态后:
您应该发送消息以在下一个函数中查看响应,因为您的下一个函数是消息处理程序,因此它需要您发送消息
并且不要忘记稍后完成您的状态
In Your example i have an error here:
except this, all other states works, but after States changed to menu state:
you should send message to see the response in the next function, because your next function is a message handler, so it expects a message from you
And don't forget to finish your state later