Answer the question
In order to leave comments, you need to log in
How to set a prefix for a VKonakte chatbot in Python?
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api
import wikipediaapi
wiki_wiki = wikipediaapi.Wikipedia('ru')
vk_session = vk_api.VkApi(token='мой токен')
vk = vk_session.get_api()
longpoll = VkBotLongPoll(vk_session, id моего бота)
Wiki = ['Википедия', 'Wikipedia', 'Вики','Wiki','википедия','вики','wikipedia','wiki']
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() in Wiki:
vk.messages.send(peer_id=event.object.peer_id, message='Введите запрос', random_id=0)
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and not event.from_me:
if event.object.peer_id != event.object.from_id:
page_py = wiki_wiki.page(event.object.text.lower())
if page_py.exists() == False:
vk.messages.send(peer_id=event.object.peer_id, message='Ошибка:\nТакой страницы не существует', random_id=0)
if page_py.exists() == True:
vk.messages.send(peer_id=event.object.peer_id, message='Обращайтесь\n' + str(page_py.title) + '\n' + str(page_py.summary), random_id=0)
break
Answer the question
In order to leave comments, you need to log in
for count in range(len(Wiki)):
if event.object.text.find(Wiki[count]) >= 0:
True
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question