Delete any message containing a link unless the author has the @Staff role, and warn them in the channel with a message that deletes itself
Automatically removes messages containing links from members without the staff role and posts a self-deleting warning.
http:// or https:// from a non-staff member is deleted immediatelyMade by MEE6. Remix it to get a copy of your own and change anything you like.
// Link moderation: delete messages with links from non-staff members
mee6.settings({
staff_role: {
type: 'role',
label: 'Staff role (members with this role can post links)',
required: true,
sample: 'Staff',
},
});
// Only messages containing a link (http:// or https://) wake the module
mee6.on('message', { contains: ['http://', 'https://'] }, async (ctx) => {
const staffRoleId = ctx.settings.staff_role;
if (!staffRoleId) {
// Not configured yet — do nothing
return;
}
// Check if the author has the staff role
const isStaff = ctx.author.roles.includes(staffRoleId);
if (isStaff) {
return; // Staff can post links
}
// Delete the message with the link
await ctx.delete();
// Warn the member with a message that deletes itself after 30 seconds
const warning = await ctx.reply(`${ctx.author.mention} Links are not allowed. Only staff members can post links.`);
// Schedule the warning to be deleted after 30 seconds (the minimum allowed)
if (warning.messageId) {
await mee6.schedule.once(`delete_warning_${warning.messageId}`, 30, {
channelId: warning.channelId,
messageId: warning.messageId,
});
}
});
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey.startsWith('delete_warning_')) {
const p = ctx.payload as { channelId: string; messageId: string } | null;
if (p) {
await mee6.deleteMessage(p.channelId, p.messageId);
}
}
});