pythonbot/dan63047bot.py

35 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
def write_msg(user_id, message):
vk.method('messages.send', {'user_id': user_id, 'message': message})
# API-ключ созданный ранее
token = "6a9c267cd469388709a9e9acaddbe0aa81a0abbf12239b3e597a31729ffbddb9c88e80a443554c918b8f7"
# Авторизуемся как сообщество
vk = vk_api.VkApi(token=token)
# Работа с сообщениями
longpoll = VkLongPoll(vk)
# Основной цикл
for event in longpoll.listen():
# Если пришло новое сообщение
if event.type == VkEventType.MESSAGE_NEW:
# Если оно имеет метку для меня( то есть бота)
if event.to_me:
# Сообщение от пользователя
request = event.text
# Каменная логика ответа
if request == "привет":
write_msg(event.user_id, "Хай")
elif request == "пока":
write_msg(event.user_id, "Пока((")
else:
write_msg(event.user_id, "Не поняла вашего ответа...")