How to organize a kick from a conversation?

  • 0
    How do I 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 is that the user ID is not known. In vk.api I realized that somehow it is possible to organize through forward, but how exactly?
    JavaScript Anonymous, Nov 28, 2019

  • 1 Answers
  • 0
    In VK it is possible not only to forward messages, but also to reply to them.

    As a consequence, 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 the existence of the object, the message to which we replied, and if it exists, we take the user ID from it.

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!