S
S
Sasha Bower2019-12-24 14:32:03
Python
Sasha Bower, 2019-12-24 14:32:03

What operator should be used for enumeration instead of or?

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() == "hello bot" or "hello bot " or "hey bot" or "Hey bot":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "hi",
"random_id": 0 })

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2019-12-24
@Darkcan

...
if event.object.text.lower() in ["привет бот", "Привет бот", "эй бот", "Эй бот"]:
...

H
hexbat, 2019-12-24
@hexbat

if ' bot' in event.object.text.lower()
But will respond to phrases like "Hi bot"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question