Why do I send a message to a handler with the function in which await state.set_state ('name2) sends the following message to the next handler using await state.set_state (name1), the problem arises: if you send two messages at the same time, they will be processed both in the name1 handler.

But if you send two in order, then everything is normal and turns first in the first handler, and the next will be transferred to the second. In both, lock is used, but this does not help.

The same thing happens if you first send one message, it will be processed in the first handler. And if in a few seconds to send two more at the same time, then again both will be processed in the second.

@dp.message_handler(state='message_in_chat') async def send_message(message: types.Message): await bot.forward_message(id, message.from_user.id, message.message_id) with dp.current_state(chat=message.chat.id, user=message.from_user.id) as state: await state.set_state('message_two') @dp.message_handler(state='message_two') async def send_message2(message: types.Message): await bot.forward_message(id, message.from_user.id, message.message_id) with dp.current_state(chat=message.chat.id, user=message.from_user.id) as state: await state.set_state('message_in_chat') 
  • In the first function, the message comes from another function using the same method. - Vitali
  • This answer may not be accurate, as I am in the process of learning python, but most likely it’s just the library itself that functions incorrectly or an out-of-date version is installed (I personally had this 2 times, one for each case). I advise you to update the library or use another. - Mr.SKRIN
  • No, the library is properly installed, that's not the point. - Vitali

0