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.
Build it
Create a Discord application
Go to https://discord.com/developers/applications → New Application. Name it after your server.
Go to Rich Presence → Art Assets. Upload images (512x512 minimum):
server_logo- your server's logoserver_large- a hero image or screenshot
Copy your Client ID (18-digit number) from the General Information page.
Set up the resource
resources/qu_discord_rpc/
fxmanifest.lua
client.lua
fx_version 'cerulean'
game 'gta5'
client_script 'client.lua'
Set the Discord app ID and presence
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
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:
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.
- Common failures
The remainder of Add Discord rich presence to your server is available to FiveM School members.