P
P
PegasusPega2020-11-15 04:30:35
JavaScript
PegasusPega, 2020-11-15 04:30:35

How to organize a kick from a conversation?

How to organize a kick from a conversation using a forwarded message?
There is this code

if(msg.peerType != "chat") return send("❌ || Данная команда работает только в беседах!");
  	if(!msg.forwards) return send("❌ || Не обнаружено пересланного сообщения!");
  var g23 = msg.forwards[0];
vk.api.messages.removeChatUser({chat_id: msg.peerId-2000000000, user_id: g23.senderId})
send("⚠Пользователь исключён!");

As I understand it, the forwarded message is not checked at all. And after that, the expected error that the user ID is not known. In vk.api, I realized that somehow it can be organized through forward, but how exactly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semin, 2020-11-17
@PegasusPega

In VK, it is possible not only to forward messages, but also to reply to them.
As a result, vk-io provides a replyMessage object in the new message event.

let removedUser = (msg.replyMessage ? msg.replyMessage.senderId : msg.forwards[0].senderId);
vk.api.messages.removeChatUser({chat_id: msg.chatId, user_id: removedUser});

In this code, we check for the existence of the message object that was replied to, and if it exists, we take the user ID from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question