G
G
Govesinc2021-07-20 20:08:56
Python
Govesinc, 2021-07-20 20:08:56

Aiogram, how to assign value to State before user enters value after set()?

Tried this but doesn't work, gives - KeyError: 'item_id'

await states.NewItem.item_name.set()

state = dp.current_state(user=user_id)
await state.update_data(item_id=item_id)


What is the correct way to pre-assign the state() value to the item_id variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bl4ckm45k, 2021-07-21
@Bl4ckm45k

To access data in the state, write in the function:

async def start_bot(message: types.Message, state: FSMContext):

you rename the variable state = dp.current_state(user=user_id), because you reassign it FSMContextto dp.current_state(user=user_id)
after that it await state.update_data(item_id=item_id)will be successful

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question