Answer the question
In order to leave comments, you need to log in
VK bot not working in conversations, why?
Hello, an example of a bot, hears messages in the community LAN, does not hear in conversations. The admin gave out to the bot in a conversation, long pool version 5.107, all permissions.
What can be wrong?
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api import VkUpload
from vk_api.utils import get_random_id
vk_session = vk_api.VkApi(token="Token")
session_api = vk_session.get_api()
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
#chat_id
for event in longpoll.listen():
print(event)
if event.type == VkEventType.MESSAGE_NEW:
print(event.text)
print(event)
Answer the question
In order to leave comments, you need to log in
Instead
VkLongPoll, VkEventType
use
VkBotLongPoll, VkBotEventType
Example
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="ТОКЕН")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, АЙДИ ГРУППЫ)
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.method("messages.send", {**locals(), "random_id": 0})
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id: #Для беседы
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
if event.object.peer_id == event.object.from_id: #Для Лс
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
except Exception as e:
print(repr(e))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question