Add an /afk command with an optional reason: when someone mentions an AFK member, reply that they are away, and clear it as soon as they talk again
AFK Status lets members mark themselves away and automatically notifies anyone who mentions them.
/afk [reason] โ Mark yourself as AFK with an optional reason (defaults to "AFK")The bot only replies once per message to avoid spam, even if multiple AFK members are mentioned.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
๐ค You are now AFK: lunch break
๐ค Alex is AFK: lunch break (5m ago)
๐ค You are now AFK: AFK
๐ค You is AFK: AFK (3m ago)
๐ Welcome back, Alex!
// AFK Status: Set yourself as away, get auto-replies on mentions, return automatically
mee6.command(
'afk',
{
description: 'Mark yourself as AFK',
options: [{ name: 'reason', type: 'string', description: 'Why are you away?' }],
},
async (ctx) => {
const reason = ctx.option<string>('reason', 'AFK');
const m = mee6.store.member(ctx.author.id);
await m.set('afk_reason', reason);
await m.set('afk_since', Date.now());
await ctx.reply(`๐ค You are now AFK: ${reason}`);
}
);
// When someone mentions an AFK member, notify them
mee6.on('message', async (ctx) => {
const m = mee6.store.member(ctx.author.id);
// If the author is AFK and speaks, clear their status
const authorAfk = await m.get<string>('afk_reason');
if (authorAfk) {
await m.delete('afk_reason');
await m.delete('afk_since');
await ctx.reply(`๐ Welcome back, ${ctx.author.displayName}!`);
return; // Don't check mentions if we just cleared their AFK
}
// Check if message mentions any members
const mentionPattern = /<@!?(\d+)>/g;
const mentions = [...ctx.message.content.matchAll(mentionPattern)];
if (mentions.length === 0) return;
// Check each mentioned member for AFK status
const replied = new Set<string>();
for (const match of mentions) {
const userId = match[1];
if (userId === ctx.author.id || replied.has(userId)) continue;
const targetMember = mee6.store.member(userId);
const afkReason = await targetMember.get<string>('afk_reason');
const afkSince = await targetMember.get<number>('afk_since');
if (afkReason) {
const member = await mee6.getMember(userId);
if (!member) continue;
const elapsed = Math.floor((Date.now() - (afkSince || Date.now())) / 1000 / 60);
const timeStr = elapsed > 0 ? ` (${elapsed}m ago)` : '';
await ctx.reply(`๐ค **${member.displayName}** is AFK: ${afkReason}${timeStr}`);
replied.add(userId);
break; // Only reply once per message to avoid spam
}
}
});