Vk-bot responds in the BOS, but does not respond in conversations, what to do?

I wrote a short bot for testing functions. The catch is that it only responds in group messages, but not in chats. I can't find the reason, no error appears.

from vk_api.longpoll import VkLongPoll, VkEventType
import vk_api
from datetime import datetime
import time


def write_msg(user_id, random_id, message):
    vk_session.method('messages.send', {'user_id': user_id, "random_id": 
random_id, 'message': message})


token = "тут мой токен"
vk_session = vk_api.VkApi(token=token)

session_api = vk_session.get_api()
longpoll = VkLongPoll(vk_session)


for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
        if event.from_user:
            write_msg(event.user_id, event.random_id, "первая фраза")
        elif event.from_chat:
            write_msg(event.сhat_id, event.random_id, "вторая фраза")
    time.sleep(1)

2 answers

  1. The bot must be added to the conversation (To do this, you must enable Возможности ботов (Управление->Сообщения->Настройки для бота) and allow you to add it to conversations (ibid.)).

  2. To use Long Poll, you must enable Long Poll Api (Управление->Настройки->Работа с API->Long Poll API) and specify which events you want to catch (Типы событий).

  3. For a community bot, you should use vk_api.bot_longpoll.

  4. In order for the bot to see the message, it must be mentioned (for example, @club666666), or the conversation administrator must give it a full name. access to correspondence.

I advise you to look at: I get an error when trying to send a message to a conversation via VK_API Python

Yesterday I encountered such a problem myself, today I described the solution: VkBotLongPoll ignores messages from the conversation

 1
Author: Михаил Муругов, 2019-03-14 09:04:23

You probably forgot to check the box "Allow adding community to conversations" since even longpoll. listen() is not processed This is the setting to go to Group Settings -> Messages -> Bot Settings enter a description of the image here

 0
Author: Melis, 2019-03-13 18:05:05