Answer the question
In order to leave comments, you need to log in
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
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:
#действия
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:
#действия
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()
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
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
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 questionAsk a Question
731 491 924 answers to any question