M
M
Maxim Yumikov2020-07-04 04:58:12
Python
Maxim Yumikov, 2020-07-04 04:58:12

Bot not sending message to conversation?

Hey Habr! I ran into a problem...
The bot simply does not work in a conversation, gave access to the correspondence, turned on longpoll, in the settings longpoll gave access to everything and silence...

import vk_api
from vk_api.utils import get_random_id
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import requests
from vk_api.longpoll import VkEventType


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

vk = vk_session.get_api()
longpoll = VkBotLongPoll(vk_session, "айди сообщества")

for event in longpoll.listen():
    if event.type == VkBotEventType.MESSAGE_NEW:
        if event.obj.text == 'тест':
            if event.from_chat:
                vk.messages.send(
                        random_id=get_random_id(),
                        peer_id=event.obj.peer_id,
                        message="Ну вроде бы работает")

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alekssamos, 2020-07-04
@OhMySenpai

He needs not only to give access to all correspondence, just like everyone else, not only by mentions, but also to make him an administrator. That's when it will work without mentioning it. I also came across this
UPD: for some reason, through a dot in new versions does not work.

for event in longpoll.listen():
    if event.type == VkBotEventType.MESSAGE_NEW:
        m = event.object.message
        if m["text"] == 'тест':
            vk.messages.send(
                    random_id=get_random_id(),
                    peer_id=m["peer_id"],
                    message="Ну вроде бы работает")

C
cython, 2020-07-04
@cython

In order for the bot to receive a message in a conversation, you need to address it specifically, either as a reply to the bot's message, or via @bot_name or *bot_name and then the text.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question