This project uses the Discord.JS NPM package to interact with the Discord API. There are several different command that the bot recognizes when being mentioned in a server it is a member of.
The bot was mostly just a fun side-project for myself, I had trouble getting anyone to actually use it. The integration with Mega (which I will go into more detail on later) was probably the most difficult and interesting part of the project.
Below is a list of the commands and sample output.
help
Fairly self-explanatory, the bot sends a list of commands to you via direct message.
The list of commands is generated dynamically, so as I added new commands I didn’t need to go back and update the help command, which was handy.
coin
Flips a coin, 50/50 chance of returning heads or tails. Definitely the simplest of the commands, but can be handy on occasion.
teams
This command was made because of how often I found us going to a website to split ourselves evenly into two teams. I would say this is the most popular command, as it is useful for randomization.
upload
Our group has a MEGA server where we store images and videos. It can be annoying to log in and manually upload stuff, so I added a command for the bot to connect to MEGA and upload files sent to it. Using the file extension, it decides whether it is a picture, video, or something else, and sends them to their respective folder.
MEGA does not have an official API for this, but thankfully there was an open-source unofficial NPM package that helped me with this task, although its documentation was a little lacking at the time I was developing.
poll
Makes a “poll” with unlimited number of options. Each option becomes its own message and users use Discord’s reactions to vote on each option.
odds
Starts a game of “odds” which has the following simple rules:
- The challenged player chooses a maximum number, essentially deciding their own odds of victory
- The challenger sees the max number the other player chose and picks a number between 0 and that number
- The challenger waits for the challenged to pick their number
- If the numbers match, the challenger wins, otherwise the challenged wins
In our group, the game is almost always accompanied with a bet, and the number the challenged picks usually corresponds with the size of the wager. So, a bet with minimal consequences will probably be met with a small max number, and vice versa.