Y
Y
Yaroslav692019-04-07 20:06:46
API
Yaroslav69, 2019-04-07 20:06:46

How to identify VK conversation admins?

Hello. Need help. I have a VK bot on NodeJS , there is a command that allows you to change the name of the conversation. I want only admins and the creator of the conversation to be able to do this. How can I find out the admins and the creator, for example, through messages.getConversationMembers ?
Help me please.
Here is the code:

updates.hear(/^\бназвание (.*)/i, async (context) => {
  if (!context.isChat) return context.send(`⚠️Эта команда работает только в беседах!`)
  cn[context.chatId] = context.$match[1]
  try {
         await vk.api.messages.editChat({chat_id: context.chatId, title: cn[context.chatId]})
         await context.send(`Новое название беседы успешно установлено!`)
         } catch (e) {
         console.log(e)
         return context.send(`Произошла ошибка! Возможно, вы не выдали мне администратора!`)
         }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-04-07
@Yaroslav69

let users = await vk.api.messages.getConversationMembers({peer_id: context.peerId}); 
let user = users.items.find((item) => item.member_id === context.senderId);
if (user.is_admin) {
  // админ
} else {
  // не админ
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question