Add /casino coinflip and /casino dice against the bot for MEE6 coins, and /casino stats which shows a member\'s games played, win rate, coins won and lost and net profit, with /casino top ranking the luckiest members
Gambling games where members bet MEE6 coins against the bot. /casino coinflip is a 50/50 heads or tails bet, /casino dice rolls two dice and you win if you beat the bot's roll. Track your performance with /casino stats (games played, win rate, net profit) and see the luckiest members with /casino top.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
The coin landed on tails!
✅ You won!
+50 coins
The coin landed on heads!
❌ You lost!
-100 coins
❌ You lost!
🎲 4 + 2 = 6
🎲 3 + 5 = 8
-80 coins
1
1
100.0%
50
0
+50
❌ You lost!
🎲 4 + 1 = 5
🎲 2 + 6 = 8
-150 coins
The coin landed on heads!
✅ You won!
+60 coins
2
0
0.0%
0
250
-250
1. You — +50 coins (1 games) 2. Jordan — -20 coins (2 games) 3. Alex — -250 coins (2 games)
// Gambling games: coinflip and dice against the bot for MEE6 coins
interface GamblingStats {
games: number;
wins: number;
coinsWon: number;
coinsLost: number;
}
/** Get or initialize a member's gambling stats. */
async function getStats(userId: string): Promise<GamblingStats> {
const m = mee6.store.member(userId);
const games = await m.get<number>('games', 0);
const wins = await m.get<number>('wins', 0);
const coinsWon = await m.get<number>('coins_won', 0);
const coinsLost = await m.get<number>('coins_lost', 0);
return { games, wins, coinsWon, coinsLost };
}
/** Update stats after a game. */
async function recordGame(userId: string, won: boolean, amount: number) {
const m = mee6.store.member(userId);
await m.incr('games', 1);
if (won) {
await m.incr('wins', 1);
await m.incr('coins_won', amount);
} else {
await m.incr('coins_lost', amount);
}
}
// Coinflip command: 50/50 bet on heads or tails
mee6.command(
'casino coinflip',
{
description: 'Flip a coin and bet MEE6 coins',
options: [
{ name: 'bet', type: 'integer', description: 'Coins to bet', required: true },
{
name: 'choice',
type: 'string',
description: 'Heads or tails?',
required: true,
choices: [
{ name: 'Heads', value: 'heads' },
{ name: 'Tails', value: 'tails' },
],
},
],
},
async (ctx) => {
const bet = ctx.option<number>('bet');
const choice = ctx.option<string>('choice');
if (bet < 1) {
await ctx.reply('❌ Bet at least 1 coin.');
return;
}
const balance = await mee6.economy.balance(ctx.author.id);
if (balance.coins < bet) {
await ctx.reply(`❌ You only have ${balance.coins} coins.`);
return;
}
// Flip the coin
const result = Math.random() < 0.5 ? 'heads' : 'tails';
const won = result === choice;
// Wins and losses follow the server's Economy game boosts
if (won) {
const { amount } = await mee6.economy.add(ctx.author.id, bet, { boost: 'games' });
await recordGame(ctx.author.id, true, amount);
await ctx.reply({
embed: {
title: '🪙 Coinflip',
description: `The coin landed on **${result}**!`,
color: '#57f287',
fields: [
{ name: 'Result', value: '✅ You won!', inline: true },
{ name: 'Winnings', value: `+${amount} coins`, inline: true },
],
},
});
} else {
const { amount } = await mee6.economy.remove(ctx.author.id, bet, { boost: 'games' });
await recordGame(ctx.author.id, false, amount);
await ctx.reply({
embed: {
title: '🪙 Coinflip',
description: `The coin landed on **${result}**!`,
color: '#ed4245',
fields: [
{ name: 'Result', value: '❌ You lost!', inline: true },
{ name: 'Lost', value: `-${amount} coins`, inline: true },
],
},
});
}
}
);
// Dice command: roll 2 dice, beat the bot's roll
mee6.command(
'casino dice',
{
description: 'Roll dice and bet MEE6 coins',
options: [{ name: 'bet', type: 'integer', description: 'Coins to bet', required: true }],
},
async (ctx) => {
const bet = ctx.option<number>('bet');
if (bet < 1) {
await ctx.reply('❌ Bet at least 1 coin.');
return;
}
const balance = await mee6.economy.balance(ctx.author.id);
if (balance.coins < bet) {
await ctx.reply(`❌ You only have ${balance.coins} coins.`);
return;
}
// Roll dice: each player rolls 2 dice
const playerRoll1 = Math.floor(Math.random() * 6) + 1;
const playerRoll2 = Math.floor(Math.random() * 6) + 1;
const playerTotal = playerRoll1 + playerRoll2;
const botRoll1 = Math.floor(Math.random() * 6) + 1;
const botRoll2 = Math.floor(Math.random() * 6) + 1;
const botTotal = botRoll1 + botRoll2;
let result: string;
let won: boolean;
let color: number;
// What moved, raised by the server's Economy game boosts
let moved = 0;
if (playerTotal > botTotal) {
moved = (await mee6.economy.add(ctx.author.id, bet, { boost: 'games' })).amount;
await recordGame(ctx.author.id, true, moved);
result = '✅ You won!';
won = true;
color = 0x57f287;
} else if (playerTotal < botTotal) {
moved = (await mee6.economy.remove(ctx.author.id, bet, { boost: 'games' })).amount;
await recordGame(ctx.author.id, false, moved);
result = '❌ You lost!';
won = false;
color = 0xed4245;
} else {
// Tie: no coins change hands, no stats recorded
result = '🤝 Tie! No coins changed.';
won = false;
color = 0x5865f2;
}
await ctx.reply({
embed: {
title: '🎲 Dice Roll',
description: result,
color,
fields: [
{
name: 'Your roll',
value: `🎲 ${playerRoll1} + ${playerRoll2} = **${playerTotal}**`,
inline: true,
},
{
name: 'Bot roll',
value: `🎲 ${botRoll1} + ${botRoll2} = **${botTotal}**`,
inline: true,
},
{
name: 'Change',
value: won ? `+${moved} coins` : playerTotal === botTotal ? '±0 coins' : `-${moved} coins`,
inline: false,
},
],
},
});
}
);
// Stats view command: view gambling stats
mee6.command(
'casino stats',
{
description: 'View gambling statistics',
options: [{ name: 'user', type: 'user', description: 'Member to view (defaults to you)' }],
},
async (ctx) => {
const userId = ctx.option<string>('user', ctx.author.id);
const member = await mee6.getMember(userId);
if (!member) {
await ctx.reply('❌ Member not found.');
return;
}
const stats = await getStats(userId);
const winRate = stats.games > 0 ? ((stats.wins / stats.games) * 100).toFixed(1) : '0.0';
const netProfit = stats.coinsWon - stats.coinsLost;
const profitSign = netProfit >= 0 ? '+' : '';
await ctx.reply({
embed: {
title: `🎰 ${member.displayName}'s Gambling Stats`,
color: '#f1c40f',
fields: [
{ name: 'Games played', value: `${stats.games}`, inline: true },
{ name: 'Games won', value: `${stats.wins}`, inline: true },
{ name: 'Win rate', value: `${winRate}%`, inline: true },
{ name: 'Coins won', value: `${stats.coinsWon}`, inline: true },
{ name: 'Coins lost', value: `${stats.coinsLost}`, inline: true },
{ name: 'Net profit', value: `${profitSign}${netProfit}`, inline: true },
],
},
});
}
);
// Stats top command: leaderboard by net profit
mee6.command(
'casino top',
{
description: 'View top gamblers by net profit',
},
async (ctx) => {
// Calculate net profit for leaderboard ranking
const gamesPlayers = await mee6.store.memberTop('games', 50);
// Filter to members who have actually played, then calculate net profit
const rankings: { userId: string; netProfit: number; games: number }[] = [];
for (const player of gamesPlayers) {
if (player.value > 0) {
const stats = await getStats(player.user_id);
const netProfit = stats.coinsWon - stats.coinsLost;
rankings.push({ userId: player.user_id, netProfit, games: stats.games });
}
}
// Sort by net profit descending
rankings.sort((a, b) => b.netProfit - a.netProfit);
const top10 = rankings.slice(0, 10);
if (top10.length === 0) {
await ctx.reply('No gambling stats yet! Play `/casino coinflip` or `/casino dice` to get started.');
return;
}
// Build leaderboard text
let description = '';
for (let i = 0; i < top10.length; i++) {
const rank = i + 1;
const { userId, netProfit, games } = top10[i];
const member = await mee6.getMember(userId);
const name = member ? member.displayName : 'Unknown';
const profitSign = netProfit >= 0 ? '+' : '';
description += `**${rank}.** ${name} — ${profitSign}${netProfit} coins (${games} games)\n`;
}
await ctx.reply({
embed: {
title: '🏆 Top Gamblers',
description,
color: '#f1c40f',
footer: { text: 'Ranked by net profit' },
},
});
}
);