Search code examples
javascriptdiscord.js

How to stop Admin's messages from getting filtered and blocked || Discord.js V.14


This is my code:

module.exports = {
    name: "messageCreate",
    async execute(message) {
        if (!message.guild || message.author.bot) return;

        if (message.content.includes("@everyone")) {
            message.delete();

            message.channel.send({ content: `${message.author}, you don't have permission to tag everyone!`});

        }
    }
}

I want my bot to ignore all the messages with the text "@everyone" from the roles that have Administrator permission enabled and delete the messages from all the other roles.


Solution

  • Your condition to delete a message is if it includes @everyone and member is not an admin:

    if (message.content.includes('@everyone') && !message.member.permissions.has(PermissionFlagBits.Administrator))
    

    Keep in mind this may still produce a ghost ping for all the members, it's best to suppress mass mentioning through Discord roles