Introduction
Colourbot was my first major project, actively developed for over two years. It was a Discord bot that enabled interactions with colours within the chat. I noticed that many users were screenshotting colours, sharing hex and RGB codes, and discussing palettes without the ability to visualise them. This is where Colourbot came in. By the time it peaked, Colourbot had been added to over 5,000 servers with a total of 500,000 members.
How Colourbot Was Built
Colourbot was written in Python using the Discord.py library, with a MySQL database on the backend to store user and server data. The website was built using PHP, HTML, CSS, and JavaScript.
Building a Seamless Licensing System
I always wanted to monetise Colourbot, so I decided to build my own licensing system using PayPal’s API. The system worked as follows:
- Users would use the Paypal API to purchase a license key from the website.
- PHP backend would use a custom key generation algorithm I wrote to generate a unique key.
- The algorithm would store information about the user, time, etc. in a hashed format.
- The key would be stored in the database.
- The key would be sent to the user via email.
- The user would then input the key into the bot, which would verify it with the database.
- If the key was valid, the bot would unlock premium features.
- The key would then be marked as used in the database.
This system worked incredibly effectively and provided an excellent learning experience in handling financial transactions, security, and database management.
The bot would send a message informing the user that they needed to purchase a license to use certain commands.
It would also send a live-updating message to the user when they had successfully activated a license.
Minimising bot downtime
The bot grew in popularilty quite quickly towards the end of 2020 even ranking top 10 on some bot websites. This put immense strain on the VPS it was hosted on and since I was on a very tight budget I had to come up with solutions that did not involve upgrading the VPS.
This is where I began to learn about sharding. In essence, sharding is the process of splitting up a bot into multiple instances that can run on different servers. This allowed me to distribute the load across multiple servers and keep the bot online even when certain zones were under particular strain. Having to handle database synchronisation and message passing between shards was very challenging - especially for a 17 year old with their A-levels coming up!
Examples of Colourbot in Action
The bot could blacklist channels so that it would not respond to commands in those channels.
Automatic detection of colours in messages with a live preview.
Gradient generation (Premium feature).
Colour name lookup using colours API.
Generating colour palettes.
Server settings and user settings.
The /shop endpoint on the website. (I had to dig through the archives to find this one!)