Answer the question
In order to leave comments, you need to log in
Why do some vk api events not work in python?
I started studying the vk api documentation and wanted to write my own bot in python. I say right away - I gave him all the rights, generated the key, etc. There is this page - https://vk.com/dev/groups_event , it describes all the events that can be used in the vk api. I do everything through Long Poll. The simplest, reaction to a specific user message, works (message_new event) through the following code:
import requests
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id
vk_session = vk_api.VkApi(token='a94555a01de3af80559b4184b10c33d5b8c88203afb449090b4bc0a06fa7485e3be0114453a3bf7681f1f')
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.text:
if event.text == 'привет' or event.text == 'здарова':
vk.messages.send(user_id=event.user_id, random_id=get_random_id(), message='Привет!')
print('Ja')
elif event.type == VkEventType.PHOTO_NEW:
vk.messages.send(user_id=event.user_id, random_id=get_random_id(), message='Привет!')
print('Ja')
Answer the question
In order to leave comments, you need to log in
Added a line:
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
So read the bot_longpoll documentation well. These methods are not listed there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question