Build rock paper scissors between two members: /rps-duel challenges someone, both pick with buttons without seeing the other choice, and the bot reveals both and scores the win
Challenge another member to Rock Paper Scissors!
How to play:
/rps-duel @opponent to challenge someoneEach player can only see their own choice until the game ends. Games expire after 5 minutes if not completed.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
๐ชจ๐โ๏ธ Game Over!
@You: ๐ paper @Alex: ๐ชจ rock
You wins!
You chose ๐ paper!
๐ชจ๐โ๏ธ Game Over!
@Jordan: โ๏ธ scissors @Alex: โ๏ธ scissors
It's a tie!
// Rock Paper Scissors game between two members
interface Game {
challenger: string;
opponent: string;
challengerChoice?: string;
opponentChoice?: string;
}
mee6.command(
'rps-duel',
{
description: 'Challenge someone to Rock Paper Scissors',
options: [{ name: 'opponent', type: 'user', description: 'Who to challenge', required: true }],
},
async (ctx) => {
const opponentId = ctx.option<string>('opponent');
// Prevent self-play
if (opponentId === ctx.author.id) {
await ctx.reply('You cannot challenge yourself!');
return;
}
// Check if opponent is a bot
const opponent = await mee6.getMember(opponentId);
if (!opponent) {
await ctx.reply('That user is not in this server.');
return;
}
if (opponent.bot) {
await ctx.reply('You cannot challenge a bot!');
return;
}
// Create the game
const sent = await ctx.reply({
content: `๐ชจ๐โ๏ธ ${ctx.author.mention} challenges ${opponent.mention} to Rock Paper Scissors!\n\nBoth players: make your choice below (only you can see what you pick).`,
buttons: [
{ label: '๐ชจ Rock', customId: 'rock', style: 'secondary' },
{ label: '๐ Paper', customId: 'paper', style: 'secondary' },
{ label: 'โ๏ธ Scissors', customId: 'scissors', style: 'secondary' },
],
});
const game: Game = {
challenger: ctx.author.id,
opponent: opponentId,
};
await mee6.store.set(`rps_${sent.messageId}`, game, { ttl: 300 });
}
);
mee6.on('button', async (ctx) => {
// Only handle rock/paper/scissors buttons
if (!['rock', 'paper', 'scissors'].includes(ctx.customId)) return;
const game = await mee6.store.get<Game>(`rps_${ctx.message.id}`);
if (!game) return;
// Check if this person is a player
if (ctx.author.id !== game.challenger && ctx.author.id !== game.opponent) {
await ctx.reply({ content: 'This is not your game!', ephemeral: true });
return;
}
const isChallenger = ctx.author.id === game.challenger;
// Check if they already chose
if (isChallenger && game.challengerChoice) {
await ctx.reply({ content: 'You already made your choice!', ephemeral: true });
return;
}
if (!isChallenger && game.opponentChoice) {
await ctx.reply({ content: 'You already made your choice!', ephemeral: true });
return;
}
// Record the choice
if (isChallenger) {
game.challengerChoice = ctx.customId;
} else {
game.opponentChoice = ctx.customId;
}
// Confirm to the player (privately)
const emoji = ctx.customId === 'rock' ? '๐ชจ' : ctx.customId === 'paper' ? '๐' : 'โ๏ธ';
await ctx.reply({ content: `You chose ${emoji} ${ctx.customId}!`, ephemeral: true });
// Check if both have chosen
if (game.challengerChoice && game.opponentChoice) {
// Reveal and score
const result = determineWinner(game.challengerChoice, game.opponentChoice);
const challenger = await mee6.getMember(game.challenger);
const opponent = await mee6.getMember(game.opponent);
const c1 = game.challengerChoice;
const c2 = game.opponentChoice;
const e1 = c1 === 'rock' ? '๐ชจ' : c1 === 'paper' ? '๐' : 'โ๏ธ';
const e2 = c2 === 'rock' ? '๐ชจ' : c2 === 'paper' ? '๐' : 'โ๏ธ';
let resultText = '';
if (result === 0) {
resultText = "It's a tie!";
} else if (result === 1) {
resultText = `${challenger?.displayName || 'Challenger'} wins!`;
} else {
resultText = `${opponent?.displayName || 'Opponent'} wins!`;
}
await ctx.editOriginal({
content: `๐ชจ๐โ๏ธ **Game Over!**\n\n${challenger?.mention || `<@${game.challenger}>`}: ${e1} ${c1}\n${
opponent?.mention || `<@${game.opponent}>`
}: ${e2} ${c2}\n\n**${resultText}**`,
buttons: [],
});
// Clean up
await mee6.store.delete(`rps_${ctx.message.id}`);
} else {
// Still waiting for the other player
await mee6.store.set(`rps_${ctx.message.id}`, game, { ttl: 300 });
}
});
function determineWinner(choice1: string, choice2: string): number {
if (choice1 === choice2) return 0; // tie
if (
(choice1 === 'rock' && choice2 === 'scissors') ||
(choice1 === 'paper' && choice2 === 'rock') ||
(choice1 === 'scissors' && choice2 === 'paper')
) {
return 1; // player 1 wins
}
return 2; // player 2 wins
}