简体   繁体   中英

Add perms for a !purge command

Hello i have tried to create a permission based purge commands This is it without any permmision code:

module.exports = {
    name: 'purge',
    description: "Deletes Messages",
    async execute(message, args){
        if(!args[0]) return message.reply("Please enter the amount of messages you wish to delete.");
        if(isNaN(args[0])) return message.reply("The specified charecters are not numbers, please enter a real number.");

        if(args[0] > 100) return message.reply("You have entered a number over 100, please enter a number under that value.");
        if(args[0] < 1) return message.reply("You have entered a number under 0, you must enter a number above 0");

        await message.channel.messages.fetch({limit: args[1]}).then(messages =>{
            message.channel.bulkDelete(messages)
        });
    }
}

Can someone tell me how to add a permission based handler to this Thank you

if (message.member.hasPermission("MANAGE_MESSAGES")) {
    // the guild member has permission
}

https://discordjs.guide/popular-topics/permissions.html

You can add this to your code: if(.message.member.hasPermission("MANAGE_MESSAGES")) { message.channel.send("message to send if member haven't got the permission") }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM