Skip to main content
TRACK B·PRODUCTION ENGINEERING·Verified June 2026 · Lua 5.4 · ox_lib 3.x
Learning with an AI assistant?
Copies this lesson plus 2026 ground rules (no lua54 'yes', Cfx.re Portal, correct callback signatures) as a ready-to-paste mentor prompt.

Add Discord rich presence to your server

Discord rich presence shows your server's name, player count, and a custom image right in Discord when someone is playing on your server. It's free advertising - every player's friends see it. This lesson sets up the full integration from Discord developer portal to Lua script.

You'll build
A Discord rich presence integration showing player count, server name, and a custom image in players' Discord profiles.
Time
~25 minutes
You need
A Discord application at discord.com/developers, a FiveM server with OneSync, and basic Lua knowledge.
You'll learn
Creating a Discord application, uploading rich presence art, connecting FiveM to Discord via SetDiscordRichPresence, and displaying live player counts and server info.
BEFORE YOU START

Build it

Create a Discord application

You have a Client ID and uploaded art assets.

Go to https://discord.com/developers/applications → New Application. Name it after your server.

Go to Rich PresenceArt Assets. Upload images (512x512 minimum):

  • server_logo - your server's logo
  • server_large - a hero image or screenshot

Copy your Client ID (18-digit number) from the General Information page.

Set up the resource

A resource that talks to Discord.
code
resources/qu_discord_rpc/
fxmanifest.lua
client.lua
code
fx_version 'cerulean'
game 'gta5'
client_script 'client.lua'

Set the Discord app ID and presence

Discord shows the small icon and server name.
code
local appId = 'YOUR_DISCORD_CLIENT_ID'  -- 18-digit number

Citizen.CreateThread(function()
-- Set the Discord application ID once
SetDiscordAppId(appId)

while true do
    -- Update presence every 15 seconds
    SetRichPresence('Playing on My Cool Server')

    -- Small image = your logo
    SetDiscordRichPresenceAssetSmall('server_logo')
    SetDiscordRichPresenceAssetSmallText('My Cool Server')

    Citizen.Wait(15000)
end
end)

Add live player count and join button

Discord shows how many players are online.
code
local appId = 'YOUR_DISCORD_CLIENT_ID'

local playerCount = 0

-- The server pushes the authoritative count to us
RegisterNetEvent('qu_discord:playerCount', function(count)
playerCount = count
end)

CreateThread(function()
SetDiscordAppId(appId)

while true do
    -- Ask the server for the current count
    TriggerServerEvent('qu_discord:getPlayerCount')

    SetRichPresence('Players online: ' .. playerCount)

    -- Large image = hero/screenshot
    SetDiscordRichPresenceAsset('server_large')
    SetDiscordRichPresenceAssetText('Join now at cfx.re/join/xxxxx')

    -- Add a Join button
    SetDiscordRichPresenceAction(0, 'Join', 'fivem://connect/localhost:30120')
    SetDiscordRichPresenceAction(1, 'Discord', 'https://discord.gg/yourserver')

    Wait(15000)
end
end)

The count must come from the server. GetNumPlayerIndices() is a client native that only sees locally-scoped players, so it is never the real total. Count players server-side with #GetPlayers() and push that number back to the client:

code
RegisterNetEvent('qu_discord:getPlayerCount', function()
local src = source
-- #GetPlayers() is the server-authoritative count of everyone online
TriggerClientEvent('qu_discord:playerCount', src, #GetPlayers())
end)

Add server_script 'server.lua' to your fxmanifest.lua so the server file loads.

Keep reading the full lesson

Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.

Still ahead in this lesson
  • Common failures

The remainder of Add Discord rich presence to your server is available to FiveM School members.