Answer the question
In order to leave comments, you need to log in
I made a bot to work in a conversation. But he responds to absolutely any message. What to do?
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api
import random
vk = vk_api.VkApi(token="token")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, vk group id)
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
if event.object.text.lower() == "привет бот" or "Привет бот" or "эй бот" or "Эй бот":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "хай",
"random_id": 0 })
Answer the question
In order to leave comments, you need to log in
Make the right condition.
if event.object.text.lower() == "привет бот" or "Привет бот" or "эй бот" or "Эй бот":
reads "if the message is "hello bot" or always". or
does not list the value options to be compared with, but the condition options (which, in this case, should be comparisons of the result event.object.text.lower()
with different strings. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question