user13461894
user13461894

Reputation:

How I can make Discord Invite filter?

I want to make a working Discord Invite filter, which is configurable and you can advertise on channels added to exception list. I have created the code earlier, but it does not work properly. Here is the code:

if (message.content.includes("https://discord.gg/")) {
    if (!db.fetch(`${message.guild.id}.antiad`) ||
      db.fetch(`${message.guild.id}.antiad`) == "disabled" ||
      message.channel.id == db.fetch(`${message.guild.id}.exceptionChannels.${message.channel.id}`))
      return;
    try {
      message.delete();
      let embed = new Discord.RichEmbed()
        .setDescription(
          `<@${message.author.id}>, you cannot advertise here!`
        )
        .setColor("RED");
      message.channel.send(embed);
    } catch (err) {
      console.log(err);
    }
  }

I am not getting any error messages in my console, by the way. Anyone knows how to help me with this? Thanks for any help.

Upvotes: 2

Views: 504

Answers (1)

Syntle
Syntle

Reputation: 5174

You could create a RegExp and test to see if the content contains an invite link:

const inviteRegex = new RegExp(/(https?:\/\/)?(www\.)?(discord\.(gg|io|me|li)|discordapp\.com\/invite)\/.+[a-z]/g);
if (!inviteRegex.test(message.content) {
    message.delete({ reason: 'Advertising' });
    return message.reply('You can not advertise here!');
}

Upvotes: 1

Related Questions