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);
}
});
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.