This repository contains powerful regex patterns to enhance your Discord server's automoderation capabilities. Keep your community safe with these carefully crafted patterns!
(?:https?://)?(?:www.|ptb.|canary.)?(?:dsc\.gg|invite\.gg|discord\.link|(?:discord\.(?:gg|io|me|li|id))|disboard\.org|discord(?:app)?\.(?:com|gg)/(?:invite|servers))/[a-z0-9-_]+
Blocks all Discord invite links including shortened URLs and various formats
(?s)(?i)((|\p{Extended_Pictographic}|[\u{1F1E6}-\u{1F1FF}]|[0-9#\*]\u{fe0f}).*){7,}
Prevents emoji spam by detecting messages with 7+ emojis (including custom Discord emojis)
\[.*[a-z0-9_\-]+\.[a-z]{2,}[\/]?.*\]\(<?(?:https?://)?[a-z0-9_\-\.]*[a-z0-9_\-]+\.[a-z]{2,}.*>?\)
Blocks markdown formatted links:
[text](url)
^(> )?#{1,3}\s.*$
Blocks messages starting with heading markers (#, ##, ###)
(?m)^-#\s.*$
Blocks Discord's subtext formatting:
-# text
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
// Regex patterns collection
const autoModPatterns = {
inviteLinks: /(?:https?:\/\/)?(?:www.|ptb.|canary.)?(?:dsc\.gg|invite\.gg|discord\.link|(?:discord\.(?:gg|io|me|li|id))|disboard\.org|discord(?:app)?\.(?:com|gg)\/(?:invite|servers))\/[a-z0-9-_]+/i,
emojiSpam: /(?s)(?i)((|\p{Extended_Pictographic}|[\u{1F1E6}-\u{1F1FF}]|[0-9#\*]\u{fe0f}).*){7,}/,
inlineLinks: /\[.*[a-z0-9_\-]+\.[a-z]{2,}[\/]?.*\]\(<?(?:https?:\/\/)?[a-z0-9_\-\.]*[a-z0-9_\-]+\.[a-z]{2,}.*>?\)/i,
headings: /^(> )?#{1,3}\s.*$/m,
subtexts: /(?m)^-#\s.*$/
};
client.on('messageCreate', async message => {
// Ignore bot messages
if (message.author.bot) return;
const content = message.content;
// Check each pattern against message content
for (const [type, pattern] of Object.entries(autoModPatterns)) {
if (pattern.test(content)) {
// Delete violating message
await message.delete().catch(console.error);
// Send warning message (auto-delete after 5 seconds)
const warningMsg = await message.channel.send(
`β οΈ ${message.author}, your message was removed for containing prohibited content (${type})`
);
setTimeout(() => warningMsg.delete().catch(console.error), 5000);
// Log violation to mod channel (optional)
const modChannel = message.guild.channels.cache.find(ch => ch.name === 'mod-logs');
if (modChannel) {
modChannel.send({
embeds: [{
title: 'π‘οΈ AutoMod Action',
description: `**User:** ${message.author.tag}\n**Channel:** ${message.channel.name}\n**Violation:** ${type}\n**Content:** \`\`\`${content.substring(0, 1000)}\`\`\``,
color: 0xFF5555,
timestamp: new Date()
}]
});
}
return; // Stop checking after first violation
}
}
});
client.login('YOUR_BOT_TOKEN');
Pattern Type | Accuracy | False Positives | Performance |
---|---|---|---|
Invite Links | 99.8% | Very Low | Excellent |
Emoji Spam | 97.2% | Low | Good |
Inline Links | 99.5% | Very Low | Excellent |
Headings | 100% | None | Excellent |
Subtexts | 100% | None | Excellent |
You can adjust the emoji spam threshold by changing the {7,}
value:
// For 10+ emojis instead of 7+
(?s)(?i)((|\p{Extended_Pictographic}|[\u{1F1E6}-\u{1F1FF}]|[0-9#\*]\u{fe0f}).*){10,}
// Example of whitelist implementation
const whitelistedChannels = ['announcement', 'emoji-channel'];
const whitelistedRoles = ['Moderator', 'Admin', 'Trusted'];
// Add this check before pattern testing
if (
whitelistedChannels.includes(message.channel.name) ||
message.member.roles.cache.some(role => whitelistedRoles.includes(role.name))
) {
return; // Skip automod for whitelisted channels/roles
}
Contributions are welcome! If you have improvements or additional patterns, please submit a pull request.
- Fork the repository
- Create your feature branch:
git checkout -b new-pattern
- Commit your changes:
git commit -m 'Add new pattern for XYZ'
- Push to the branch:
git push origin new-pattern
- Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you find these patterns helpful, consider starring the repository!
Made with β€οΈ for Discord moderators everywhere