Inspiration
As a recent graduate in web development and someone who loves perusing various Liquipedia wikis, I wanted to experiment with the Liquipedia API and trying something completely new. Wanting to branch out from full web applications, I dabbled with learning and trying to create a Discord bot but haven't successfully deployed one.
I was re-inspired to build one after checking out Marvin's workshop at the Liquid Hackathon on how to create a simple Discord bot that queried the Liquipedia API and gave the user relevant information about players.
What it does
The bot MCY-bot can be utilized using slash commands from Discord. Its main purpose is to give the inquirer information about a player that they specify by correctly inputting the correct wiki and player in the required fields. What the bot returns is a short biography of the player where the relevant information is filled out by grabbing the appropriate key-values from the JSON object representing the player. Their socials are also listed ranging from their YouTube to their Weibo accounts, if available.
There is some user validation when the user inputs the incorrect wiki or player name, or if the player doesn't exist.
How I built it
Some of the code was borrowed or refactored from Marvin's tutorial on how to deploy a Discord bot, mainly the config.py which housed the function on grabbing relevant environment variables from the .env.dev file. There are only four files in the application:
config.py- Contains a function to extrapolate environment variables from the.env.devfile which contains the BOT_TOKEN, GUILD_ID, and API_KEYbot.py- Instantiates a bot and runs it. Includes decorators that allows the bot to monitor for any messages and slash commands such as/MCY-getplayerand respond appropriately.liquipediaAPI.py- ContainsgetPlayerandprintDatafunctions.getPlayerfetches from the liquipedia API and returns either the player's JSON content, an empty array if there are no results, or a string'Invalid Wiki'if the wiki doesn't exist.printDataformats the JSON content to be displayed appropriately when the bot sends the results in the Discord channel.dataCorrection.py- ContainscorrectedDatafunction which checks the JSON whether key-values exist, and creates the key if it doesn't exist or its value is empty (""), with the value being a string of'<key> unavailable'. For example, if the player did not belong to a teamdata['team'] == "", the key is reassigned a new value of'no team (free agent)'so that it would display as such in the player's mini-biography MCY-bot sends.
Challenges I ran into
One of the biggest challenges that I ran into was the immensity of the amount of wikis Liquipedia contains. Some of these wikis I never even knew existed! As a consequence, there are inconsistencies when accessing the keys from JSONs of different wikis. For example, a Starcraft player would not specialize in any Dota heroes or League of Legends champions, but rather, they usually specialize in a race. correctedData is supposed to help alleviate some of these issues, but considering the scope of the project, it was better to slightly satisfy everyone utilizing all wikis than having a perfect response to just two or three wikis.
Another challenge was not specifically code related, but deploying an application to the cloud. Many errors that I got was version incompatibility between python packages or the python version itself. The process of creating a manifest.yml file and creating dependencies to be utilized by the cloud is something I still don't fully understand, but was definitely an experience full of googling and troubleshooting.
Accomplishments that I'm proud of
I deployed a discord bot! And it's not local to my machine! And it works (kind of)! I think having a bot that is able to query the liquipedia API would be very useful in a community, such as if they want to look up certain stats for a player. For example, their most recent tournament placings or what other wikis they're on.
What I learned
Writing a simple bot is not too bad, especially with guidance from the workshop! I wish I could utilize JSX so that I can more easily program conditionals in case there was data missing, so that I could change the player's biography dynamically. There might be a library or a feature of python I haven't found yet that does this.
The Discord documentation for developing applications is not super newbie friendly, but is definitely in-depth and just requires a bit of googling to find answers to reaching a certain endpoint. For example, the application ID refers to the ID of the application that houses the bot we create, not an ID for any general application (so obvious now..).
What's next for MCY-Liquipedia-Bot
Regurgitation of the README.md from the MCY-bot repo:
- The bot is optimized mostly for League of Legends, Dota2, and Brood War queries, so querying other wikis will likely make strange contextual mistakes.
- Make it easier for the user to search for players. It requires the user to be very exact with the player's liquipedia page name.
- Add randomizer
- Remove embeds as the bot response can be very bulky
- Add a cooldown to reduce frequency of API querying
Log in or sign up for Devpost to join the conversation.