My project is a playable Hangman Discord Bot with generative text. The player on the discord guesses for a word or a sentence from generative text by suggesting letters within a certain number of guesses. My plan was to generate random words but it’s still its hardcoded version. I wanted the hangman have some personality. A version that when the player fails hangman give some emotional reactions like “Taking someone’s life shouldn’t be this easy… “ I used emojis to represent the hangman.
CODE
For this project, I’ve used discord.js library. Discord API allows you to create bots that can take Discord functions like messages and reactions as input and return Discord functions as output. All of them were in Discord Developer website in Resources. I’ve created the hangman game in to it’s own file. Where I call it with Hangman game command. I’ve got on class with constructor and 5 functions in it.
For messageEmbed,
I’ve used discord.js library’s example which they show the constructor and the methods I can use.
new Discord.MessageEmbed() => https://discord.js.org/#/docs/main/stable/class/MessageEmbed
iI’ve used, setColor, setTItle, setDescription, addField, addTimeStamp methods.
waitforReaction() => The reactions to trigger letters on the hangman board. I utilized the reactions to be able to input your letters that you wanted to guess.
makeGuess(reaction){} => Getting the guess letter. in this function, I got the guess letter from inputted reaction emoji and stored the English character in a map that had previously guessed characters and display them on the screen in the game.
getDescription() {} => I’ve built up the description of embed(or actual hangman game) that was graphical display that would show the hangman being built as well as include the word as you guessed it and show the letters that you got correct. I’ve represented the hangman as bunch of emojis with a top hat, a face, a shirt, shorts and then shoes. Then I’ve used a code blocks “```” with the three ticks surrounding the code, which I’ve learned treat this text as is display as is don’t do anything fancy to it I understand. Which allowed me to have the hangman board look like this and for the spacing.
PROBLEMS
My initial idea was to take the emoji or reaction and the kind of key code (A=:A:) that discord gives it which is the colons with the actual emoji name in the middle and use that to parse out what letter the user guessed. But it doesn’t work, because (A=:A:) for example is actually a blood type A and there is no :C:
So I’ve used the blue ones which is called, regional indicator symbols
:regional_indicator_a:
:regional_indicator_b:
:regional_indicator_c:
However, discord.js doesn’t actually send over the way you type in the original indicator symbols into discord as a string to the bot. So there was o way for me to parse the colons and the middle and get the character from what is typed in. All is given the actual emoji as a unicode character. So I’ve built up an array of the unicode characters and their actual english typed characters. Also, unicode Characters in vs code look a lot like the standard type version which made it confusing but they were smaller than normal.
Glitch link for the project