Delete messages matching a list of regular expressions in the code (phone numbers, invite links, crypto addresses), DM the author their text so they can repost it fixed, and let the @Staff role add a pattern with /filter add and see them with /filter list
Automatically removes messages matching configurable regex patterns (phone numbers, Discord invites, crypto addresses by default) and DMs the author their message so they can repost it fixed. Staff can add custom patterns with /filter add, view all patterns with /filter list, and remove them with /filter remove.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
Your message in #general was removed because it matched a filter: Phone numbers
You can repost it after fixing the issue.
Call me at 555-123-4567 if you need help!
Your message in #general was removed because it matched a filter: Email addresses
You can repost it after fixing the issue.
Contact me at [email protected]
// Message filter: removes messages matching patterns, DMs the author, staff can manage filters
mee6.settings({
staff_role: { type: 'role', label: 'Staff role (can manage filters)', sample: 'Staff' },
});
// Default patterns: phone numbers, Discord invites, crypto addresses
const DEFAULT_PATTERNS = [
{ pattern: '\\b\\d{3}[-.]?\\d{3}[-.]?\\d{4}\\b', description: 'Phone numbers' },
{ pattern: 'discord\\.gg/[a-zA-Z0-9]+', description: 'Discord invite links' },
{ pattern: '\\b(bc1|[13])[a-zA-Z0-9]{25,39}\\b', description: 'Bitcoin addresses' },
{ pattern: '0x[a-fA-F0-9]{40}', description: 'Ethereum addresses' },
];
// Initialize default patterns if not already set
async function ensurePatterns() {
const existing = await mee6.store.get<typeof DEFAULT_PATTERNS>('filter_patterns');
if (!existing) {
await mee6.store.set('filter_patterns', DEFAULT_PATTERNS);
}
}
mee6.command(
'filter add',
{
description: 'Add a filter pattern (staff only)',
options: [
{ name: 'pattern', type: 'string', description: 'Regex pattern to match', required: true },
{ name: 'description', type: 'string', description: 'What this pattern catches', required: true },
],
},
async (ctx) => {
// Check staff permission
if (!ctx.settings.staff_role) {
await ctx.reply('No staff role is configured — ask an admin to set one in the dashboard.');
return;
}
if (!ctx.author.roles.includes(ctx.settings.staff_role)) {
await ctx.reply({ content: '❌ Only staff can manage filters.', ephemeral: true });
return;
}
const pattern = ctx.option<string>('pattern');
const description = ctx.option<string>('description');
// Test if it's a valid regex
try {
new RegExp(pattern, 'i');
} catch (e) {
await ctx.reply({ content: `❌ Invalid regex pattern: ${e}`, ephemeral: true });
return;
}
await ensurePatterns();
const patterns = await mee6.store.get<typeof DEFAULT_PATTERNS>('filter_patterns', []);
// Check if pattern already exists
if (patterns.some((p) => p.pattern === pattern)) {
await ctx.reply({ content: '⚠️ This pattern already exists.', ephemeral: true });
return;
}
patterns.push({ pattern, description });
await mee6.store.set('filter_patterns', patterns);
await ctx.reply({
embed: {
title: '✅ Filter added',
description: `**Pattern:** \`${pattern}\`\n**Catches:** ${description}`,
color: 0x43b581,
},
});
}
);
mee6.command(
'filter list',
{
description: 'List all filter patterns (staff only)',
},
async (ctx) => {
// Check staff permission
if (!ctx.settings.staff_role) {
await ctx.reply('No staff role is configured — ask an admin to set one in the dashboard.');
return;
}
if (!ctx.author.roles.includes(ctx.settings.staff_role)) {
await ctx.reply({ content: '❌ Only staff can view filters.', ephemeral: true });
return;
}
await ensurePatterns();
const patterns = await mee6.store.get<typeof DEFAULT_PATTERNS>('filter_patterns', []);
if (patterns.length === 0) {
await ctx.reply({ content: 'No filter patterns configured.', ephemeral: true });
return;
}
const fields = patterns.map((p, i) => ({
name: `${i + 1}. ${p.description}`,
value: `\`${p.pattern}\``,
}));
await ctx.reply({
embed: {
title: '🛡️ Active Filter Patterns',
fields,
color: 0x5865f2,
footer: { text: `${patterns.length} pattern(s) active` },
},
ephemeral: true,
});
}
);
mee6.command(
'filter remove',
{
description: 'Remove a filter pattern by number (staff only)',
options: [{ name: 'number', type: 'integer', description: 'Pattern number from /filter list', required: true }],
},
async (ctx) => {
// Check staff permission
if (!ctx.settings.staff_role) {
await ctx.reply('No staff role is configured — ask an admin to set one in the dashboard.');
return;
}
if (!ctx.author.roles.includes(ctx.settings.staff_role)) {
await ctx.reply({ content: '❌ Only staff can manage filters.', ephemeral: true });
return;
}
const num = ctx.option<number>('number');
await ensurePatterns();
const patterns = await mee6.store.get<typeof DEFAULT_PATTERNS>('filter_patterns', []);
if (num < 1 || num > patterns.length) {
await ctx.reply({ content: `❌ Invalid number. Use /filter list to see available patterns.`, ephemeral: true });
return;
}
const removed = patterns.splice(num - 1, 1)[0];
await mee6.store.set('filter_patterns', patterns);
await ctx.reply({
embed: {
title: '✅ Filter removed',
description: `**Pattern:** \`${removed.pattern}\`\n**Was catching:** ${removed.description}`,
color: 0xf04747,
},
});
}
);
mee6.on('message', async (ctx) => {
await ensurePatterns();
const patterns = await mee6.store.get<typeof DEFAULT_PATTERNS>('filter_patterns', []);
const content = ctx.message.content;
// Check each pattern
for (const { pattern, description } of patterns) {
const regex = new RegExp(pattern, 'i');
if (regex.test(content)) {
// Delete the message
await ctx.delete();
// DM the author with their message
const dmSent = await mee6.dm(ctx.author.id, {
embed: {
title: '⚠️ Message Removed',
description: `Your message in <#${ctx.channelId}> was removed because it matched a filter: **${description}**\n\nYou can repost it after fixing the issue.`,
fields: [{ name: 'Your message', value: content.length > 1024 ? content.slice(0, 1021) + '...' : content }],
color: 0xfaa61a,
},
});
// Log if DM failed
if (!dmSent) {
mee6.log(`Could not DM ${ctx.author.username} about filtered message (DMs closed)`);
}
return; // Stop after first match
}
}
});