Every Monday morning, post the most active member of the past seven days with their avatar and how far ahead of the runner-up they were, give them a Member of the Week role, and take it back from whoever held it before
Member of the Week crowns your most active contributor every Monday morning.
/motw-setup once to start the weekly scheduleThe role transfers automatically each week, and message counts reset for a fresh competition.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
✅ Member of the Week is now scheduled for every Monday at 9:00 AM UTC!
Congratulations to @Jordan for being the most active member this week with 3 messages! They were 1 message ahead of the runner-up!
// Member of the Week — tracks weekly activity and crowns the top contributor
mee6.settings({
channel: {
type: 'channel',
label: 'Announcement channel',
required: true,
sample: 'general',
},
role: {
type: 'role',
label: 'Member of the Week role',
required: true,
sample: 'Member of the Week',
},
cooldown: {
type: 'integer',
label: 'Seconds between counted messages',
description:
"A member's messages count once per this many seconds, like Levels XP, so spamming doesn't win. 0 counts every message.",
default: 60,
sample: 60,
},
counted_roles: {
type: 'list',
label: 'Only count members with these roles',
description: 'Leave empty to count everyone. Pick your staff roles here for an Admin of the Week.',
fields: { role: { type: 'role', label: 'Role', required: true } },
default: [],
sample: [],
},
ignored_roles: {
type: 'list',
label: 'Ignored roles',
description: "Members with one of these roles are never counted, so admins don't win every week.",
fields: { role: { type: 'role', label: 'Role', required: true } },
default: [],
sample: [{ role: 'Admin' }],
},
counted_channels: {
type: 'list',
label: 'Only count these channels',
description: 'Leave empty to count messages in every channel.',
fields: { channel: { type: 'channel', label: 'Channel', required: true } },
default: [],
sample: [],
},
ignored_channels: {
type: 'list',
label: 'Ignored channels',
description: 'Messages in these channels never count: a spam or bot-commands channel, for instance.',
fields: { channel: { type: 'channel', label: 'Channel', required: true } },
default: [],
sample: [],
},
});
/** The ids picked in a list setting's rows. */
function picked(rows: unknown, field: string): string[] {
if (!Array.isArray(rows)) return [];
return rows.map((row) => row?.[field]).filter((id): id is string => typeof id === 'string' && id !== '');
}
/** Whether this message counts, by who wrote it and where. */
function counts(ctx: Context): boolean {
const roles = ctx.author.roles;
const countedRoles = picked(ctx.settings.counted_roles, 'role');
if (countedRoles.length && !countedRoles.some((r) => roles.includes(r))) return false;
if (picked(ctx.settings.ignored_roles, 'role').some((r) => roles.includes(r))) return false;
const countedChannels = picked(ctx.settings.counted_channels, 'channel');
if (countedChannels.length && !countedChannels.includes(ctx.channelId)) return false;
return !picked(ctx.settings.ignored_channels, 'channel').includes(ctx.channelId);
}
// The week's counts live under a key carrying the week's number, so the
// Monday reset is one increment — never a walk over every member. Week 0
// keeps the first version's key: the counts running when it was updated
// still count.
async function weekKey(): Promise<string> {
const week = await mee6.store.get<number>('week', 0);
return week ? `week_messages_${week}` : 'week_messages';
}
/** Whether a call was refused because the member has left the server. */
function hasLeft(err: unknown): boolean {
return String(err).includes('is not in this server');
}
// Track message activity
mee6.on('message', async (ctx) => {
if (!counts(ctx)) return;
const m = mee6.store.member(ctx.author.id);
// One counted message per cooldown, the way Levels gives XP once a minute
const cooldown = Math.max(0, Number(ctx.settings.cooldown ?? 60));
if (cooldown > 0) {
const now = Math.floor(Date.now() / 1000);
if (now - (await m.get<number>('last_counted', 0)) < cooldown) return;
await m.set('last_counted', now);
}
const key = await weekKey();
// A member's first message of the week clears their past weeks' counts: a
// key per week would fill their storage (64 keys) in a year or so.
if ((await m.incr(key)) === 1) {
for (const old of Object.keys(await m.all())) {
if (old.startsWith('week_messages') && old !== key) await m.delete(old);
}
}
});
// Every Monday at 9:00 AM UTC
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey !== 'weekly_announcement') return;
const channelId = ctx.settings.channel;
const roleId = ctx.settings.role;
if (!channelId || !roleId) {
mee6.log('Missing channel or role setting');
return;
}
// The most active members — ten, as the first ones may have left the
// server since — then a new week, fresh counts for everyone.
const top = await mee6.store.memberTop(await weekKey(), 10);
await mee6.store.incr('week');
let rank = 0;
let winner = top.length ? await mee6.getMember(top[0].userId) : null;
while (!winner && ++rank < top.length) winner = await mee6.getMember(top[rank].userId);
if (!winner) {
await ctx.send(channelId, '📊 No activity this week!');
return;
}
// Calculate lead over runner-up
const winnerCount = top[rank].value;
const runnerUp = top[rank + 1];
const lead = winnerCount - (runnerUp ? runnerUp.value : 0);
// Remove role from previous holder — unless they left the server, the
// role with them
const prevWinnerId = await mee6.store.get<string>('current_winner');
if (prevWinnerId && prevWinnerId !== winner.id) {
try {
await mee6.removeRole(prevWinnerId, roleId);
} catch (err) {
if (!hasLeft(err)) throw err;
}
}
// Give role to new winner
await mee6.addRole(winner.id, roleId);
await mee6.store.set('current_winner', winner.id);
// Announce
const leadText = runnerUp ? ` They were **${lead} message${lead === 1 ? '' : 's'}** ahead of the runner-up!` : '';
await ctx.send(channelId, {
embed: {
title: '👑 Member of the Week',
description: `Congratulations to ${winner.mention} for being the most active member this week with **${winnerCount} messages**!${leadText}`,
color: '#FFD700',
thumbnail_url: winner.avatarUrl,
footer: { text: 'Keep up the great work!' },
},
});
});
// Set up the weekly schedule on first command run
mee6.command('motw-setup', { description: 'Initialize Member of the Week schedule' }, async (ctx) => {
await mee6.schedule.cron('weekly_announcement', '0 9 * * 1'); // Mondays at 9 AM UTC
await ctx.reply('✅ Member of the Week is now scheduled for every Monday at 9:00 AM UTC!');
});