Answer the question
In order to leave comments, you need to log in
How to make waiting for a message from the user in Python 3?
I made a bot for VK, in python 3, and I needed the bot to wait for a message.
Here is an example code:
import vk_api
import time
import json
while True:
try:
# главный цикл
messages = vk.method("messages.getConversations", {"offset": 0, "count": 20})
if messages["count"] >= 1:
id = messages["items"][0]["last_message"]["from_id"]
body = messages["items"][0]["last_message"]["text"]
elif body == "Пароли":
vk.method("messages.send", {"peer_id": id, "message": "Введите ваш пароль: "})
if body == "*пароль*":
vk.method("messages.send", {"peer_id": id, "message": "*все пароли*"})
else:
vk.method("messages.send", {"peer_id": id, "message": "Не верный пароль: "})
time.sleep(0.5)
except Exception as E:
time.sleep(1)
Answer the question
In order to leave comments, you need to log in
in general, you receive messages incorrectly
, there are special tools for this: Bots LongPoll API and Callback API
, most likely, it will be easier to solve your problem with them
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question