Discord Bot

A Discord bot with various commands used by me and my friends in our private Discord

Published on Apr 01, 2022

Reading time: 2 minutes.


Built with

Discord.JS
NodeJS

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

triggering bot’s help command

Fairly self-explanatory, the bot sends a list of commands to you via direct message.

output of help command

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

flipped heads

Flips a coin, 50/50 chance of returning heads or tails. Definitely the simplest of the commands, but can be handy on occasion.

teams

two users split into 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

uploading file via bot

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

making a simple 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

odds contest

Starts a game of “odds” which has the following simple rules:

  1. The challenged player chooses a maximum number, essentially deciding their own odds of victory
  2. The challenger sees the max number the other player chose and picks a number between 0 and that number challenger chooses number
  3. The challenger waits for the challenged to pick their number
  4. 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.