Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
Ban discord invite

I would like to make a whitelist on the bot and that the people who are in it can send links.

client.on(`message`, async message => {
   let msg = message
   const bannedWords = [`discord.gg`, `.gg/`, `.gg /`, `. gg /`, `. gg/`, `discord .gg /`, `discord.gg /`, `discord .gg/`, `discord .gg`, `discord . gg`, `discord. gg`, `discord gg`, `discordgg`, `discord gg /`]
   try {
       if (bannedWords.some(word => message.content.toLowerCase().includes(word))) {
           if (message.author.id === message.guild.ownerID) return;
           await message.delete();
           await message.channel.send(`<@`+message.author+`> **You cannot send invites to other Discord servers ๐Ÿ’ฃ**`).then((m) => m.delete({ timeout: 3000 }))
       }
   } catch (e) {
       console.log(e);
   }
});
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

You can do the same like you did with the banned words and put everyone's User ID in an array. (Not recommended for medium / large guilds) or work with roles. So let's say, you make a role and give it to the persons who are allowed to put in links. Then check if they have the role, if not you could send a warning and remove the message.

Example with whitelist arrays using user ids:

client.on(`message`, async message => {
    let msg = message;

    // Put all the user ID's in this array
    const allowedUsers = ["user_id_1","user_id_2","user_id_3"];
    const bannedWords = [`discord.gg`, `.gg/`, `.gg /`, `. gg /`, `. gg/`, `discord .gg /`, `discord.gg /`, `discord .gg/`, `discord .gg`, `discord . gg`, `discord. gg`, `discord gg`, `discordgg`, `discord gg /`]
    try {
        if (bannedWords.some(word => message.content.toLowerCase().includes(word))) {
            if (message.author.id === message.guild.ownerID) return;
            if(allowedUsers.indexOf(message.author.id) !== -1) return;
            
            await message.delete();
            await message.channel.send(`<@`+message.author+`> **You cannot send invites to other Discord servers ๐Ÿ’ฃ**`).then((m) => m.delete({ timeout: 3000 }))
        }
    } catch (e) {
        console.log(e);
    }
});

Or you can do it with roles. Just create a new role for example Links Allowed, copy the ID of this role and put it in de code below at message.member.roles.cache.has("role_id_of_allowed")

client.on(`message`, async message => {
    let msg = message;

    // Put all the user ID's in this array
    const bannedWords = [`discord.gg`, `.gg/`, `.gg /`, `. gg /`, `. gg/`, `discord .gg /`, `discord.gg /`, `discord .gg/`, `discord .gg`, `discord . gg`, `discord. gg`, `discord gg`, `discordgg`, `discord gg /`]
    try {
        if (bannedWords.some(word => message.content.toLowerCase().includes(word))) {
            if (message.author.id === message.guild.ownerID) return;
            if(message.member.roles.cache.has("role_id_of_allowed") === true) return;
            
            await message.delete();
            await message.channel.send(`<@`+message.author+`> **You cannot send invites to other Discord servers ๐Ÿ’ฃ**`).then((m) => m.delete({ timeout: 3000 }))
        }
    } catch (e) {
        console.log(e);
    }
});

If it's not working properly, you can also fetch the user's profile first by using await message.guild.members.fetch(); to refresh the cache.

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!