Build hangman: /hangman start begins a round from a word list in settings, /hangman letter guesses one letter, the same message keeps showing the revealed word and the letters already missed, and the round ends on the word or six mistakes Make the word bank editable in list settings, retaining the existing words as defaults.
A classic hangman word game. /hangman start begins a round with a random word, and /hangman letter guesses one letter at a time. The board updates in place showing revealed letters, missed guesses, and the hangman drawing. Win by guessing the word before six mistakes!
Made by MEE6. Remix it to get a copy of your own and change anything you like.
+---+
| |
O |
| |
|
|
=========```
**Word:** K E Y B O A R D
**Missed:** T, N
**Mistakes:** 2/6
🎉 **You won!** The word was **KEYBOARD**
✅ Letter guessed!
✅ Letter guessed!
✅ Letter guessed!
✅ Game updated!
// Hangman game — /hangman start and /hangman letter
interface HangmanGame {
word: string;
guessed: string[]; // all letters guessed
mistakes: number;
messageId: string;
channelId: string;
}
const WORDS = [
'algorithm',
'computer',
'programming',
'developer',
'javascript',
'typescript',
'discord',
'database',
'function',
'variable',
'command',
'server',
'channel',
'community',
'message',
'keyboard',
'monitor',
'internet',
'software',
'hardware',
'network',
'security',
'encryption',
'interface',
'boolean',
];
mee6.settings({
words: {
type: 'list',
label: 'Words',
maxItems: 100,
fields: { word: { type: 'string', label: 'Word', required: true } },
default: WORDS.map((word) => ({ word })),
},
});
const HANGMAN_STAGES = [
'```\n +---+\n | |\n |\n |\n |\n |\n=========```',
'```\n +---+\n | |\n O |\n |\n |\n |\n=========```',
'```\n +---+\n | |\n O |\n | |\n |\n |\n=========```',
'```\n +---+\n | |\n O |\n /| |\n |\n |\n=========```',
'```\n +---+\n | |\n O |\n /|\\ |\n |\n |\n=========```',
'```\n +---+\n | |\n O |\n /|\\ |\n / |\n |\n=========```',
'```\n +---+\n | |\n O |\n /|\\ |\n / \\ |\n |\n=========```',
];
function displayWord(word: string, guessed: string[]): string {
return word
.split('')
.map((ch) => (guessed.includes(ch.toLowerCase()) ? ch.toUpperCase() : '_'))
.join(' ');
}
function renderGame(game: HangmanGame): { content: string; buttons: any[] } {
const word = game.word;
const display = displayWord(word, game.guessed);
const missed = game.guessed.filter((ch) => !word.includes(ch));
const won = word.split('').every((ch) => game.guessed.includes(ch));
const lost = game.mistakes >= 6;
let content = HANGMAN_STAGES[game.mistakes] + '\n\n';
content += `**Word:** ${display}\n`;
if (missed.length > 0) {
content += `**Missed:** ${missed.join(', ').toUpperCase()}\n`;
}
content += `**Mistakes:** ${game.mistakes}/6\n\n`;
if (won) {
content += `🎉 **You won!** The word was **${word.toUpperCase()}**`;
return { content, buttons: [] };
}
if (lost) {
content += `💀 **Game over!** The word was **${word.toUpperCase()}**`;
return { content, buttons: [] };
}
content += 'Use `/hangman letter` to guess a letter.';
return { content, buttons: [] };
}
mee6.command('hangman start', { description: 'Start a new hangman game' }, async (ctx) => {
const WORDS = (ctx.settings.words as { word: string }[])
.map((row) => row.word.trim().toLowerCase())
.filter((word) => /^[a-z]+$/.test(word));
if (!WORDS.length) {
await ctx.reply('No playable words configured. Add words using letters A–Z in settings.');
return;
}
const word = WORDS[Math.floor(Math.random() * WORDS.length)];
const game: HangmanGame = {
word,
guessed: [],
mistakes: 0,
messageId: '',
channelId: ctx.channelId,
};
const rendered = renderGame(game);
const sent = await ctx.reply(rendered);
game.messageId = sent.messageId;
await mee6.store.set(`hangman_${ctx.channelId}`, game, { ttl: 3600 });
});
mee6.command(
'hangman letter',
{
description: 'Guess a letter',
options: [{ name: 'letter', type: 'string', description: 'A single letter', required: true }],
},
async (ctx) => {
const game = await mee6.store.get<HangmanGame>(`hangman_${ctx.channelId}`);
if (!game) {
await ctx.reply('No game in progress. Start one with `/hangman start`!');
return;
}
const input = ctx.option<string>('letter').toLowerCase().trim();
if (input.length !== 1 || !/[a-z]/.test(input)) {
await ctx.reply('Please guess a single letter (a-z).');
return;
}
if (game.guessed.includes(input)) {
await ctx.reply(`You already guessed **${input.toUpperCase()}**!`);
return;
}
game.guessed.push(input);
if (!game.word.includes(input)) {
game.mistakes++;
}
const rendered = renderGame(game);
await mee6.editMessage(game.channelId, game.messageId, rendered);
const won = game.word.split('').every((ch) => game.guessed.includes(ch));
const lost = game.mistakes >= 6;
if (won || lost) {
await mee6.store.delete(`hangman_${ctx.channelId}`);
await ctx.reply({ content: '✅ Game updated!', ephemeral: true });
} else {
await mee6.store.set(`hangman_${ctx.channelId}`, game, { ttl: 3600 });
await ctx.reply({ content: '✅ Letter guessed!', ephemeral: true });
}
}
);