Answer the question
In order to leave comments, you need to log in
How to implement the work of a VK-bot in Python with several users at the same time?
There is a group VK bot written in Python. If during the communication of the bot with one user (for example: a) another user writes to the bot (for example: b), then the bot will think that both messages were written by the first user (a). That is, several users will not be able to communicate with the bot at the same time. How to fix it? What needs to be added to the code, changed in it, to solve the problem?
I tried to write a VK bot in two ways: using longpoll and without it. (The above problem is present in both methods!)
The code itself (very ugly :) ):
Ya.Disk - https://yadi.sk/d/n3IhqYkXwPwPzw
Answer the question
In order to leave comments, you need to log in
You need to store a step/question number (some people call it a conversation context, a state) for each user who started a conversation with the bot. Unfortunately, I did not find such libraries for vk in python in the public domain. Therefore, I will give a general algorithm for solving such a problem. For a specific implementation, you already need to go to a neighboring site .
In the case of a linear chain of questions without the possibility of going back
Начало +-> Вопрос 1 +-> Вопрос 2 +-> Вопрос 3 +-> Конец
^ + ^ + ^ +
+---+ +---+ +---+
Начало +-> Вопрос 1 +-> Вопрос 2 +-> Конец
+ ^
+-> Вопрос 3 +-+
What kind of AI bot do you have there,
he doesn’t know how to think
, a message comes from a he sees that from a
comes from b he sees that from b
he doesn’t think anything
Why reinvent the wheel? There are tons of ready-made platforms for creating bots on the Internet.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question