How to make a command for only people with a specific permission

Personally I have made a ban,kick and clear command but what i’m having trouble with is permissions because anyone can just use those commands and ban/kick and mess up the server with the bot i just need to really know how to make it so then the commands are for people who have a specific permission only and how to make it send a message if they don’t have the permission

Add this to your kick, ban or clear command

if (!message.member.hasPermission(“KICK_MEMBERS”)) return message.reply(“No Permission!”)

You can replace the KICK_MEMBERS to any permission you want.

EDIT: If you are using Discord.js v13 then use this:

if (!message.member.permissions.has(“Permissions.FLAGS.KICK_MEMBERS”)) return message.reply(“No Permission!”)

3 Likes

I have tried that many times and it just spams the No Permission Message whenever people say something

because you add it inside a command
example

if (message.content === "/ban") {
// the code above 
}

ty it worked but instead i used an else statement

there are various ways to include that code, that was one of them.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.