Guide – 8 min read
Hangman is a game everyone knows, and you can run it in your own Discord server without writing any code. In this guide you will make a Discord hangman game with a secret word, a /guess command, mistakes, a win and a loss, using the new text tools and the letter loop.
No code Free Windows About 20 minutes
What the hangman bot does
Hangman is the classic word game: the bot picks a secret word, shows one blank for every letter, and people guess one letter at a time. Right letters appear in the word. Wrong letters count as mistakes, and six mistakes means the game is over.
In this guide you will build it with Cubevate, with no code. You will use two commands: /hangman starts a new game and /guess tries a letter. It also shows off the new text tools and the letter loop from Cubevate 1.8.0.
Before you start
You need Cubevate 1.8.0 or newer (the new text tools are not in older versions), and a bot that is made and invited to your server. If you have not done that yet, follow How to make a Discord bot without coding first. When you finish, download your bot again so it gets the new blocks.
Step 1: Make three memory boxes
The bot has to remember the secret word, the letters already tried and the number of mistakes. On the Memory boxes page press Make a memory box three times:
- word: it remembers Some words, for Each server has its own. This is the secret word.
- guessed: Some words, Each server has its own. These are the letters tried so far.
- wrong: A number, Each server has its own, starts as 0. These are the mistakes.
Because the boxes belong to the server, everyone in the server plays the same game together.
Step 2: The /hangman command
On the Blocks page press Add event. This command picks a word and starts a game.
- Choose the purple WHEN block Someone uses a /command. Type the name hangman and the description Start a new game of hangman.
- In the green THEN DO area add Pick one thing at random. Type some words separated by commas, for example banana, planet, rocket, guitar, dragon, castle, pizza, jungle, and name the note pick.
- Add Put something in a memory box: put {temp.pick} in the box word.
- Add Reset a memory box for guessed, and another one for wrong. This clears the last game.
- Add Change or measure a text. The text is {temp.pick}, choose Count its letters, and name the note len.
- Add Change or measure a text again. The text is {temp.pick}, choose Hide every letter except some, leave the extra box empty, and name the note hidden. Every letter is now hidden.
- Add Send a message and type: New game of hangman! The word has {temp.len} letters: `{temp.hidden}` and on the next line Try a letter with /guess. You can make 6 mistakes.
- Press OK.
The little marks around {temp.hidden} are backticks. They stop Discord from turning the underscores into italic text.
Step 3: The /guess command
Add a second event. This is the main part of the game.
- Choose Someone uses a /command, name it guess, and under Add a blank to fill in make a blank called letter (kind of answer: Words, must fill in: Yes).
- In THEN DO add Change or measure a text: the text is {option.letter}, choose make it all small letters, note name low. This way A and a are the same letter.
- Add it again: the text is {temp.low}, choose Take the first letters, extra 1 is 1, note name l. If someone types a whole word, only its first letter counts.
- Add it a third time: the text is {memory.word}, choose Count its letters, note name wl. If this is 0, there is no game yet.
Now the rules. A sub-event is a smaller rule inside an event that only runs when its own check is true. Press Add sub-event under your /guess event for each of these, in this order:
Step 4: The sub-events
Sub-event A: no game yet. ONLY IF Compare two things: {temp.wl} is equal to 0. THEN DO Send a message: There is no game yet. Type /hangman to start one.
Sub-event B: a game is running. ONLY IF Otherwise (it sits right below sub-event A). THEN DO Change or measure a text: the text is {memory.guessed}, choose Find the position of something, extra 1 is {temp.l}, note name seen. Inside B you add two more sub-events:
- B1: already tried. ONLY IF {temp.seen} is more than 0. Send a message: You already tried **{temp.l}**. Pick another letter.
- B2: the real guess. ONLY IF Otherwise. THEN DO, in this order: Put something in a memory box ({memory.guessed}{temp.l} in the box guessed), then Change or measure a text to find {temp.l} in {memory.word} (note name pos), then to hide every letter of {memory.word} except the ones in {memory.guessed} (note name shown), then to count how often _ is in {temp.shown} (note name left).
Step 5: Mistakes, winning and losing
Inside sub-event B2 add these sub-events, in this order:
- Mistake. ONLY IF {temp.pos} is equal to 0 (the letter is not in the word). THEN DO Add to a number box: add 1 to the box wrong.
- Win. ONLY IF {temp.left} is equal to 0 (no hidden letters left). THEN DO Send a message: You got it! The word was **{memory.word}**. Type /hangman to play again. Then Reset a memory box for word so the game is over.
- Not won yet. ONLY IF Otherwise. Inside it add two more sub-events: first ONLY IF {memory.wrong} is at least 6 for losing (see the next step), then ONLY IF Otherwise with THEN DO Send a message: `{temp.shown}` and on the next line Mistakes: {memory.wrong} of 6. Tried: {memory.guessed}
Step 6: Spell the word with the letter loop
When someone loses, spell the secret word out one letter at a time. This is a good place for the new Do it for each letter block. The losing sub-event (ONLY IF {memory.wrong} is at least 6) has these blocks:
- THEN DO Change or measure a text: the text is {memory.word}, choose MAKE IT ALL CAPITALS, note name big.
- THEN DO Remember something for a moment: name spelled, value The word was:.
- Add a sub-event with ONLY IF Do it for each letter and the text {temp.big}. Its THEN DO is Remember something for a moment: name spelled, value {temp.spelled} {loop.item}. {loop.item} is the current letter, so the note grows by one letter every round.
- Add another sub-event with no ONLY IF. Its THEN DO is Send a message: Game over. {temp.spelled} and on the next line Type /hangman to try again. Then Reset a memory box for word.
Order matters here: the letter loop sub-event must come before the sub-event that sends the message. The bot shows: ‘Game over. The word was: B A N A N A’.
Try it
Press Finish & host, put your bot online and use /hangman in your server. You can also try everything first with Live mode and the Pretend switch on. Guess a few letters, make the same guess twice, win a game, then lose one on purpose.
Make it better
- Add many more words to the list in the first event. Ask your friends for their favourite words.
- Put the game in one channel by adding a check for the channel on both commands.
- Show the game in a fancy box with a picture instead of plain text.
- Give a coin or some XP for a win. See the Economy and Levels pages of the Dashboard.
- Make the game longer or shorter by changing the 6 in the lose check and in the messages.
Video: host your bot 24/7 and set up the Dashboard
Watch the full walkthrough: how to host your Discord bot 24/7 on a bot host and set up the Dashboard, step by step.
Ready to play?
Download Cubevate for free and make your first game today. If you get stuck, the Cubevate docs have a step-by-step guide for everything, and you can ask questions in the Cubefem Discord community.