We made a Bot Used by 180k Students for 3 Centuries’ Worth of Time

TLDR: I made an open-source Discord bot that displays real-time rankings 🧗of the time students have truly spent in our StudyStream Discord study server, for free.


The exponential growth of the Discord server since COVID


The beautiful frontend of the bot coded by Cole Killian

The Non-Technical Backstory

A person usually focuses much better if watched by others.

— Zack Light

I coined this theory of mine the prison effect of studying 🔒. Based on it, I decided to search for online study rooms when my university shut down its libraries due to COVID around March 2020. (My backup option was to go back to as a StudyTuber.)

Luckily, I found a community on Discord with about 1k students 🤩. I became hooked by how the leaderboard inside the server has gamified studying 🎮.

Games are the only force in the known universe that can get people to take actions against their self-interest, in a predictable way, without using force.”

— Gabe Zichermann


The leaderboard for the top people in April 2020 ( I was the 8th)

The leaderboard motivated me and my peers to study non-stop, seriously. Since there are many types of rankings like all-time, monthly, weekly, daily, hours, etc., and streaks, it’s easy to set a goal suitable for oneself. Personally, I was mostly focused on the longer-term: monthly and all-time. I have strived to be within the monthly top 10 and all-time top 3.


Moreover, it’s extremely motivating to see friends work so hard to try to catch up with you ⚔️. Admittedly though, I do have friends addicted to online studying so much that they sleep inhumanly little every day 🤯…

My semester went so well that I secured my full-time job before my last winter vacation. To give back to this symbiotic community 👼, I decided to spend my winter vacation coding an open-source Discord bot capable of displaying real-time rankings of students’ study time on the server, for free.

The Technical Process

I initially did an elaborate SQL database design.


Very elaborate just like the SQL design homework I have done

In reflection, the final database we have is way simpler. For example, to store channel names and channel IDs, I ended up using a simple HJSON file that allows our non-technical mods to edit easily. Storing some rarely-changed data like this in SQL is simply counter-productive for us.

The biggest challenge, and the reason why no other real-time time-ranking bot exists (AFAIK) is that we have too many students to sort every student’s study time for every display of the leaderboard 😰. One way is to sort all the 170k students and refresh the leaderboard periodically, but it was hardly scalable and required a waiting period horrible for UX.


So I created handlers that log the times when students join study rooms and, when they leave, add the amount of elapsed time to our database. I used a skip-list for real-time ranking for logarithmically complex operations. (It’s a marvelous albeit so-called “advanced” probabilistic data structure.)


Based on this idea, I started to implement, test, and debug the whole program. The code is well-documented here 😇. (Many of our and all of my projects are open-source.) I used Redis sorted sets to avoid concurrency issues. The bot itself interacts with the users directly. It’s capable of detecting even seconds of time changes🙃.



This has been an absolutely thrilling journey. Since my bots went online, the time students has spent in our Discord server has exceeded 3 centuries 🤩.


Even though I took 7 classes for 24 credits in my final undergrad semester, I spent countless tireless nights resolving issues likes the instability of Discord API. After all, how could I fall asleep when hundreds of thousands of students are agonizing over my buggy bot? (You’re welcome 😘) I also appreciate the tremendous help from the mods!

I hope you enjoyed the secrets behind this crazily successful bot. If you want to hear more about my ventures, please connect with me in any way convenient — follow me on Medium, sign up for my newsletter here, or even schedule a chat with me for any questions👋 at ZackLight.com Cheers 🤗