A
A
Artem Melnykov2019-12-08 19:04:40
JavaScript
Artem Melnykov, 2019-12-08 19:04:40

Why can't the bot kick?

Good afternoon!
There were problems because the bot does not want to kick even the most ordinary participant.
Event code:

spoiler

if (message.content.startsWith("!kick")) { if(!message.member.roles.some(r=>["Administrator", "Moderator"].includes(r.name))) { return message.reply("Извините, но у вас нет прав!");
} let mem = message.content.split(' ');
let member = mem[1]; var reason = mem[2];
if(!reason) reason = "Без причины";
member.kick(reason);
message.reply(member.user.tag + " бы
л кикнут " + message.author.tag + "!Причины
" + reason);
}

Log:
spoiler

(node:13936) UnhandledPromiseRejectionWarning: TypeError: member.kick is not a function at Client. (/data/data/com.termux/files/home/musicbot/index.js:43:9)
at Client.emit (events.js:210:5) at MessageCreateHandler.handle (/data/data/com.termux/files/home/musicbot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34) at WebSocketPacketManager.handle (/data/data/com.termux/files/home/musicbot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65) at WebSocketConnection.onPacket (/data/data/com.termux/files/home/musicbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/data/data/com.termux/files/home/musicbot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/data/data/com.termux/files/home/musicbot/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:210:5)
at Receiver.receiverOnMessage (/data/data/com.termux/files/home/musicbot/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (events.js:210:5)
(node:13936) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13936) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Only possible without additional libraries, purely on discord.js.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-12-08
@NickProgramm

Only GuildMember's message can be kicked: https://discord.js.org/#/docs/main/master/class/Gu...
You can't just teleport him out of nowhere.
If you want to create a command equivalent:
Then you need to write this piece of code like this:

if (message.content.startsWith("!kick")) {
  var member= message.mentions.members.first(); //Это и будет объект GuildMember
  member.kick(); //Кик
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question