Skip to content
Advertisement

discord.js problem: How can I implement a command that will only allow people with the kick and administrator permission to use the command

I used this command for kicks, but everyone in the server can now kick. I just want to add something that will only allow people with the admin and kick permissions to use it.

module.exports = {
    name: 'kick',
    description: "This command kicks a member!",
    execute(message, args){
        const target = message.mentions.users.first();
        if(target){
            const memberTarget = message.guild.members.cache.get(target.id);
            memberTarget.kick();
            message.channel.send("User has been kicked");
        }else{
            message.channel.send(`error. solution; please specify one person to kick, maybe that person has higher permissions than me and you`);
        }
    }
}

Answer

You have to implement something like

if(!message.member.hasPermission("ADMINISTRATOR") && 
!message.member.hasPermission("KICK_MEMBERS")) return mesage.channel.send("You don't 
have permission to kick a member");

at the beginning of your kick command code.

Advertisement