Answer the question
In order to leave comments, you need to log in
VK API, Python. How to eliminate interference from other users in the message thread with the bot?
I have a VK bot that, upon receiving a "Report a bug" message, prompts the user to enter text to describe what happened, which is then sent to the admin. Here is that part of the code:
def message_fail():
try:
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
mess = str(event.user_id)
mess_fail = event.text
vk.messages.send(keyboard = keyboards.keyboard1.get_keyboard(), user_id=event.user_id, message='Сообщение отправлено администратору!.', random_id = random_id())
vk.messages.send(user_id=admin_id, message='Поступило сообщение об ошибке от vk.com/id' + mess + '\n\nТекст обращения: ' + mess_fail, random_id = random_id())
break
except Exception as e:
vk.messages.send(keyboard = keyboards.keyboard.get_keyboard(), user_id=event.user_id, message="Произошла неизвестная ошибка", random_id = random_id())
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
if event.text == 'Сообщить об ошибке':
vk.messages.send(user_id=event.user_id, message='Опишите ошибку, как можно подробнее', random_id = random_id())
message_fail()
for event in longpoll.listen():
, but I could not otherwise implement the message chain. Please tell me how to fix this. I will be grateful.
Answer the question
In order to leave comments, you need to log in
If you want it to be possible through a conversation, then try to connect a database to your bot. For example sqlite3: create a database, set the user ID column (column) 1, create another column for what it currently writes about an error (column 2) (then you can add more if necessary). After the user writes "Report an error", add some value to column 2 (For example, the standard 0, and you added 1), check each message event and check the ID through the database (and also add if it is not there, and just also check whether it exists or not). If this user wrote an error - change the value of column 2 to 0 and display his message to yourself. It is possible in another way, just the bot would write to him in private messages, and then you would have brought it to yourself. If you need a code, then I will write it when I wake up.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question