L
L
letoqq2021-06-06 19:29:57
Python
letoqq, 2021-06-06 19:29:57

How to implement a user kick from a conversation?

You need to kick a user from the conversation example:
/kick 123
123 is the user id.
The script is written on the vk_api library using LongPoll. My script:

import vk_api, json
from vk_api.longpoll import VkLongPoll, VkEventType

vk_session = vk_api.VkApi(token = '#')
longpoll = VkLongPoll(vk_session)

def sender(id, text):
  vk_session.method('messages.send', {'chat_id' : id, 'message' : text, 'random_id' : 0})

for event in longpoll.listen():
  if event.type == VkEventType.MESSAGE_NEW:
    if event.to_me:
      if event.from_chat:
        msg = event.text.lower()
        id = event.chat_id
        if msg in ['привет', 'hi', 'ку']:
          sender(id, f'Привет бро!')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WolfInChains, 2021-06-06
@letoqq

An example for a group, but for a user it is easy to rewrite, almost nothing changes
How to make a kick command in VK api?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question