Build a battle royale: /rumble posts a Join button for one minute, then every 30 seconds a round eliminates one or two players with a random funny cause, the same message updates until one survivor remains and wins 100 coins
A Battle Royale game where members compete to be the last one standing!
How to play:
/rumble to start a new gameThe game board updates in place as rounds progress, showing survivors and eliminated players.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
🏆 VICTORY ROYALE! 🏆
@Jordan is the last one standing and wins 100 coins!
Eliminated (2): @Alex, @Sam
💥 ELIMINATION! 💥
@Alex got distracted by a butterfly! @Sam got stuck in a revolving door!
// Battle Royale: members join for 1 minute, then elimination rounds every 30s until one winner remains
interface RumbleState {
players: string[]; // user ids
eliminated: string[]; // user ids
roundNumber: number;
messageId: string;
channelId: string;
joinEndsAt: number;
}
const CAUSES = [
'tripped over a banana peel',
'got distracted by a butterfly',
'accidentally pressed the wrong button',
'ran out of coffee',
'sneezed too hard',
'was defeated by autocorrect',
'fell into a plot hole',
'challenged a duck to a duel and lost',
'got stuck in a revolving door',
'was eliminated by a rogue shopping cart',
'forgot to read the instructions',
'tried to divide by zero',
'walked into a wall they thought was a door',
'got caught in a meme loop',
'was outsmarted by a houseplant',
'stepped on a LEGO brick',
'lost a staring contest with a cat',
'was defeated by Monday',
'forgot how gravity works',
'got hit by the karma boomerang',
];
/** Whether a call was refused because the member has left the server. */
function hasLeft(err: unknown): boolean {
return String(err).includes('is not in this server');
}
/** Pay the last one standing 100 coins, raised by the server's Economy
* boosts like /work; what was paid, 0 when they have left the server. */
async function payWinner(winner: string): Promise<number> {
try {
return (await mee6.economy.add(winner, 100, { boost: 'income' })).amount;
} catch (err) {
if (!hasLeft(err)) throw err;
return 0;
}
}
function pickRandom<T>(arr: T[]): T {
return arr[Math.floor(Math.random() * arr.length)];
}
function renderRumble(
state: RumbleState,
joinPhase: boolean,
winnerPaid = 100
): { content: string; buttons?: object[] } {
if (joinPhase) {
return {
content: `🎮 **BATTLE ROYALE** 🎮\n\nClick JOIN to enter the arena!\n\n**Players:** ${state.players.length}`,
buttons: [{ label: 'Join the Rumble!', customId: 'join_rumble', style: 'success' }],
};
}
if (state.players.length === 0 && state.eliminated.length === 0) {
return { content: '💀 **BATTLE ROYALE** 💀\n\nNobody joined! The rumble is cancelled.' };
}
if (state.players.length === 1) {
const winner = state.players[0];
return {
content: `🏆 **VICTORY ROYALE!** 🏆\n\n<@${winner}> is the last one standing${
winnerPaid ? ` and wins **${winnerPaid} coins**` : ', but has left the server: no coins this time'
}!\n\n**Eliminated (${state.eliminated.length}):**\n${state.eliminated.map((id) => `<@${id}>`).join(', ')}`,
};
}
const alive = state.players.map((id) => `<@${id}>`).join(', ');
const dead = state.eliminated.length > 0 ? state.eliminated.map((id) => `<@${id}>`).join(', ') : 'None yet';
return {
content: `⚔️ **BATTLE ROYALE - Round ${state.roundNumber}** ⚔️\n\n**Survivors (${state.players.length}):**\n${alive}\n\n**Eliminated (${state.eliminated.length}):**\n${dead}\n\n⏳ Next round in 30 seconds...`,
};
}
mee6.command('rumble', { description: 'Start a Battle Royale!' }, async (ctx) => {
const state: RumbleState = {
players: [],
eliminated: [],
roundNumber: 0,
messageId: '',
channelId: ctx.channelId,
joinEndsAt: Date.now() + 60000,
};
const sent = await ctx.reply(renderRumble(state, true));
state.messageId = sent.messageId;
await mee6.store.set(`rumble_${sent.messageId}`, state, { ttl: 3600 });
// Schedule the join period to end
await mee6.schedule.once(`rumble_start_${sent.messageId}`, 60, {
messageId: sent.messageId,
channelId: ctx.channelId,
});
});
mee6.on('button', async (ctx) => {
if (ctx.customId !== 'join_rumble') return;
const state = await mee6.store.get<RumbleState>(`rumble_${ctx.message.id}`);
if (!state) {
await ctx.reply({ content: 'This rumble has ended!', ephemeral: true });
return;
}
// Check if join period is still active
if (Date.now() > state.joinEndsAt) {
await ctx.reply({ content: 'Too late! The rumble has already started.', ephemeral: true });
return;
}
if (state.players.includes(ctx.author.id)) {
await ctx.reply({ content: "You're already in!", ephemeral: true });
return;
}
state.players.push(ctx.author.id);
await mee6.store.set(`rumble_${ctx.message.id}`, state, { ttl: 3600 });
await ctx.editOriginal(renderRumble(state, true));
await ctx.reply({ content: '✅ You joined the rumble!', ephemeral: true });
});
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey.startsWith('rumble_start_')) {
const p = ctx.payload as { messageId: string; channelId: string };
const state = await mee6.store.get<RumbleState>(`rumble_${p.messageId}`);
if (!state) return;
// Start the elimination rounds
if (state.players.length === 0) {
await mee6.editMessage(p.channelId, p.messageId, renderRumble(state, false));
return;
}
if (state.players.length === 1) {
// Only one player joined - they win by default
await mee6.store.delete(`rumble_${p.messageId}`);
const paid = await payWinner(state.players[0]);
await mee6.editMessage(p.channelId, p.messageId, renderRumble(state, false, paid));
return;
}
// Start first elimination round — saved and scheduled before the board
// is touched, so a board that cannot be edited does not end the rumble
state.roundNumber = 1;
await mee6.store.set(`rumble_${p.messageId}`, state, { ttl: 3600 });
await mee6.schedule.once(`rumble_round_${p.messageId}`, 30, {
messageId: p.messageId,
channelId: p.channelId,
});
await mee6.editMessage(p.channelId, p.messageId, renderRumble(state, false));
} else if (ctx.scheduleKey.startsWith('rumble_round_')) {
const p = ctx.payload as { messageId: string; channelId: string };
const state = await mee6.store.get<RumbleState>(`rumble_${p.messageId}`);
if (!state) return;
// Eliminate 1 or 2 players
const toEliminate = state.players.length > 2 ? (Math.random() < 0.6 ? 1 : 2) : 1;
const victims: string[] = [];
for (let i = 0; i < toEliminate && state.players.length > 1; i++) {
const victimIndex = Math.floor(Math.random() * state.players.length);
const victim = state.players.splice(victimIndex, 1)[0];
victims.push(victim);
state.eliminated.push(victim);
}
state.roundNumber++;
// Build elimination announcement
let announcement = `💥 **ELIMINATION!** 💥\n\n`;
for (const victim of victims) {
announcement += `<@${victim}> ${pickRandom(CAUSES)}!\n`;
}
// Check for winner. The rumble is saved, or over, before anything is
// posted: a message that fails must not stop it halfway.
let paid = 100;
if (state.players.length === 1) {
await mee6.store.delete(`rumble_${p.messageId}`);
paid = await payWinner(state.players[0]);
} else {
// Continue to next round
await mee6.store.set(`rumble_${p.messageId}`, state, { ttl: 3600 });
await mee6.schedule.once(`rumble_round_${p.messageId}`, 30, {
messageId: p.messageId,
channelId: p.channelId,
});
}
// Post the elimination, then update the board
await ctx.send(p.channelId, announcement);
await mee6.editMessage(p.channelId, p.messageId, renderRumble(state, false, paid));
}
});