Home>
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.
@dp.message_handler(state=FMS.waite_user_id)
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)
print(user_id_players['user_id_player_1'])
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")
print(player_1)
await call.answer()
await state.finish()
The output gives me None
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:58Related questions
- python : make sure that the buttons are not detected
- python : AttributeError: 'NoneType' object has no attribute 'startswith'
- TypeError: 'list' object is not callable. Literally today I started learning Python and telebot API and I don’t understand what
- python : Sending a file using telegramAPI
- python : Bot on aiogram does not see the answer to someone else's message
- python : How to send a single message in response to the user via bot.send_message
- python : Filter data with pydantic by values
- python : Error with matrix multiplication. Numpy
- Can't uninstall/install Python
Through the third entity -database, queue or stack... Any entity independent of both handlers.
Михаил Алексеевич2022-01-23 19:48:03