I started building a Discord bot and the first function I made was kicking members. This is the code
const Discord = require("discord.js");
const { prefix, token } = require("./config.json");
const client = new Discord.Client();
client.once("ready", () => {
console.log("Ready!");
});
client.on("message", (message) => {
if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {
if (message.content.startsWith(`${prefix}kick`)) {
let member = message.mentions.members.first();
member.kick().then((member) => {
message.channel.send("```" + member.displayName + " has been kicked ```");
});
}
}
});
client.login(token);
If someone without the kick and ban permission tries it nothing happens so this part is working. If an admin types eg. :kick @someone then someone will be kicked. But if an Admin types :kick (without someone's username) I get an error and the bot stops working until I restart it manually. This is the error:TypeError: Cannot read property 'kick' of undefined. What can I do to make this fully working?