Top Chatter - a discord bot
- 4 Devlogs
- 7 Total hours
A discord bot that shows who has the most messages in a discord server
A discord bot that shows who has the most messages in a discord server
I finally moved all the time-based commands like /last-hour, /last-day, and /last-week to pull directly from the SQLite database instead of using the discord api to scrape thousands of messages. This makes the bot way faster and more reliable since it doesn’t have to calculate everything on the fly anymore. I was also able to add a brand new /last-month command.
I also worked on polishing the experience and making the initial message scanning easier. Sometimes server owners have their DMs closed, so the bot would fail to send the automatic setup button when it joined. To fix this, I added a manual /setup command. Now, if the bot misses the DM, someone can just run the command themselves to start the background scan. It makes the onboarding process a lot smoother and prevents the bot from getting stuck.
I finally got the bot hosted on a server! I moved it off my local computer and onto Hack Club Nest. I used PM2 to keep it running in the background permanently.
This will probably be my final devlog as to be honest I’ve accomplished everything I wanted to with this bot and I feel very good about it because it has 1 core purpose and it does that purpose very well. I want to move on to other projects so I will probably ship it.
If you want to try the bot out for yourself and add it to your server you can use this link:
I’ve made a lot of progress on the bot and changed how it tracks server activity and message data!
I moved the bot away from using the Discord API to scrape the data because that took way too long and wasn’t efficient. For the all-time command, it now dms the owner of the server to ask them for permission to get the data from the server (using discord api) then it adds that data into an sqlite database.
I set up an automatic table layout that tracks users by their permanent Discord user_id rather than their display name. This completely prevents leaderboard tracking bugs if a user decides to change their server nickname.
Next, I added into the real-time event system. The bot now logs and adds to message counts instantly as they are sent in real-time, meaning we don’t have to wait for slow api scrapes anymore. I also updated the /all-time command to pull directly from this local database instantly. I might update the other commands but for now its just using the discord api.
To make the system scaleable, I added a full-server data sync. When the bot joins a new server, it sends a DM to the owner with a green setup button. Clicking it runs a background scan across all text channels to build the database. I ran into two big bugs while setting this up:
Lastly, I added stats.db to the .gitignore file so it isn’t committed to github.
Next steps:
I might just ship it with these core features (definitely not for a sticker or anything 😂 🙏)
I will try and continue to work on it and somehow find away to integrate VC support. This would need me to:
I might also in the future update the leaderboard messages from the commands to have embeds so it looks cleaner and more professional using discord embeds.
Thank you for reading my 3rd devlog!
Edit:
OH YEAH I just remembered I’m gonna host it on a server so I don’t need it running locally all the time.
I finally finished adding the core message tracking features! I made some slash commands that let users track the top chatters over different time periods.
I created the /last-hour, /last-day, and /last-week commands. I used Python’s datetime module to calculate an exact time period and then look back through the channel history to count up the messages. I also added a defer() function to each command so the bot can safely process the data without timing out or breaking.
When implementing the /all-time command, I realized that downloading every single message ever sent could easily crash the bot. To fix this, I built a custom warning button using. Now, the bot sends a warning message with a Confirm & Run button, and it will only start the process if a user explicitly clicks it.
I ran into a frustrating issue with Git where my .env file kept getting included in my commits even though it was listed in my .gitignore. I learned that because Git tracked the file early on, it was ignoring the ignore rules. I used the terminal to untrack it and was able to keep it ignored.
Next I will be working on moving the bot away from API scraping and into local storage. I will be working on the following thiings:
Thank you for reading my 2nd devlog!
I was able to get the discord bot online and running! Set up the basic framework using Python and the discord.py library. I got it connected to discord and online and made it print a confirmation message to terminal when it’s online.
I also used canva to make some custom art for the discord profile picture and the banner to make it look more professional and give it some personality.
I ran into some SSL certificate verification errors when running the bot which was annoying to debug and fix. I used Github Copilot to help me debug and solve the issues and I figured out that I had to point Python to the certifi certificate bundle. Once I restarted and ran it again, the bot connected successfully.
Next I will be working on the core features of the bot which are:
These are the core basic features I plan to implement, I have other ideas like commands to see who spent time in vc (voice chat) in the same pattern as the messages commands and more things like that.
Thank you for reading my 1st devlog!