Delete messages that have or contain discord.gg/ or https//discord.gg/ so that no one can send invite links in your server. The bot will post a warning message after deleting invite links.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const DISCORD_LINKS = ['discord.gg/', 'https://discord.gg/']; // The Discord start link start off
let event = context.params.event;
const regEx = new RegExp(DISCORD_LINKS.join('|'), 'gi');
let messageContent = event.content;
if (messageContent.match(regEx)) {
await lib.discord.channels['@0.0.3'].messages.destroy({
// This will delete the message.
message_id: event.id,
channel_id: event.channel_id,
});
await lib.discord.channels['@0.0.6'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `<@!${context.params.event.author.id}> Please do not post discord invites in this server.`, // Change this to anything you want
});
}