Build a blackjack game against the bot: /blackjack takes a bet in MEE6 coins, deals the cards in an embed with Hit and Stand buttons, pays out at the end, and keeps a leaderboard of the biggest wins
Play blackjack against the dealer and win MEE6 coins! The table is a picture: real cards on green felt, the dealer's first card face down until you stand.
How to play:
/blackjack <bet> โ Start a game with your coin betCommands:
/blackjack-stats โ View your personal statistics/blackjack-leaderboard โ See the biggest single-game winsThe game uses standard blackjack rules with automatic ace adjustment. Games expire after 1 hour if unfinished.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
๐ You win! (Profit: +50)

๐ BLACKJACK! You win 250 coins! (Profit: +150)

Biggest Single-Game Wins
๐ฅ @Alex โ 150 coins ๐ฅ @You โ 50 coins
// Blackjack game against the bot with MEE6 coins betting
interface Game {
userId: string;
bet: number;
playerHand: string[];
dealerHand: string[];
deck: string[];
messageId: string;
}
// A call moves at most 1,000,000,000 coins, the Economy plugin's own balance
// cap, and a won hand pays twice the bet back: bets stop at 500,000,000.
const MAX_BET = 500_000_000;
// Card deck and values
const SUITS = ['โ ', 'โฅ', 'โฆ', 'โฃ'];
const RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
function createDeck(): string[] {
const deck: string[] = [];
for (const suit of SUITS) {
for (const rank of RANKS) {
deck.push(rank + suit);
}
}
return shuffle(deck);
}
function shuffle(array: string[]): string[] {
const shuffled = [...array];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}
function cardValue(card: string): number {
const rank = card.slice(0, -1);
if (rank === 'A') return 11;
if (['J', 'Q', 'K'].includes(rank)) return 10;
return parseInt(rank);
}
function handValue(hand: string[]): number {
let value = 0;
let aces = 0;
for (const card of hand) {
const val = cardValue(card);
value += val;
if (card[0] === 'A') aces++;
}
// Adjust for aces
while (value > 21 && aces > 0) {
value -= 10;
aces--;
}
return value;
}
// ---------------------------------------------------------------------------
// The table: one picture per state of the hand, real cards on green felt
// ---------------------------------------------------------------------------
/** The suit pictures shipped with the module, by the suit's symbol. */
const SUIT_ART: Record<string, string> = { 'โ ': 'spades', 'โฅ': 'hearts', 'โฆ': 'diamonds', 'โฃ': 'clubs' };
const CARD_W = 104;
const CARD_H = 146;
const TABLE_W = 800;
const TABLE_H = 420;
function isRed(card: string): boolean {
const suit = card.slice(-1);
return suit === 'โฅ' || suit === 'โฆ';
}
/** The layers of one card: a face with its rank in two corners and its suit in the middle, or the back. */
function cardLayers(card: string, x: number, y: number, faceUp: boolean): any[] {
const layers: any[] = [
{ type: 'rect', x: x + 3, y: y + 5, width: CARD_W, height: CARD_H, color: '#000000', opacity: 30, radius: 10 },
];
if (!faceUp) {
layers.push({ type: 'image', src: 'card_back', x, y, width: CARD_W, height: CARD_H, radius: 10 });
return layers;
}
const rank = card.slice(0, -1);
const suit = SUIT_ART[card.slice(-1)];
const ink = isRed(card) ? '#D6343F' : '#1F2228';
// The index in two corners: the rank over a small suit, the lower one upside down
const corner = {
type: 'text',
text: rank,
size: 26,
font: 'inter',
weight: 'bold',
color: ink,
align: 'center',
valign: 'middle',
};
layers.push(
{ type: 'rect', x, y, width: CARD_W, height: CARD_H, color: '#FBFAF7', radius: 10 },
{ ...corner, x: x + 3, y: y + 5, width: 28, height: 28 },
{ type: 'image', src: suit, x: x + 9, y: y + 33, width: 16, height: 16 },
{ ...corner, x: x + CARD_W - 31, y: y + CARD_H - 33, width: 28, height: 28, rotate: 180 },
{ type: 'image', src: suit, x: x + CARD_W - 25, y: y + CARD_H - 49, width: 16, height: 16, rotate: 180 }
);
if (['J', 'Q', 'K'].includes(rank)) {
// A court card: its letter and its suit in a gold frame, between the two indexes
layers.push(
{
type: 'rect',
x: x + 32,
y: y + 18,
width: CARD_W - 64,
height: CARD_H - 36,
color: '#F6EAC8',
radius: 6,
outline: '#D9A93B',
thickness: 3,
},
{
type: 'text',
text: rank,
x: x + 32,
y: y + 30,
width: CARD_W - 64,
height: 40,
size: 32,
font: 'ginto',
weight: 'bold',
color: ink,
align: 'center',
valign: 'middle',
},
{ type: 'image', src: suit, x: x + CARD_W / 2 - 13, y: y + 78, width: 26, height: 26 }
);
} else {
const big = rank === 'A' ? 58 : 48;
layers.push({
type: 'image',
src: suit,
x: x + (CARD_W - big) / 2,
y: y + (CARD_H - big) / 2,
width: big,
height: big,
});
}
return layers;
}
type Tone = 'plain' | 'bust' | 'win';
/** A row of the table: who it is, their total in a pill, and their cards, fanned when there are many. */
function rowLayers(label: string, total: string, tone: Tone, hand: string[], hideFirst: boolean, y: number): any[] {
const pill = { plain: '#0D2D1A', bust: '#ED4245', win: '#F5C542' }[tone];
const layers: any[] = [
{ type: 'text', text: label, x: 44, y: y + 34, size: 22, font: 'ginto', weight: 'bold', color: '#D6F1DF' },
{
type: 'rect',
x: 44,
y: y + 72,
width: 132,
height: 40,
color: pill,
radius: 20,
opacity: tone === 'plain' ? 75 : 100,
},
{
type: 'text',
text: total,
x: 44,
y: y + 72,
width: 132,
height: 40,
size: 22,
font: 'inter',
weight: 'bold',
color: tone === 'win' ? '#4A3500' : '#FFFFFF',
align: 'center',
valign: 'middle',
},
];
const left = 204;
const room = TABLE_W - 34 - left - CARD_W;
const step = hand.length > 1 ? Math.min(CARD_W + 14, room / (hand.length - 1)) : 0;
hand.forEach((card, index) => {
layers.push(...cardLayers(card, Math.round(left + index * step), y + 16, !(hideFirst && index === 0)));
});
return layers;
}
/** The table as one picture: the dealer above, the player below; the dealer's first card face down until the end. */
async function drawTable(game: Game, gameOver: boolean): Promise<string> {
const playerValue = handValue(game.playerHand);
const dealerValue = handValue(game.dealerHand);
const dealerBust = gameOver && dealerValue > 21;
const dealerTotal = gameOver ? String(dealerValue) : `${handValue(game.dealerHand.slice(1))} + ?`;
const playerTone: Tone =
playerValue > 21 ? 'bust' : gameOver && (dealerValue > 21 || playerValue > dealerValue) ? 'win' : 'plain';
return await mee6.draw({
width: TABLE_W,
height: TABLE_H,
background: '#17502F',
layers: [
{
type: 'rect',
x: 12,
y: 12,
width: TABLE_W - 24,
height: TABLE_H - 24,
color: '#22744A',
radius: 30,
outline: '#3D8F60',
thickness: 2,
},
...rowLayers(
'DEALER',
dealerBust ? `${dealerTotal} ยท BUST` : dealerTotal,
dealerBust ? 'bust' : 'plain',
game.dealerHand,
!gameOver,
12
),
{ type: 'rect', x: 44, y: TABLE_H / 2 - 1, width: TABLE_W - 88, height: 2, color: '#FFFFFF', opacity: 10 },
...rowLayers(
'YOU',
playerValue > 21 ? `${playerValue} ยท BUST` : String(playerValue),
playerTone,
game.playerHand,
false,
TABLE_H / 2 - 4
),
],
});
}
/** How a finished hand ended, in words. */
function resultLine(game: Game): string {
const playerValue = handValue(game.playerHand);
const dealerValue = handValue(game.dealerHand);
if (playerValue > 21) return '๐ฅ **BUST!** You lose.';
if (dealerValue > 21) return '๐ **Dealer busts!** You win!';
if (playerValue > dealerValue) return '๐ **You win!**';
if (playerValue < dealerValue) return '๐ **Dealer wins.**';
return '๐ค **Push** (tie) - bet returned.';
}
/** The game's message: the table, then what to do, or how it ended and what it paid (`extra`). */
async function createGameEmbed(game: Game, gameOver = false, extra = ''): Promise<any> {
const playerValue = handValue(game.playerHand);
const dealerValue = handValue(game.dealerHand);
return {
title: '๐ฐ Blackjack',
description: gameOver ? resultLine(game) + extra : '**Hit** to draw a card, **Stand** to keep your hand.',
imageUrl: await drawTable(game, gameOver),
color: gameOver
? playerValue > 21 || (playerValue < dealerValue && dealerValue <= 21)
? 0xe74c3c
: 0x2ecc71
: 0x3498db,
footer: { text: `Bet: ${game.bet} coins` },
};
}
mee6.command(
'blackjack',
{
description: 'Play blackjack against the dealer',
options: [{ name: 'bet', type: 'integer', description: 'Amount of coins to bet (1 to 500000000)', required: true }],
},
async (ctx) => {
const bet = ctx.option<number>('bet');
if (bet < 1 || bet > MAX_BET) {
await ctx.reply({
content: `โ You can bet from 1 to ${MAX_BET.toLocaleString('en-US')} coins.`,
ephemeral: true,
});
return;
}
// Check balance
const balance = await mee6.economy.balance(ctx.author.id);
if (balance.coins < bet) {
await ctx.reply({
content: `โ You don't have enough coins. Your balance: ${balance.coins} coins.`,
ephemeral: true,
});
return;
}
// Create new game
const deck = createDeck();
const game: Game = {
userId: ctx.author.id,
bet: bet,
playerHand: [deck.pop()!, deck.pop()!],
dealerHand: [deck.pop()!, deck.pop()!],
deck: deck,
messageId: '',
};
// Check for instant blackjack
const playerValue = handValue(game.playerHand);
if (playerValue === 21) {
// Blackjack! Pay 3:2 โ the bet never left: only the profit is paid,
// raised by the server's Economy game boosts
const paid = await mee6.economy.add(ctx.author.id, Math.floor(bet * 1.5), { boost: 'games' });
const profit = paid.amount;
const winnings = bet + profit;
// Update stats
const m = mee6.store.member(ctx.author.id);
await m.incr('bj_games', 1);
await m.incr('bj_wins', 1);
const biggestWin = await m.get<number>('bj_biggest_win', 0);
if (profit > biggestWin) {
await m.set('bj_biggest_win', profit);
}
await ctx.reply({
embed: {
...(await createGameEmbed(game, true)),
description: `๐ **BLACKJACK!** You win ${winnings} coins! (Profit: +${profit})`,
color: 0xf1c40f,
},
});
return;
}
// The bet is held for the rest of the game
await mee6.economy.remove(ctx.author.id, bet);
// Send game board
const sent = await ctx.reply({
embed: await createGameEmbed(game),
buttons: [
{ label: 'Hit', customId: 'bj_hit', style: 'primary' },
{ label: 'Stand', customId: 'bj_stand', style: 'secondary' },
],
});
game.messageId = sent.messageId;
await mee6.store.set(`blackjack_${sent.messageId}`, game, { ttl: 3600 });
}
);
mee6.on('button', async (ctx) => {
if (!ctx.customId.startsWith('bj_')) return;
const game = await mee6.store.get<Game>(`blackjack_${ctx.message.id}`);
if (!game) {
await ctx.reply({ content: 'โ This game has expired.', ephemeral: true });
return;
}
if (ctx.author.id !== game.userId) {
await ctx.reply({ content: 'โ This is not your game.', ephemeral: true });
return;
}
if (ctx.customId === 'bj_hit') {
// Deal another card
game.playerHand.push(game.deck.pop()!);
const playerValue = handValue(game.playerHand);
if (playerValue > 21) {
// Bust - game over
await endGame(ctx, game, true);
} else if (playerValue === 21) {
// Auto-stand on 21
await dealerPlay(ctx, game);
} else {
// Continue playing
await ctx.editOriginal({
embed: await createGameEmbed(game),
buttons: [
{ label: 'Hit', customId: 'bj_hit', style: 'primary' },
{ label: 'Stand', customId: 'bj_stand', style: 'secondary' },
],
});
await mee6.store.set(`blackjack_${ctx.message.id}`, game, { ttl: 3600 });
}
} else if (ctx.customId === 'bj_stand') {
// Dealer's turn
await dealerPlay(ctx, game);
}
});
async function dealerPlay(ctx: any, game: Game) {
// Dealer draws until 17+
while (handValue(game.dealerHand) < 17) {
game.dealerHand.push(game.deck.pop()!);
}
await endGame(ctx, game, true);
}
async function endGame(ctx: any, game: Game, showResult: boolean) {
const playerValue = handValue(game.playerHand);
const dealerValue = handValue(game.dealerHand);
// The game ends before it pays: a second click finds no game to pay again
await mee6.store.delete(`blackjack_${game.messageId}`);
let winnings = 0;
let profit = -game.bet;
let won = false;
let lost = false;
if (playerValue > 21) {
// Player bust - lose bet (already removed)
lost = true;
} else if (dealerValue > 21 || playerValue > dealerValue) {
// Player wins: the held bet comes back as is, the winnings take the
// server's Economy game boosts
await mee6.economy.add(ctx.author.id, game.bet);
const paid = await mee6.economy.add(ctx.author.id, game.bet, { boost: 'games' });
profit = paid.amount;
winnings = game.bet + profit;
won = true;
} else if (playerValue === dealerValue) {
// Push - return bet
winnings = game.bet;
profit = 0;
await mee6.economy.add(ctx.author.id, winnings);
} else {
// Dealer wins - bet already removed
lost = true;
}
if (lost) {
// The bet is gone; a "games losses" boost on the server takes its share more
const { gamesLosses } = await mee6.economy.boost();
const extra = Math.round((game.bet * gamesLosses) / 100);
if (extra > 0) {
await mee6.economy.remove(ctx.author.id, extra);
profit -= extra;
}
}
// Update stats
const m = mee6.store.member(game.userId);
await m.incr('bj_games', 1);
if (won) {
await m.incr('bj_wins', 1);
}
if (profit > 0) {
const biggestWin = await m.get<number>('bj_biggest_win', 0);
if (profit > biggestWin) {
await m.set('bj_biggest_win', profit);
}
}
// Show final result
let resultText = '';
if (profit > 0) {
resultText = ` (Profit: +${profit})`;
} else if (profit < 0) {
resultText = ` (Loss: ${profit})`;
}
await ctx.editOriginal({
embed: await createGameEmbed(game, true, resultText),
buttons: [],
});
}
mee6.command('blackjack-stats', { description: 'View your blackjack statistics' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const games = await m.get<number>('bj_games', 0);
const wins = await m.get<number>('bj_wins', 0);
const biggestWin = await m.get<number>('bj_biggest_win', 0);
const winRate = games > 0 ? Math.round((wins / games) * 100) : 0;
await ctx.reply({
embed: {
title: '๐ Your Blackjack Stats',
fields: [
{ name: 'Games Played', value: `${games}`, inline: true },
{ name: 'Wins', value: `${wins}`, inline: true },
{ name: 'Win Rate', value: `${winRate}%`, inline: true },
{ name: 'Biggest Win', value: `${biggestWin} coins`, inline: false },
],
color: 0x9b59b6,
},
ephemeral: true,
});
});
mee6.command('blackjack-leaderboard', { description: 'View the biggest blackjack wins' }, async (ctx) => {
const top = await mee6.store.memberTop('bj_biggest_win', 10);
if (top.length === 0) {
await ctx.reply({ content: '๐ No games played yet!', ephemeral: true });
return;
}
let leaderboard = '';
for (let i = 0; i < top.length; i++) {
const entry = top[i];
const medal = i === 0 ? '๐ฅ' : i === 1 ? '๐ฅ' : i === 2 ? '๐ฅ' : `${i + 1}.`;
leaderboard += `${medal} <@${entry.user_id}> โ **${entry.value}** coins\n`;
}
await ctx.reply({
embed: {
title: '๐ Blackjack Leaderboard',
description: '**Biggest Single-Game Wins**\n\n' + leaderboard,
color: 0xf1c40f,
},
});
});
The pictures this example ships with. Remix it to change them or add your own.
spadesheartsdiamondsclubscard_back