Building with the API

Build a Discord Bot That Shows Live FiveM Server Status

A walkthrough for wiring the CFXR API into a Discord bot that posts live player counts and status.

The short answer

A status bot needs two things: your server's join code, and a call to CFXR's public resolve endpoint — GET /api/resolve/{code}, for example curl https://cfxr.cc/api/resolve/b578o4. A slash command or scheduled job fetches that endpoint, reads the name, player count and status out of the response, and formats them into a Discord embed.

What the bot needs

Beyond the join code itself, the only other input is the endpoint URL — the resolver doesn't require authentication for basic use, so a bot can start making requests against /api/resolve/{code} immediately. The full reference for the response shape, including which fields you can request, lives at the in-app API reference and as a machine-readable spec at /api/openapi.json, which is worth feeding into whatever HTTP client or codegen tool your bot framework uses.

The high-level flow

Most implementations follow the same shape regardless of which Discord library you use. A slash command (something like /status) or a scheduled job running every minute or so calls the resolve endpoint for your stored join code, checks whether the response indicates the server is online, and builds an embed with the server's name, current player count and a timestamp. On a scheduled job, you'd typically edit a single pinned message rather than posting a new one each time, so the channel doesn't fill with repeated status updates.

If you only need the name and player count rather than the full payload, the resolve endpoint accepts a fields query parameter to trim the response down, which keeps your bot's parsing logic simpler and the request itself smaller.

Respecting rate limits

Every response includes X-RateLimit-* headers describing your remaining quota, and if you exceed it you'll get back a 429 response with a Retry-After header telling you how long to wait. A bot polling on a schedule should read these headers rather than guessing at a safe interval — back off when you're close to the limit instead of finding out via a wave of 429s. If your bot serves more than a handful of servers or polls more frequently than the unauthenticated limit comfortably allows, an API key from /account/api-keys raises your rate limit and is worth setting up before you hit that ceiling, not after.

Send the key as a bearer token — Authorization: Bearer cfxr_xxxxxxxx — on every request, and keep it in your bot's environment configuration rather than committed alongside the code.

Upgrading to live updates

Polling on an interval is the simplest approach and is fine for most Discord bots, but it means status is only ever as fresh as your last poll and it spends rate-limit budget on requests that often return unchanged data. If you want the embed to update the moment a player count actually changes, CFXR also exposes a Server-Sent Events stream at /api/servers/{code}/live that pushes updates as they happen instead of making you ask repeatedly. Swapping a polling loop for a long-lived connection to that stream is a natural next step once the basic polling version of the bot is working end to end.

Related guides