My Profile Photo

Bencey's Blog

Informing the world about the application of Technology.
If you are looking for Tier III Technologies click the button below

Discord.js Advertising Filter

Welcome everyone to the third discord.js guide. In this post, I will be showing you how you can create an advertising filter for your bot.

This bot will delete any messages that contain https, http or and will post a log message to your server logs

To begin you will need to add the following into your message event

        if (message.content.includes("https://" || "http://" || "")) {
            // If the website is one of my sites the bot will ignore it
            if (message.content.includes("")) return;
            // If the filter is not enabled the bot will not filter messages
            // If you are not using per guild settings uncomment the lines below
            // let filterEnabled = True
            // if (filterEnabled == "false") return;
            // If you are not using per guild settings comment out the line below
            if (message.settings.filterEnabled == "false") return;

            // If the user has manage message perms (staff member) They will not be affected by the advertisement filter
            if (message.member.hasPermission('MANAGE_MESSAGES')) return
            // Creates an embed to alert staff that someone attempted to advertise
            let embed = new Discord.RichEmbed()
                .setDescription("Attempted Advertisement")
                .setColor(`#f28621`) // Sets the color of the embed
                .setAuthor(, // Sets the author of the embed which is the user who advertised
                .addField("Message", message.content) // Adds what the advertisement message was
                .setFooter("Advertisement Filter")

            let channel = message.guild.channels.find(c => === message.settings.modLogChannel)
            //if it cannot find a logs channel the bot will return
            if (!channel) {
                return`${} Attempted to advertise`)




The first thing the bot checks for is if the message contains https, http or (Discord invites) If the message does contain these then it will check to see if it is one of my domains, after that if the filter is enabled it will post a log message to the server log channel and delete the user’s message. It will also see if the user is a member of staff and if they are it will not remove their message

Hope this guide helps you to add a filter for your discord bot :)