Count the messages sent each week and post a recap in #general every Monday at 10am UTC with the total and the three most active members
Tracks all messages sent in the server and posts a weekly recap every Monday at 10:00 UTC.
How it works:
Setup:
/setup-recap to activate the Monday schedule/week-stats anytime to check current week progressThe creation works across any Discord server without hardcoded channels or roles.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
โ Weekly recap scheduled for every Monday at 10:00 UTC!
Total: 6 messages
Top Members: ๐ฅ Alex: 3 messages ๐ฅ Jordan: 2 messages ๐ฅ Sam: 1 messages
Here's the activity summary for the past week!
6 messages sent this week
3 messages
2 messages
1 messages
// Weekly message tracking system
// Counts messages per member and posts a recap every Monday at 10am UTC
mee6.settings({
recap_channel: {
type: 'channel',
label: 'Recap channel',
required: true,
sample: 'general',
},
});
// 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 ? `weekly_messages_${week}` : 'weekly_messages';
}
/** The most active members still in the server, with their names. */
async function topMembers(key: string, count: number): Promise<{ name: string; messages: number }[]> {
// Ten looked at, as the first ones may have left the server
const top = await mee6.store.memberTop(key, 10);
const shown: { name: string; messages: number }[] = [];
for (const entry of top) {
if (shown.length === count) break;
const member = await mee6.getMember(entry.userId);
if (member) shown.push({ name: member.displayName, messages: entry.value });
}
return shown;
}
const MEDALS = ['๐ฅ', '๐ฅ', '๐ฅ'];
// Track every message sent
mee6.on('message', async (ctx) => {
const m = mee6.store.member(ctx.author.id);
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)) === 1) {
for (const old of Object.keys(await m.all())) {
if (old.startsWith('weekly_messages') && old !== key) await m.delete(old);
}
}
// Also increment global counter
await mee6.store.incr('total_weekly_messages');
});
// Schedule the weekly recap to run every Monday at 10:00 UTC
// Cron format: minute hour day month weekday
// 0 10 * * 1 = 10:00 on Mondays
mee6.command('setup-recap', { description: 'Set up the weekly recap schedule' }, async (ctx) => {
await mee6.schedule.cron('weekly_recap', '0 10 * * 1');
await ctx.reply('โ
Weekly recap scheduled for every Monday at 10:00 UTC!');
});
// Handle the scheduled recap
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey !== 'weekly_recap') return;
const channelId = ctx.settings.recap_channel;
if (!channelId) {
mee6.log('No recap channel configured');
return;
}
// Get total message count and the top 3 most active members
const total = await mee6.store.get<number>('total_weekly_messages', 0);
const top = await topMembers(await weekKey(), 3);
// Reset counters for the new week before posting: a recap that cannot be
// posted must not keep the week from ending
await mee6.store.set('total_weekly_messages', 0);
await mee6.store.incr('week');
// Build the recap embed
const fields = top.map((entry, i) => ({
name: `${MEDALS[i]} ${entry.name}`,
value: `${entry.messages} messages`,
inline: true,
}));
await ctx.send(channelId, {
embed: {
title: '๐ Weekly Message Recap',
description: `Here's the activity summary for the past week!`,
color: '#5865F2',
fields: [
{
name: '๐ฌ Total Messages',
value: `${total} messages sent this week`,
inline: false,
},
...fields,
],
footer: { text: 'See you next Monday!' },
},
});
mee6.log(`Weekly recap posted: ${total} total messages`);
});
// Manual command to check current stats
mee6.command('week-stats', { description: 'Check current week statistics', ephemeral: true }, async (ctx) => {
const total = await mee6.store.get<number>('total_weekly_messages', 0);
const top = await topMembers(await weekKey(), 3);
const leaderboard = top.map((entry, i) => `${MEDALS[i]} ${entry.name}: ${entry.messages} messages\n`).join('');
await ctx.reply({
embed: {
title: '๐ Current Week Stats',
description: `**Total:** ${total} messages\n\n**Top Members:**\n${leaderboard || 'No activity yet'}`,
color: '#5865F2',
},
});
});