Learn to build a Discord bot using Discord.py and host it on Replit (for free)

2022/09/23

Tags: discord python

While there are sites like splatoon3.ink with which I can check the cuurent and future stage information in Splatoon, I still want a tool at hand that allows me to check the stage information conveniently and to share it with my Splat-friends. A Discord Bot maybe? So I learnt and built a bot myself for my Splatoon 3 server!.

Tools

  1. The language I used was Python, and the package I used to build and communicate with the bot was Discord.py. Other packages used including dotenv, requests, and pillow.

  2. I’m completely new to developing Discord bots. The Discord developer documentation and the Discord.py documentation were very useful when I started the project.

  3. The API I used to get Splatoon 3 stage infomation was Spla3 API. Thanks to the author!

  4. I put the bot on Replit.com. To avoid their restriction and make the bot online 24/7, I followed the last part of this tutorial. In a word, I created a web server in my repl, and then used a third party service uptimerobot to “wake up” the bot every 5 mins. See [UPDATE 2022/09/25] at the bottom.

Caveats

  1. On Replit.com, I cannot have a .env file now. I have to use the so-called Secrets to store my bot token.

  2. The bot on Replit.com kept giving me 429 error after running for a certain time. It is probably because [Replit.com uses shared IP addresses] (https://stackoverflow.com/questions/67395660/replit-discord-bot-blocked-from-discord). And to deal with that issue, we can simply use the command kill 1 in the shell (see this answer).

Finally, the Github repo for my bot is here. Stay safe and enjoy coding!

Screenshots

Screenshot1

Screenshot2

====================

[UPDATE 2022/09/25] Due to the 429 error issue, I gave up hosting my bot on Replit. Now I am using Heroku to host the bot. The tutorial I followed was this one. However, the bad news is that Heroku is going to cancel all the free dyno hours very soon (by the end of 2022).



comments powered by Disqus