Every morning at 9am UTC, congratulate in a channel I choose the members whose server join date is today, with how many years they have been here, and give a role I choose at one year
Every morning at 9am UTC, this creation checks for members whose server join date anniversary is today and posts a celebration message in your chosen channel. Members who reach their 1-year anniversary automatically receive a special role.
Setup: Configure the announcement channel and the one-year role in settings. The creation uses the XP leaderboard to find members, so it works best on servers with the Levels plugin enabled.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
You joined October 5, 2023 — 2 years ago. Next anniversary: 2 months ago.
You joined January 5, 2023 — 3 years ago. Next anniversary: in 2 months.
// Server anniversaries: every morning, the members who joined on this day a
// year or more ago are congratulated, and the one-year mark earns a role.
mee6.settings({
channel: {
type: 'channel',
label: 'Anniversary channel',
required: true,
sample: 'announcements',
},
role: {
type: 'role',
label: 'One-year anniversary role',
sample: 'Veteran',
},
});
interface Known {
id: string;
joinedAt: string | null;
}
/** "0913" for September 13 — the key of the day's list. */
function dayKey(date: Date): string {
return `anniv_${String(date.getUTCMonth() + 1).padStart(2, '0')}${String(date.getUTCDate()).padStart(2, '0')}`;
}
// There is no way to list every member, so members are remembered under the
// day they joined — when they join, or the first time they talk. One list
// per calendar day: 366 keys at most, read once a day.
async function register(member: Known): Promise<void> {
if (!member.joinedAt) return;
const m = mee6.store.member(member.id);
if (await m.get<boolean>('anniv_registered')) return;
const key = dayKey(new Date(member.joinedAt));
const list = (await mee6.store.get<string[]>(key)) || [];
if (!list.includes(member.id)) {
list.push(member.id);
await mee6.store.set(key, list.slice(-500));
}
await m.set('anniv_registered', true);
}
mee6.on('member_join', async (ctx) => {
await register(ctx.author);
});
mee6.on('message', async (ctx) => {
await register(ctx.author);
});
mee6.command('anniversary', { description: 'When you joined, and when your next anniversary is' }, async (ctx) => {
const joinedAt = ctx.author.joinedAt;
if (!joinedAt) {
await ctx.reply('Discord did not say when you joined, so I cannot count.');
return;
}
await register(ctx.author);
const joined = new Date(joinedAt);
const now = new Date();
let years = now.getUTCFullYear() - joined.getUTCFullYear();
const next = new Date(Date.UTC(now.getUTCFullYear(), joined.getUTCMonth(), joined.getUTCDate(), 9));
if (next.getTime() < now.getTime()) {
next.setUTCFullYear(next.getUTCFullYear() + 1);
} else {
years -= 1;
}
await ctx.reply({
embed: {
title: '🎂 Your anniversary',
description:
`You joined <t:${Math.floor(joined.getTime() / 1000)}:D>` +
(years > 0 ? ` — **${years} year${years === 1 ? '' : 's'}** ago.` : '.') +
`\nNext anniversary: <t:${Math.floor(next.getTime() / 1000)}:R>.`,
color: '#5865f2',
thumbnail_url: ctx.author.avatarUrl,
},
});
});
// Every morning at 9am UTC
mee6.schedule.cron('daily_anniversaries', '0 9 * * *');
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey !== 'daily_anniversaries') return;
const channelId = ctx.settings.channel;
if (!channelId) {
mee6.log('Anniversary channel not configured');
return;
}
const today = new Date();
const ids = (await mee6.store.get<string[]>(dayKey(today))) || [];
if (ids.length === 0) return;
const guild = await mee6.guild();
const lines: string[] = [];
let rolesGiven = 0;
// A run may read thirty members and change ten roles: enough for a day.
for (const id of ids.slice(0, 30)) {
const member = await mee6.getMember(id);
if (!member || !member.joinedAt) continue;
const years = today.getUTCFullYear() - new Date(member.joinedAt).getUTCFullYear();
if (years < 1) continue;
lines.push(`🎉 ${member.mention} — **${years} year${years === 1 ? '' : 's'}**`);
if (years === 1 && ctx.settings.role && rolesGiven < 10) {
await mee6.addRole(member.id, ctx.settings.role);
rolesGiven++;
}
}
if (lines.length === 0) return;
await ctx.send(channelId, {
embed: {
title: `🎂 Anniversaries on ${guild.name}`,
description: `${lines.join('\n')}\n\nThank you for being here!`,
color: '#5865f2',
},
});
});