Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Trying to make a discord js kick command, but it kicks based on user id

Writer Sebastian Wright

I am trying to make a discord kick command that kicks a specific person on my server. Yes, it isn't very practical but this is exactly what my bot needs. This is my code:

if (command == "kickderek") { let member = message.guild.member("<@userid>"); member.kick(); kickd = Math.floor(Math.random() * 10000); if (kickd == 1) { member.kick(); message.channel.send("God has accepted your wish and derek has been kicked"); return; } else { message.channel.send("Try again, you failed kicking derek"); return; }
}

Whenever I run it I get the error:

/home/admin/discbot/disc.js:357 member.kick(); ^
TypeError: Cannot read property 'kick' of null
at Client.<anonymous> (/home/admin/discbot/disc.js:357:16)
at Client.emit (events.js:326:22)
at MessageCreateAction.handle (/home/admin/discbot/node_modules/)
at Object.module.exports [as MESSAGE_CREATE] (/home/admin/discbot/node_modules/)
at WebSocketManager.handlePacket (/home/admin/discbot/node_modules/)
at WebSocketShard.onPacket (/home/admin/discbot/node_modules/)
at WebSocketShard.onMessage (/home/admin/discbot/node_modules/)
at WebSocket.onMessage (/home/admin/discbot/node_modules/ws/lib/event-target.js:125:16)
at WebSocket.emit (events.js:314:20)
at Receiver.receiverOnMessage (/home/admin/discbot/node_modules/ws/lib/websocket.js:797:20)

Can someone help me solve this problem, I have been working on it for hours.

1 Answer

Cannot read property 'kick' of null means that the member part of member.kick if not defined, meaning that when you defined member, let member = message.guild.member('<@userid>'); is returning null.
Just pass the userid without the bracket notation: let member = message.guild.member(USERID);

P.S. If you're trying to only kick after the RNG roll, you have a typo in your code: You call kick before the rng rolls

member.kick();
kickd = Math.floor(Math.random() * 10000);
if(kickd == 1){
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy