A
A
Alice Cherry2019-08-15 15:36:56
Python
Alice Cherry, 2019-08-15 15:36:56

Why doesn't the bot receive messages from the VKontakte conversation?

The VK bot sees messages sent to it via PM (and returns a message with the same text), but does not respond to messages in the conversation (even print (event) does not detect). I found a similar question, the answer says that messages should be addressed to him , but I still don’t understand what this means. Works through BotsLongPoll. What's wrong?

Screenshots

В беседе:
5d5550c92aecd765203900.png
В личке:
5d5550dc064b4093809060.png

Python code, aiovk library

session = TokenSession(access_token = 'token')
api = API(session)
lp = longpoll.BotsLongPoll(api, mode=2, group_id=group_id)

async def main():
    try:
        event = await lp.wait()
    except asyncio.TimeoutError:
        pass
    else:
        if event['updates'] != []:
            if event['updates'][0]['type'] == 'message_new':        
                await api.messages.send(
                    user_id=event['updates'][0]['object']['user_id'],
                    random_id=int(time.time()*10000),
                    message=event['updates'][0]['object']['body'])
    asyncio.get_event_loop().create_task(main())
        
loop = asyncio.get_event_loop()
loop.create_task(main())
loop.run_forever()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alice Cherry, 2019-08-17
@ytochka_alisa

Oh yo, everything turned out to be much easier. I used version LongPoll 5.50 - put 5.101 and everything comes as it should. Thanks to all)
5d58194e87fa8728641261.png

S
Stockholm Syndrome, 2019-08-15
@StockholmSyndrome

if event['updates'][0]['type'] == 'message_new':

well, maybe this is not the only event that came from the long poll, check all events, and not just the first one
, check if the bot has access to mentions and commands in the conversation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question