S
S
Smirnovoleg4562020-12-02 16:01:41
In contact with
Smirnovoleg456, 2020-12-02 16:01:41

How to kick all participants in a conversation using the vk api?

Hello, how to kick all participants from a conversation? VK API, PYTHON

Answer the question

In order to leave comments, you need to log in

5 answer(s)
W
WolfInChains, 2020-12-02
@Smirnovoleg456

import vk_api

vk_session = vk_api.VkApi(token='токен от стр')
vk = vk_session.get_api()


peer_id =  # тут чат айди + 2000000000. Пример - 2000002203, где 2203 - чат айди
my_id =  # айди страницы, которая будет кикать

users = vk.messages.getConversationMembers(peer_id=peer_id)['items']
for user in users:
    if user['member_id'] != my_id:
        vk.messages.removeChatUser(chat_id=peer_id - 2000000000, member_id=user['member_id'])

Z
ZIK1337, 2020-12-02
@ZIK1337

https://vk.com/dev/messages.removeChatUser

T
Timtaran, 2020-12-02
@Timtaran

1. get a list of all participants.
2. kick everyone from this list.

D
Dmitry Belyaev, 2016-11-15
@bingo347

In js, strings in memory are stored in UTF16-LE encoding (2-4 bytes per character, in most cases 2) and the library works with the bytes of the string in it
. The C ++ library accepts std:: vector as input when simply converting the string into which you get a vector of bytes in the user's current encoding, most likely a single byte
Encode the C++ string in UTF16-LE before encoding - then get the same result

R
Rsa97, 2016-11-15
@Rsa97

Libraries add different endings if the string is not a multiple of eight characters.
In JS:

if (block.length < 8) {
        var count = 8 - block.length;
        while (0 < count--) {
          block += "\0";
}

In C++:
size_t padding_length = dst.size() % sizeof(uint64_t);
  if (padding_length == 0) {
    padding_length = sizeof(uint64_t);
  } else {
    padding_length = sizeof(uint64_t) - padding_length;
  }

  for (size_t i = 0; i < padding_length; ++i) {
    dst.push_back(static_cast<char>(padding_length));
  }

If you don't want to change the code of the libraries - add the strings yourself to a length that is a multiple of eight.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question