Every hour, post the current member count in #stats and delete the previous one
Posts the current member count every hour in a channel of your choice, automatically deleting the previous post.
/membercount to post the count immediately and start hourly updatesMade by MEE6. Remix it to get a copy of your own and change anything you like.
2 members
// Hourly member count tracker with configurable channel
mee6.settings({
channel: {
type: 'channel',
label: 'Stats channel',
required: true,
sample: 'stats',
},
});
// Manual trigger to start the schedule and post immediately
mee6.command('membercount', { description: 'Post member count now and start hourly updates' }, async (ctx) => {
const channelId = ctx.settings.channel;
if (!channelId) {
await ctx.reply('No channel is set yet โ an admin can choose one in the dashboard.');
return;
}
await postMemberCount(ctx, channelId);
await mee6.schedule.every('hourly_count', 3600, {});
await ctx.reply('โ
Posted member count and scheduled hourly updates.');
});
// Scheduled event fires every hour
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey === 'hourly_count') {
const channelId = await mee6.store.get<string>('channel_id');
if (channelId) {
await postMemberCount(ctx, channelId);
}
}
});
async function postMemberCount(
ctx: { send: (channelId: string, payload: unknown) => Promise<{ messageId: string }> },
channelId: string
) {
const guild = await mee6.guild();
// Delete the previous post if it exists
const previousMessageId = await mee6.store.get<string>('last_message_id');
if (previousMessageId) {
try {
await mee6.deleteMessage(channelId, previousMessageId);
} catch (e) {
// Message was already deleted or bot lacks permission
}
}
// Post the new count
const sent = await ctx.send(channelId, {
embed: {
title: '๐ฅ Member Count',
description: `**${guild.memberCount}** members`,
color: '#5865F2',
footer: { text: `${guild.name}` },
},
});
// Store for deletion next hour
await mee6.store.set('last_message_id', sent.messageId);
await mee6.store.set('channel_id', channelId);
}