T
T
TheBeJIIHiu2021-08-03 19:21:22
PHP
TheBeJIIHiu, 2021-08-03 19:21:22

How to display the ID of the admins of the VK conversation?

I am writing a VK bot in php and using the simplevk 2.0 library.

How do I get a list of conversation admins? Something stupid. ID administrators - I do not understand how

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
RINAMI, 2021-08-03
@RINAMI

As I understand it, you need to check for the administrator, to do this, create a file with the .py extension, and create an array in it, an example on vk_api (python):

user = event.object.message['from_id']
admins = []
if user in admins:
   #действия

In general, it’s better to do this (if you don’t have a database) create a txt file, and then like this:
checker = open('file_name', 'r')
shecker = checker.read()
checker.close()
user = event.object.message['from_id']
mes = event.object.message['text']
if mes == 'text' and user in shecker:
      #действия

Also, you can add a user to the admin list and exclude him:
def adminadder(): #ADD
      adder = open('file_name', 'a')
      radder = adder.write(mes.split(' ')[1] + '\n')
      adder.close()
      pass
if mes.split(' ')[0] == 'adminadd':
   adminadder()
def adminremover(): #REMOVE
      rem = open('file_name', 'r')
      lines = rem.readlines()
      rem.close()
      rem = open("administration.txt", "w")
      for line in lines:
        if line != mes.split(' ')[1] + "\n":
            rem.write(line)
            rem.close()
            pass
if mes.split(' ')[0] == "adminremove':
   adminremover()

M
maksam07, 2021-08-03
@maksam07

I don’t know how to use the library, but at least on the page of this library there is a chat in VK, I wonder why they didn’t apply there.
For your question, the method will help: messages.getConversationMembers

B
billy_herington, 2021-08-03
@billy_herington

What is the problem? in vk api there is a method "messages.getConversationMembers"( https://vk.com/dev/messages.getConversationMembers )
and this is what it returns
61099bab373f8723496677.png
the simplest example

<?php

 define('TOKEN', '');
 
 $ch = curl_init('https://api.vk.com/method/messages.getConversationMembers');

 $data = [
 	'access_token'   => TOKEN,
 	'v'		         => '5.144',
 	'peer_id' 		 => '',
 	'count'  		 => 200
 ];

 curl_setopt_array($ch, [
 	CURLOPT_RETURNTRANSFER   => 1,
 	CURLOPT_HEADER                    => 0,
 	CURLOPT_POST                         => 1,
 	CURLOPT_POSTFIELDS              => $data
 ]);
 
 $result = curl_exec($ch);

 if ($result === false)
 	die();

 curl_close($ch);

 $result = json_decode($result, true);

 $adminList = [];

 foreach ($result['response']['items'] as $item)
 {
 	if (array_key_exists('is_admin', $item)  && $item['is_admin'] == true)
 	{
 		$adminList[] = $item['member_id'];
 	}
 }

 var_dump($adminList);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question