Permissions help with Delete Messages

I want to delete messages with the discord.js bot, but I don’t want to let anyone without the permissions of AMINISTRATOR to delete messages. How would I make it so only people with this specific permission can do this?

Assuming you are using discord.js:

1 Like

It depends on what language you are using.
With discord.js it’s easy.
Put this code before you delete the messages.

// check if they have administrator permission
if(!message.member.hasPermission("ADMINISTRATOR") {
// put your code here if they DO NOT have administrator permission
}

You shouldn’t be using Discord.js V11, since it will become unusable in the near future.

Use V12.

// check if they have administrator permission
if(!message.member.permissions.has("ADMINISTRATOR")) {
// put your code here if they DO NOT have administrator permission
}
1 Like

Just letting you know, hasPermission is still a method on discord.js v12.

1 Like

Thank you, everybody!