Answer the question
In order to leave comments, you need to log in
Bot does not work in VK, why?
Hello, an example of a bot does not hear messages in the PM. It does not give errors when starting.
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
main = токен'
vk_session = vk_api.VkApi(token = main)
session_api = vk_session.get_api()
longpoll = VkLongPoll(vk_session)
def sender (id, text):
vk_session.method('messages.send',{'user_id' : id,'message' : text,'random_id' : 0})
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
msg = event.text.lower()
id = event.user_id
if msg == 'Да':
sender(id,'Нет')
Answer the question
In order to leave comments, you need to log in
If there should be messages from PM, try the following:
1) open quotes before the token: 'token'
2) replace event.to_me with event.from_user
3) add the peer_id parameter to the messages.send method, get it like this: "event.peer_id" , instead of user_id, it can be removed altogether
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question