I need to make that not everyone can kick members, but only who have permissions Here is my kick system-
client.on('message', message => {
if (!message.guild) return;
if (message.content.startsWith(' kick')) {
const user = message.mentions.users.first();
if (user) {
const member = message.guild.members.resolve(user);
if (member) {
member
.kick({
reason: 'They were bad!',
})
.then(() => {
message.channel.send(`Successfully kicked ${user.tag}`);
})
.catch(err => {
message.channel.send('I was unable to kick the member');
console.error(err);
});
} else {
message.channel.send("That user isn't in this guild!");
}
} else {
message.channel.send("You didn't mention the user to kick!");
}
}
});
CodePudding user response:
Welcome to StackOverflow! And, from the look of things, the beginning of your bot-making journey.
You can use message.mentions.members.first()
to skip a step and simplify your code somewhat.
As mentioned above, you'll want to use member.permissions.has()
to check if a member has the MANAGE_MEMBERS
permission, or whatever other permission you want to check for. (See Permissions.FLAGS
)
Also, consider moving away from using message-based commands, if possible. For a small personal bot, it's not really an issue, but Discord is really pushing the new Interactions
(aka slash commands) system, which you can read more about here (discord.js guide) and here (official, discord.com).
CodePudding user response:
if (!message.member.permissions.has("KICK_MEMBERS")) {
return message.reply({content: `You need permissions to use command`})
}