AsyncTelebot 消息处理程序无法处理状态

问题描述 投票:0回答:1

我对 AsyncTeleBot 中的状态有疑问。消息处理程序无法处理状态,我不知道出了什么问题。代码如下

bot = AsyncTeleBot(token, state_storage=StateMemoryStorage())


@bot.message_handler(commands=['start'])
async def startup(message: Message):
    text = 'Hi! Lets start!'
    await bot.send_message(message.chat.id, text, reply_markup=main_keyboard())


@bot.message_handler(regexp='Mark')
async def marks_main(message):
    text = 'Choose option:'
    await bot.send_message(message.chat.id, text, reply_markup=qa_main_keyboard())


@bot.message_handler(regexp='Add mark')
async def marks_action_handler(message):
    text = 'Type your mark'
    state = bot.current_states
    await bot.send_message(message.chat.id, text)
    await state.set_state(user_id=message.from_user.id, state=QaState.add_mark,
                          chat_id=message.chat.id)


@bot.message_handler(state=QaState.add_mark)
async def add_mark_func(message):
    await QaDAO.add({'mark': message.text})
    text = 'Mark added!'
    await bot.send_message(message.chat.id, text, reply_markup=qa_main_keyboard())
from telebot.asyncio_handler_backends import StatesGroup, State


class QaState(StatesGroup):
    add_mark = State()
    all_marks = State()

最后一个处理程序 add_mark_func 不起作用。但状态是同时添加的(我在调试器控制台中检查这一点),但处理程序没有捕获状态

python state telebot
1个回答
0
投票

你有来自

bot.setup_middleware(StateMiddleware(bot))
telebot.states.asyncio.middleware
吗 毕竟是message_handler的。 像这样

© www.soinside.com 2019 - 2024. All rights reserved.