Y
Y
y_o_l_k_i_n___e_g_o_r2021-03-19 10:21:31
Python
y_o_l_k_i_n___e_g_o_r, 2021-03-19 10:21:31

How to make the vk bot work both in a conversation and in private messages?

There is a code:

bot_ls = vk_api.VkApi(token=TOKEN)
ls_longpoll = VkLongPoll(bot_ls)

for event in longpoll.listen():
    for event in ls_longpoll.listen():
        if event.type == VkEventType.MESSAGE_NEW and event.to_me:
            bot.method('messages.send', {'user_id': event.user_id,
                                         'message': 'Привет!',
                                         'random_id': 0})
    # === далее - отправка сообщений в  беседы


It only works if I'm PMing, but I need it to work in both chat and private messages.

How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-03-19
@HemulGM

READ THE DOCUMENTATION. Then you need to send not to the user (user_id), but to the peer - peer_id .
DO NOT USE THE API WRAPPER FOR ANYTHING WITHOUT AT LEAST THE SURFACE STUDY OF THE API ITSELF

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question