Making a Phrase Tracking Discord Bot

This was my first time making a discord bot. After learning and becoming proficient at C++ through my school’s coursework, I decided to do something new and actually apply my new skills to a project. I wanted to start pretty basic and make a simple phrase logging program similar to a popular discord bot called Cup.

Cup was a bot that was created as a joke in a server where you could type on of two things: cup (to gain a cup) and cups (to see how many cups you had). Any other messages typed in this server would result in your message being deleted and a copypaste meme response by the tracking bot. The bot and server became wildly popular with over 10,000 members and millions of cups typed. Unfortunately, in October 2020, the bot was overloaded and the server shut down.

However the concept intrigued me, and I wanted to create my own implementation based on the same concept. In my personal discord server with many of my friends, we have a channel called #good-morning-gamers where, if the user chooses wants to, you type gmg in the morning when you wake up. A nice little morning routine pillar as I see it. I thought that this was an interesting data set as most of the users in the server interact with the channel within 15 minutes of waking up. Knowing this I wanted to create a bot that would do the following:

  • Log how many total times a user has said “gmg”
  • Log the time of day that the user said “gmg”
  • View their average wake up time (as determined by when they interact with the channel)
  • Create a ranking system that would encourage daily gmg streaks

After outlining the above criteria I got to work. This was my first time learning JavaScrpit and the Discord.js library. Discord.js is an open source library to use the Discord API on Javascript. To get started I set up an Ubuntu server running NodeJS, mySQL Lite and NPM. After installing all of the required repos I got to work implementing a SQL Database that would hold the usersIDs and their respective “gmg” values. I would say that this was the hardest part to implement because this was also my first time using SQL in a project. The first command I implemented was a .stats command and a setstats command so I could make sure that the database was working correctly:

After that was working I then implemented the code to atuomatically add 1 to the userstats when they said gmg in the #good-morning-gamers channel. Unfortunately due to time constraints, that is where the project ended. I felt as it was good enough and felt as if it had served its purpose for making me get to know javascript and SQL. The projects source code will be linked on my Github, and it was a fun first project!