Search code examples
pythontelegramtelegram-botaiogram

How to correct this issue, Aiogram, Trelegram


I a making a telegram bot, and the problem is that user has to accept policy and when user click accept the bot just shows loading message

Video with the problem: https://drive.google.com/file/d/1yAZl0VDn_tisBsHAaJ2udyfnaW-G9IOH/view?usp=sharing

My code:https://github.com/user515244/code.git


Solution

    1. You have a typo in line 37 (confirm_correct1 instead of confirm_correct)

    2. To handle the next state, you simply need the next state, otherwise it will not be switched. This is how FSM works.

    Add to your class:

    state_name = State()
    

    Add to your handlers with text=confirm_correct and text=go_back (please don't give the functions in them the same names, names should explain what the function does) the following:

    @dp.callback_query_handler(text="confirm_correct", state=SomeState.state_name)
    

    ...

    @dp.callback_query_handler(text="go_back", state=SomeState.state_name)
    

    Add to handle_accept_policy setting the state:

    if amount and wallet:
            await callback.message.edit_text(f"Amount: {amount}\nWallet: {wallet}\n\nIs everything correct?",
                                             reply_markup=accept_menu)
    
            await SomeState.state_name.set()
    

    And that'll be it.