[Python] AsyncTelebot message handler not working with a state

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I have a problem with states in AsyncTeleBot. message handler not working with state, and i don't have any idea, whats going wrong. Code is below here

    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()


    Last handler, add_mark_func, is not working. But the state is added at the same time (i check this in debbuger console), but handler does not catch state

    Continue reading...

Compartilhe esta Página