Skip to main content
This tutorial walks through a complete VALORANT Discord bot built on Riot’s official API, designed so Riot can approve it for a production key. By the end you’ll have these slash commands: The finished code is in examples/discord-bot on GitHub. Clone it to skip ahead.
Why /link instead of /stats PlayerName#TAG? Riot requires VALORANT apps to get each player’s opt-in through Riot Sign On (RSO) before showing their match history. A bot that looks up any Riot ID won’t get a production key. This bot only shows match data for players who signed in with /link. Leaderboards and server status don’t need opt-in. Details are in Getting a production key.

Prerequisites

  • Python 3.10 or newer
  • A Riot API key from the Riot Developer Portal. A development key is enough to start the bot, but most VALORANT endpoints return 403 until you have a production key.
  • A Discord application with a bot user. Create one in the Discord Developer Portal, copy the bot token, and invite the bot to your server with the bot and applications.commands scopes.
  • Later: RSO client credentials from Riot, which are issued after your production key is approved. Until then /link is disabled, and everything else runs normally.

Project setup

1

Get the code

The Python files, each with one job:
  • riot.py: Riot API access with caching
  • rso.py: the “Sign in with Riot” flow and linked-account storage
  • bot.py: Discord slash commands
  • test_example.py: offline tests for the Riot and RSO logic
2

Install dependencies

This installs valaw, discord.py, and python-dotenv.
3

Add your tokens

Then fill in at least these:
.env
DEV_GUILD_ID is optional. When it’s set, slash commands sync to that one server instantly instead of waiting for global commands to appear.
Never commit .env. Anyone with your Riot key can use up your rate limit or get your key revoked.
4

Run it

Type / in your server and the commands appear.

How it works

One shared client

Create one valaw.Client for the whole bot and reuse it. It holds an aiohttp session, so creating one per command wastes connections. RiotService in riot.py owns the client, and the bot closes it on shutdown:
bot.py
Slash commands don’t need the privileged message content intent, so Intents.default() is enough.

Account linking with RSO

/link sends the user a one-time “Sign in with Riot” button. valaw’s create_RSO_link builds the URL. The random state value ties the sign-in to the Discord user and protects against CSRF:
rso.py
After the player signs in, Riot redirects them to your callback URL. A small aiohttp web server, started with the bot, trades the code for an access token. It then asks Riot who signed in using GET_getByAccessToken:
rso.py
The callback doesn’t save anything yet. It shows a confirmation page: “Link Riot account Name#TAG to Discord user @alice?” The link is saved only when the person who signed in clicks Link my account. Without this step, someone could forward their /link URL to a friend, and the friend’s Riot sign-in would silently attach to the sender’s Discord account. The page shows the Discord username, not the display name, because anyone can copy a display name. Two more details keep linking safe:
  • /unlink cancels unfinished sign-ins. revoke() bumps a per-user counter, and the callback and confirmation both check it after waiting on Riot. A sign-in that was in progress can’t re-link an account the user just removed.
  • Failed sign-ins are logged with the cause, but never the authorization code or access token. The player sees a generic error page.
Links are saved to links.json. That’s fine for one bot process. Move to SQLite or Postgres when you outgrow it. To turn it on, add your RSO credentials to .env:
.env
The redirect URI must exactly match the one registered with Riot and must be reachable over HTTPS. Put the bot’s web server behind a reverse proxy such as Caddy or nginx, or a tunnel such as Cloudflare Tunnel.

Caching

Most VALORANT data barely changes. Game content changes once per patch, a finished match never changes, and leaderboards update every few minutes. Caching keeps the bot fast and well under Riot’s rate limits:
riot.py
TTLCache is a small in-memory dictionary with expiry times. If you run more than one bot process, swap it for Redis.

Rate-limit handling

The bot doesn’t need any rate-limit code of its own. valaw.Client waits to stay under your key’s limits and retries 429 Too Many Requests responses, so the bot just calls it:
riot.py
If Riot is still limiting the bot after valaw’s retries, the command tells the user to try again in a minute. See Rate limits for how it works.

Finding the right region

Account calls go to a cluster (americas, europe, asia), but match data lives on the player’s region (na, eu, ap, kr, …). Don’t make users type their region. Ask Riot for the player’s active shard:
riot.py

Turning IDs into names

Match data refers to maps by asset path and agents by UUID. Look them up in the cached content response with valaw’s content lookups:
riot.py
The lookups ignore case, since the content and match endpoints don’t use the same casing for IDs. The /lastmatch command gets its stats from player_summary, so the bot doesn’t compute ACS or headshot percentage itself.

The /lastmatch command

/lastmatch checks for a linked account before calling Riot. It then defers, because Discord only waits 3 seconds for a response and a cold lookup can take longer:
bot.py

One error handler for every command

Commands don’t contain try/except. Errors bubble up to one tree-wide handler, which turns Riot’s status codes into messages a user can act on:
riot.py

Before you apply for a production key

Riot reviews your bot before it gets a production key. This example already covers the basics: RSO opt-in, /unlink, anonymous leaderboard entries stay anonymous, and the legal notice in /about. You’ll also need a landing page with screenshots of each command. Change BOT_NAME in bot.py so the legal notice uses your bot’s name. See the Discord bot checklist.

Ideas for next steps

  • Match tracking. Poll linked players’ match lists every few minutes and post new results to a channel.
  • Persistent cache. Move TTLCache to Redis so restarts don’t start from zero.
  • Deploy it. Any always-on host with HTTPS works for the RSO callback, such as a small VPS behind Caddy, Railway, or Fly.io.

Full source on GitHub

Clone the complete bot from examples/discord-bot.