My thoughts on developing ValFriends, a discord bot for Valorant [ python app ] Aug 10, 2023 Intro ValFriends is a Discord bot for game Valorant, aims for helping you play with your friends happily. Just need a simple command to register your valorant account into the user list. You can easily view stats and rank info for everyone in the discord server. It is developed by me and my friends. Basic Usage Step 1: Bind a Valorant account to a Discord account Originally, the user list is empty. You can bind your valorant account with your discord account to the user list by executing: /bind_val <valorant_name>#<valorant_tag> Or you can help your friends bind their accounts: /bind_val <friend_valorant_name>#<friend_valorant_tag> <friend_discord_name> Step 2: Play with all commands! To show your stats, execute: /stats To show your friend’s stats, execute: /stats <friend_discord_name> When you execute commands that require discord id as input, it will autocomplete based on your input. To print users in sorted order of current rank, use /crank. To print users in sorted order of lifetime highest rank, use /hrank. To print stats for all users, use /all_stats Note that the profile for every user in the user list is cached in a sqlite database. When you execute stats, the bot actually returns the data in cache. The bot generates a timestamp for every profile. The profile will expire after some time and the bot will fetched the up-to-date data from the API. You can also force the cache to update by using /expire or /all_expire. All Commands Execute /help to get the help message for all supported commands: all_stats - Get all users' stats. stats - Get user's stats. crank - Print users who have highest current rank in the user list. all_expire - Force expire all user's stats. hrank - Print users who have highest lifetime rank in the user list. expire - Force expire user's stats. help - Print information for commands review - Give a fair and objective review of a game. bind_val - Bind a Valorant user to a discord user and add it to the user list. all_delete - Delete all users from the user list of this server (admin only). hello - Responds with 'Hello World'. Used for testing. You can also execute help <command> to view the details of the command parameters. My Thoughts on Developing Don’t Use discord.py To develop a discord bot, you need to choose a discord API wrapper, like discord.py, pycord and disnake, where last two are both forks of discord.py. When developing ValFriends, I first tried discord.py because I thought it is the oldest and there should be a lot of docs or tutorials for reference. However it proves that I’m wrong. For example, it is painful to update commands to slash commands. Say you implement a command called stats, everything works and you are happy. Then you wanted it to be a slash command so that it can have many nice features like command autocompletion, parameter autocompletion, options list, inline docs, etc. You googled and find a good tutorial on stackoverflow how-do-i-make-a-working-slash-command-in-discord-py. “Hey this is so easy,” you thought. You start coding, update your old function stats, and go to your server trying to test your bot. However, you suddenly found that since the new command name is also stats and the cache of old command is not cleared, you can’t test your new slash command! And there is no easy way to clear the cache, so the solution is to change your new command name. Stupid solution… Ok, it makes sense. People have reasons when they fork discord.py. Therefore I switch to disnake, it’s much better. For example, it would automatically clear the command cache so the above problem doesn’t exist. If you want to have a easier life, don’t use discord.py. Riot’s API Riot’s Valorant API is so bad. The API design sucks. Also, it doesn’t even support personal key applications, which means if your want to develop an app that use the Valorant API, you need to apply for a production key and the process is much harder than the one for a personal key, because your app should be a “larger-size, professional project”. Note that Riot’s Leauge of Legends API does allow personal key… Valorant team is so lazy! Therefore, we really need a third-party API. I tried several and finally decided to use Henrik-3’s API. The experience is good, though we found that some parts of the API doc don’t match the actual json format when we use datamodel-codegen to generate the pydantic models. Please enable JavaScript to view the comments powered by Disqus.