Add /lfg which posts a looking-for-group post as one Components V2 card updated in place: a heading with the game, who is looking and how many players, a separator, the party list with how many places are left and when the post expires, and Join and Leave buttons inside the card. Ping everyone in it when it is full, and expire after two hours
Creates LFG posts where members can join with a button. When the group fills up, everyone gets pinged. Posts automatically expire after 2 hours if not filled.
Usage: /lfg game:Valorant slots:3
Each post is one card that updates in place: the game, who is looking, the party list with places left, when it expires, and Join / Leave buttons. The creator is automatically added to the group. When full, the group is notified and the buttons are removed.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
๐ Party is FULL! Have fun!
Party (3/3) โ full
Group is ready!
@Alex @Jordan @Riley Your group for Valorant is ready! ๐
// LFG (Looking For Group) system with auto-fill notifications and expiration
interface LFGState {
game: string;
slots: number;
members: string[]; // user ids
ownerId: string;
channelId: string;
messageId: string;
/** when the post expires, Unix seconds โ absent on posts made before the card */
expiresAt?: number;
}
const LFG_TTL = 7200; // a post stays open for two hours
const BLURPLE = 0x5865f2;
const GREEN = 0x57f287;
const GREY = 0x747f8d;
// ---------------------------------------------------------------------------
// The card: one Components V2 message, rewritten as members join and leave
// ---------------------------------------------------------------------------
/** The party, one member per line, the leader first */
function partyText(state: LFGState): string {
const left = state.slots - state.members.length;
const count = left > 0 ? `${left} place${left === 1 ? '' : 's'} left` : 'full';
const lines = state.members.map((id, i) => `${i + 1}. <@${id}>${id === state.ownerId ? ' ๐' : ''}`);
return `**Party (${state.members.length}/${state.slots})** โ ${count}\n${lines.join('\n')}`;
}
function card(state: LFGState, status: 'open' | 'full' | 'expired'): MessagePayload {
const heading = `## ๐ฎ Looking for Group: ${state.game}`;
if (status === 'expired') {
return {
layout: [
{
type: 'container',
color: GREY,
blocks: [
{
type: 'text',
text: `${heading}\n~~<@${state.ownerId}> was looking for **${state.slots}** players~~\n\n**Expired** โ this group didn't fill in time.`,
},
],
},
],
};
}
const full = status === 'full';
const expires = state.expiresAt ? `Expires <t:${state.expiresAt}:R>` : 'Expires 2 hours after it was posted';
const blocks: LayoutBlock[] = [
{
type: 'text',
text: full
? `${heading}\n๐ **Party is FULL!** Have fun!`
: `${heading}\n<@${state.ownerId}> is looking for **${state.slots}** players!`,
},
{ type: 'separator' },
{ type: 'text', text: partyText(state) },
{ type: 'text', text: full ? '-# Group is ready!' : `-# ${expires}` },
];
if (!full) {
blocks.push({
type: 'buttons',
buttons: [
{ label: 'Join', customId: 'lfg_join', style: 'success' },
{ label: 'Leave', customId: 'lfg_leave', style: 'secondary' },
],
});
}
return { layout: [{ type: 'container', color: full ? GREEN : BLURPLE, blocks }] };
}
mee6.command(
'lfg',
{
description: 'Create a looking-for-group post',
options: [
{ name: 'game', type: 'string', description: 'What game/activity', required: true },
{ name: 'slots', type: 'integer', description: 'How many people needed (including you)', required: true },
],
},
async (ctx) => {
const game = ctx.option<string>('game');
const slots = ctx.option<number>('slots');
if (slots < 2 || slots > 10) {
await ctx.reply('Slots must be between 2 and 10.');
return;
}
const state: LFGState = {
game,
slots,
members: [ctx.author.id],
ownerId: ctx.author.id,
channelId: ctx.channelId,
messageId: '',
expiresAt: Math.floor(Date.now() / 1000) + LFG_TTL,
};
const sent = await ctx.reply(card(state, 'open'));
state.messageId = sent.messageId;
await save(state, sent.messageId);
// Schedule expiration after 2 hours
await mee6.schedule.once(`lfg_expire_${sent.messageId}`, LFG_TTL, {
channelId: ctx.channelId,
messageId: sent.messageId,
});
}
);
/** Keep the post's state past its expiry, for the scheduled job to close it */
async function save(state: LFGState, messageId: string): Promise<void> {
await mee6.store.set(`lfg_${messageId}`, state, { ttl: LFG_TTL });
}
mee6.on('button', async (ctx) => {
if (ctx.customId !== 'lfg_join' && ctx.customId !== 'lfg_leave') return;
const state = await mee6.store.get<LFGState>(`lfg_${ctx.message.id}`);
if (!state) {
await ctx.reply({ content: 'This LFG post has expired.', ephemeral: true });
return;
}
if (ctx.customId === 'lfg_leave') {
if (ctx.author.id === state.ownerId) {
await ctx.reply({ content: 'You started this group, so you stay in it.', ephemeral: true });
return;
}
if (!state.members.includes(ctx.author.id)) {
await ctx.reply({ content: 'You are not in this group.', ephemeral: true });
return;
}
state.members = state.members.filter((id) => id !== ctx.author.id);
await ctx.editOriginal(card(state, 'open'));
await save(state, ctx.message.id);
await ctx.reply({ content: `You left the group for **${state.game}**.`, ephemeral: true });
return;
}
// Already in the group?
if (state.members.includes(ctx.author.id)) {
await ctx.reply({ content: 'You are already in this group!', ephemeral: true });
return;
}
// Group already full?
if (state.members.length >= state.slots) {
await ctx.reply({ content: 'This group is already full.', ephemeral: true });
return;
}
// Add the member
state.members.push(ctx.author.id);
const isFull = state.members.length >= state.slots;
// Update the card (an old embed post becomes a card too)
await ctx.editOriginal(card(state, isFull ? 'full' : 'open'));
await save(state, ctx.message.id);
if (isFull) {
// Ping everyone in the group
const mentions = state.members.map((id) => `<@${id}>`).join(' ');
await ctx.send(state.channelId, `${mentions} Your group for **${state.game}** is ready! ๐`);
// Cancel the expiration schedule since the group is full
await mee6.schedule.cancel(`lfg_expire_${ctx.message.id}`);
} else {
await ctx.reply({ content: `You joined the group for **${state.game}**!`, ephemeral: true });
}
});
mee6.on('scheduled', async (ctx) => {
if (!ctx.scheduleKey.startsWith('lfg_expire_')) return;
const p = ctx.payload as { channelId: string; messageId: string };
const state = await mee6.store.get<LFGState>(`lfg_${p.messageId}`);
if (!state) return; // Already cleaned up
// Mark as expired
await mee6.editMessage(p.channelId, p.messageId, card(state, 'expired'));
await mee6.store.delete(`lfg_${p.messageId}`);
});