Answer the question
In order to leave comments, you need to log in
How to make the bot reply to a message with two conditions?
I want to make the bot respond to the message, for example:
-Bot, how much Ilya is beautiful
- Ilya is 100% beautiful.
How can I get the second part of the question "Ilya is beautiful" in response to the bot. So that I don’t try, he writes either “Bot, how handsome Ilya is 100%” or simply ignores.
import vk_api
import random
import requests
import urllib3
from vk_api import VkUpload
from vk_api.utils import get_random_id
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from infobot import opozd
from infobot import anek
def write_messages(sender, message):
authorize.method('messages.send', {'chat_id': sender, 'message': message, 'random_id': get_random_id(), 'attachment': ','.join(attachments)})
def write_messages_stick(sender, number,):
authorize.method('messages.send', {'chat_id': sender, 'sticker_id': number, 'random_id': get_random_id()})
token = 'Токен'
image = "r.jpg"
authorize = vk_api.VkApi(token = token)
longpoll = VkBotLongPoll(authorize, group_id=204284522)
upload = VkUpload(authorize)
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.from_chat and event.message.get('text') !="":
reseived_message = event.message.get('text')
textper = event.message.get('text')
sender = event.chat_id
attachments = []
upload_image = upload.photo_messages(photos=image)[0]
stickers = ['162', '53826', '48', '4342', '9060', '10256', '10676', '2467', '2164', '9332', '53832', '53823']
t = ['1', '2']
if reseived_message == "Привет" or reseived_message == "привет" or reseived_message == "Бот привет" or reseived_message == "Бот, привет":
write_messages(sender, "Привет!")
elif reseived_message == "Пока":
write_messages(sender, "До свидания")
elif reseived_message == ("Бот насколько процентов" + textper):
write_messages(sender, (textper + " " + str(random.randint(0,200)) + "%"))
Answer the question
In order to leave comments, you need to log in
import re
pattern = re.compile(r'Бот насколько процентов (\w+) красивый')
<...>
elif pattern.search(reseived_message):
write_messages(sender, pattern.search(reseived_message).group(1) + " красивый на " + str(random.randint(0,200)) + "%")
Depending on what you need, you can use if instead of elif, then 2 conditions will work for you
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question