Add a /timedmute command that gives the @Muted role for a number of minutes and removes it automatically when the time is up
Temporarily mute members with automatic unmute.
Usage: /timedmute @member minutes [reason]
The command adds a configurable muted role for the specified duration (1 minute to 28 days) and automatically removes it when the time expires.
Setup: Configure the muted role in Settings. The bot needs Manage Roles permission and must have a higher role than the muted role.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
✅ @Alex has been muted for 5 minutes. Reason: Spamming chat
✅ @Sam has been muted for 120 minutes. Reason: Harassment
// Temporary mute command: mutes a member for a specified duration
mee6.settings({
muted_role: {
type: 'role',
label: 'Muted role',
required: true,
sample: 'Muted',
},
});
mee6.command(
'timedmute',
{
description: 'Temporarily mute a member',
options: [
{ name: 'user', type: 'user', description: 'Member to mute', required: true },
{ name: 'minutes', type: 'integer', description: 'Duration in minutes', required: true },
{ name: 'reason', type: 'string', description: 'Reason for the mute' },
],
},
async (ctx) => {
const userId = ctx.option<string>('user');
const minutes = ctx.option<number>('minutes');
const reason = ctx.option<string>('reason', 'No reason given');
const mutedRoleId = ctx.settings.muted_role;
if (!mutedRoleId) {
await ctx.reply('⚠️ No muted role is configured. Ask an admin to set it in the dashboard.');
return;
}
// Validate duration (30 seconds to 40320 minutes / 28 days)
if (minutes < 1) {
await ctx.reply('⚠️ Duration must be at least 1 minute.');
return;
}
if (minutes > 40320) {
await ctx.reply('⚠️ Duration cannot exceed 28 days (40320 minutes).');
return;
}
const seconds = minutes * 60;
// Check if already muted by this system
const existingMute = await mee6.store.member(userId).get<number>('temp_mute_until');
if (existingMute && existingMute > Date.now()) {
await ctx.reply(`⚠️ <@${userId}> is already temporarily muted.`);
return;
}
try {
// Add the muted role
await mee6.addRole(userId, mutedRoleId);
// Store the mute end time
const endsAt = Date.now() + seconds * 1000;
await mee6.store.member(userId).set('temp_mute_until', endsAt, { ttl: seconds });
// Schedule automatic unmute
await mee6.schedule.once(`unmute_${userId}`, seconds, {
userId,
roleId: mutedRoleId,
});
await ctx.reply(
`✅ <@${userId}> has been muted for ${minutes} minute${minutes === 1 ? '' : 's'}.\n` + `**Reason:** ${reason}`
);
mee6.log(`Muted ${userId} for ${minutes} minutes: ${reason}`);
} catch (error) {
await ctx.reply(
'❌ Failed to mute the member. Make sure I have the Manage Roles permission and a higher role than the Muted role.'
);
mee6.log(`Failed to mute ${userId}: ${error}`);
}
}
);
// Handle scheduled unmutes
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey.startsWith('unmute_')) {
const payload = ctx.payload as { userId: string; roleId: string } | null;
if (!payload) return;
try {
await mee6.removeRole(payload.userId, payload.roleId);
mee6.log(`Automatically unmuted ${payload.userId}`);
} catch (error) {
mee6.log(`Failed to automatically unmute ${payload.userId}: ${error}`);
}
// Clean up the stored mute time
await mee6.store.member(payload.userId).delete('temp_mute_until');
}
});