Answer the question
In order to leave comments, you need to log in
How to handle requests from 2 or more accounts at the same time?
Good day! When creating a bot, I encountered such a problem that when sending messages from two different VK accounts, the bot works sequentially, that is, it’s the same as if I wrote to the bot from one account. For example, if User 1 in the menu has reached the selection of projects (in the project1 code, etc.), and User 2 is in the game selection menu (in the game1 code, etc.) and User 2 selects, for example, game1, then he goes directly to the server selection menu ( in the server1 code, etc.), although, logically, I should have gone to the project selection menu.
How can this problem be solved?
I use libraries: asyncio and aiovk
async def main():
session = TokenSession(access_token=TOKEN())
api = API(session)
longpoll = BotsLongPoll(session, mode=8, group_id=VK_GROUP_ID())
while True:
try:
data = await longpoll.wait()
updates = data['updates']
for event in updates:
if event['type'] == 'message_new':
payload = event['object']['message']['payload']
responce = event['object']['message']['text'].lower
dict_event = event['object']['message']
if payload == '{"button":"1"}':
await api('messages.send',
peer_id=event['object']['message']['peer_id'],
message="game 1\n",
random_id=0,
keyboard=keyboardReturnMenu)
elif (responce == '1') and (payload_event == '{"button":"1"}'): \
stage3_menu1 = 1
await api('messages.send',
peer_id=event['object']['message']['peer_id'],
message="project 1\n",
random_id=0,
keyboard=keyboardReturnMenu)
elif (stage3_menu1 == 1) and (responce == '1'):
stage3_menu1 = 0
await api('messages.send',
peer_id=event['object']['message']['peer_id'],
message="server 1\nserver 2\nserver 3\n",
random_id=0,
keyboard=keyboardReturnMenu)
if dict_event.get('payload') != None:
payload_event = event['object']['message']['payload']
else:
payload_event = None
except Exception as E:
time.sleep(1)
await session.close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question