This is a Discord bot that allows users to catch, collect, and trade Pokemon. This code is in production, meaning it is live 24/7 serving real users, and I regularly update it with bug fixes and features using Git. The users interact with the application through the Discord messaging app, which I accomplish using the discord.py API library. User data is stored in a remote database through MongoDB. I am hosting the application itself on my Raspberry Pi, which is a small Linux computer that I SSH into when I need to push an update to the live branch.
Viewing your pokemon with /pokedex.
The bot is added to a Discord server and users can interact with it using application commands. For example, a user might view their Pokedex by typing /pokedex. They might trade their Squirtle for another user’s Bulbasaur by typing /trade @other_user squirtle bulbasaur. The Discord API provides certain front-end view components as classes that I can use to construct the widgets that compose the app, such as the ones pictured below.
Trading pokemon with another user.
Evolving your pokemon with /evolve {pokemon}.
Users can use /roll to get a group of three Pokemon. The rolls reset every day at noon and midnight UTC. There is a 1% chance that any Pokemon rolled can be a shiny Pokemon, meaning it has a rare color variation.
Every message sent in the server has a 1% chance to spawn a random Pokemon that multiple users can claim (within a time frame). This Pokemon also has a 1% chance to be a shiny Pokemon.
Users can use /search to lookup a Pokemon and see how many of this Pokemon they own. They can also click a button to toggle between the normal and shiny sprite in the display.
Users can use /pokedex to view a paginated list of their collected Pokemon. They can set the thumbnail of the Pokemon displayed in their Pokedex using /favorite. Users can view another person’s Pokedex by passing their name as an argument: /pokedex @user.
Users can set a list of 5 Pokemon to display in a special view. Similar to Pokedex, you can view another user’s battle party by passing their name as an argument: /battleparty @user You can set or update the party using /setparty, which opens a modal that allows you to enter your Pokemon.
Users can use /evolve {pokemon} to evolve one of their Pokemon. Evolving consumes Bluk Berries, which have a 2% chance of being awarded to the author of any given message in the server. There is some interesting stuff behind the scenes when it comes to detecting and evolving Pokemon that have multiple possible “next” evolutions, such as Eevee which has eight possible secondary forms.
Users can trade Pokemon with each other using /trade @user {my_pokemon} {their_pokemon}. One user initiates the request, and the other user either accepts it or declines it.
The discord.py module is basically a component library integrated with the Discord API, learning it entails a lot of reading the docs and watching tutorials. It is essentially an asynchronous backend in the same way that Flask or Django is, except instead of handling websites it handles your Discord bot. The library provides an architectural building block called a Cog. This is a class that can be added to your main bot loop at runtime, the main benefit being that it allows you to separate distinct functionality into different files. I use Cogs in exactly that way, encapsulating functionality for things like evolving, trading, and viewing pokemon into separate Cogs.
The discord.py module also provides classes representing different widgets, with limited customization options exposed like buttons, images, headers and footers, basic forms, etc. These are the building blocks that I use to create all the UI widgets that exist in the application.
The bot itself is written in Python with the Discord.py module as the framework used for interacting with Discord itself. The database uses MongoDB Atlas which I connect to using pymongo. Finally, the application is hosted on a personal Raspberry Pi, which is a very small linux-based computer. To update the app, I can simply push my changes to GitHub, then ssh into the Raspberry Pi, pull those changes, and restart the bot.
I got approval from a handful of friends to invite this bot to their Discord servers. Most of those servers use the bot fairly regularly, and I got a lot of feedback, bug reports, and feature requests. In a few servers, the users were rolling new Pokemon during every reset period, and this carried on for months. Finally, nearly 6 months later, the interest has died down, mainly because they’ve collected all the Pokemon they were interested in. I suppose the next feature to brainstorm is one that might renew user interest, but for now I’m very happy with how this project turned out and the success it had.