{ const regex = /(https?:\/\/)?(www\.)?(discord\.(g" /> { const regex = /(https?:\/\/)?(www\.)?(discord\.(g" /> { const regex = /(https?:\/\/)?(www\.)?(discord\.(g"/>

Inviteblock Discord.js

1.8k Views Asked by At

I want to create a bot that blocks invitations.
this is my code

bot.on("message", async message => {
    const regex = /(https?:\/\/)?(www\.)?(discord\.(gg|io|me|li|club)|discordapp\.com\/invite|discord\.com\/invite)\/.+[a-z]/gi;
    if (regex.exec(message.content)) 
        await message.channel.send(
          `${message.author} **você não pode postar link de outros servidores aqui!**\n Vais levar ban se voltares a`
        );
    
  });

The problem is that this also blocks the adm invites.

1

There are 1 best solutions below

1
Razvan On BEST ANSWER

You need to check if the user has the admin role.

bot.on("message", async message => {
    const regex = /(https?:\/\/)?(www\.)?(discord\.(gg|io|me|li|club)|discordapp\.com\/invite|discord\.com\/invite)\/.+[a-z]/gi;

    if (!message.member.roles.cache.has('xxxxx')) {  //replace the Xs with the admin role ID
        if (regex.exec(message.content)) {
           await message.channel.send(
              `${message.author} **você não pode postar link de outros servidores aqui!**\n Vais levar ban se voltares a`
           )
        }
    } 
});