Case Study Page

project thumbnail

Aegis

A Discord bot that generates a unique invite link and tracks how many users someone has invited to a Discord server with their assigned invite link

Year

2023

Type

Personal Project

Role

Solo Developer

Project goal

The goal was to create an invite tracking system handled by a Discord bot to be used during a recruitment challenge event in a Discord server. The bot would be used to generate a unique invite link for each participant, which they would then use to invite new members to the server.

The bot would also be able to track server joins and leaves, check which server roles someone has, and return information such as a leaderboard of the top recruiters and individual records for each participant to know how many members they've recruited and who those members are.

Technologies Used

I used Node.js for the functionality, Airtable for the database (I used their API for performing the CRUD operations), and Autocode for hosting the bot.

How it was created

Before I started coding, I began planning out which commands I would need the bot to have along with how I would go about coding them. The easiest way to track who invited who would be to have a command that generates a new server invite link and assigns it to the person that ran the command so that whenever they invite someone with that link, the bot will log that information in the database and will start adding up how many people they've invited. I also knew that I would need a command to retrieve information on a participant such as the total of users they've invited along with the list of who those users are and whether or not they count towards their total based on certain conditions. Last but not least, I would also need a command to retrieve a leaderboard of the top recruiters.

Once I had finalized the commands I needed, I then planned out the event listeners that I would need to make the invite tracking possible and update the database accordingly whenever the event listeners were triggered. I added an event listener for when a user joins the server, when a user leaves the server, and when a users roles are updated. When a new member joins the server using a link that has been generated by a participant, it should create a profile for them so that the bot can log when they joined and who invited them. This would also make it possible for the bot to keep track of whether or not they stay in the server and if they have the required roles because these two conditions affect whether or not the invited member counts towards the total of the person who recruited them.

A challenge I ran into was being able to know which invite link a new member used when they joined the server since this information can't be retrieved through Discord's API. To overcome this, I used the Key-Value API and added an event listener for when a new invite link is created in the server. This allowed the bot to create a new Key-Value pair, with the key as the server invite code, and the value as the number of times the invite has been used. Each time the new member event would be triggered, the bot would make a call to the Discord API to retrieve all existing server invites. It would then loop through the array returned from the API and fetch the number of previous uses for the invite code from the Key-Value store, and compare that value with the one returned from the API; if the number of previous uses + 1 is equal to the current number of uses for the invite, it means the invite was the one that was used by the new member.

project imageproject imageproject imageproject imageproject imageproject image

Thanks for checking out my case study.

Here are some of my other projects & work.

If you like what you see and think I'd be a good fit for your next project, I'd love to chat!