When a member leaves, post in a channel I choose how long they had been on the server and how many messages this creation had counted for them
Posts to a configured channel when a member leaves, showing how long they were on the server and how many messages they sent. The creation quietly tracks message counts in the background.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
Alex (Alex) has left the server
1347 days
2
// Member Leave Tracker
// Tracks when members leave and posts their stats to a configured channel
mee6.settings({
log_channel: {
type: 'channel',
label: 'Leave log channel',
description: 'Where to post when members leave',
required: true,
sample: 'member-log',
},
});
// Track message count for each member
mee6.on('message', async (ctx) => {
const m = mee6.store.member(ctx.author.id);
await m.incr('message_count', 1);
});
// When a member leaves, post their stats
mee6.on('member_leave', async (ctx) => {
const channelId = ctx.settings.log_channel;
if (!channelId) {
mee6.log('Leave log channel not configured');
return;
}
const m = mee6.store.member(ctx.author.id);
const messageCount = (await m.get<number>('message_count')) ?? 0;
// Calculate how long they were on the server
let timeOnServer = 'Unknown';
if (ctx.author.joinedAt) {
const joined = new Date(ctx.author.joinedAt);
const now = new Date();
const daysOnServer = Math.floor((now.getTime() - joined.getTime()) / (1000 * 60 * 60 * 24));
if (daysOnServer === 0) {
timeOnServer = 'Less than a day';
} else if (daysOnServer === 1) {
timeOnServer = '1 day';
} else {
timeOnServer = `${daysOnServer} days`;
}
}
await ctx.send(channelId, {
embed: {
title: '👋 Member Left',
description: `**${ctx.author.displayName}** (${ctx.author.username}) has left the server`,
fields: [
{ name: 'Time on server', value: timeOnServer, inline: true },
{ name: 'Messages sent', value: `${messageCount}`, inline: true },
],
color: '#ed4245',
thumbnail_url: ctx.author.avatarUrl,
footer: { text: `User ID: ${ctx.author.id}` },
},
});
});