Hello everyone, I have such a problem, I can't figure out how to transfer the value of a variable from one handler to another. I am trying to use FSM for this, here is a sample code.

    async def pvp_reg_id(message: types.Message, state: FSMContext):
        user_id_player_1= message.from_user.id # Who sends
        await state.update_data(user_id_player_2=message.text)#opponent
        await state.update_data(user_id_player_1=user_id_player_1)# Who sends
        user_id_players= await state.get_data() #Sent to
        await state.reset_state(with_data=False)

Here I am trying to getawait state.update_data(user_id_player_1=user_id_player_1)# Submitting

@dp.callback_query_handler(text="Acc", state="*")
    async def Accept_Pvp(call: types.CallbackQuery, state: FSMContext):
        user_id_players= await state.get_data()
        player_1= user_id_players.get("user_id_player_2")
        await call.answer()
        await state.finish()

The output gives me None

Through the third entity -database, queue or stack... Any entity independent of both handlers.

Михаил Алексеевич2022-01-23 19:48:03

I tested your code, it works for me. pastebin.com/phBtRBGF Maybe you are resetting the state somewhere or overwriting the data?

oleksandrigo2022-01-24 07:55:58