Discord Integration
Connecting your server to Discord builds community and aids administration.
Rich Presence (RPC)
Show “Playing on My Server” in players’ Discord status.
In your server.cfg or a script:
-- Set the App ID from Discord Developer Portal
SetDiscordAppId('123456789012345678')
-- Set assets (images uploaded to Developer Portal)
SetDiscordRichPresenceAsset('logo_large')
SetDiscordRichPresenceAssetText('Best RP Server')
SetDiscordRichPresenceAssetSmall('logo_small')
SetDiscordRichPresenceAssetSmallText('Join now!')
-- Buttons (connect link)
SetDiscordRichPresenceAction(0, 'Connect', 'fivem://connect/cfx.re/join/yourcode')
SetDiscordRichPresenceAction(1, 'Discord', 'https://discord.gg/yourinvite')Role Sync (Permissions)
Syncing Discord roles (Admin, Police, VIP) to FiveM permissions (aces).
Popular Resources
- Badger_Discord_API: A library many other scripts use.
- DiscordAcePerms: Directly maps roles to aces in
server.cfg.
Setup Steps
- Developer Portal: Create an app, create a Bot User.
- Intents: Enable Server Members Intent in the “Bot” tab (crucial for reading roles).
- Config:
roles = { ['112233445566778899'] = 'group.admin', ['998877665544332211'] = 'group.vip', }
Webhooks (Logging)
Send server logs to Discord channels.
Warning: Discord has strict rate limits (30 requests/sec globally, but 5/sec per channel is safe).
- Do: Batch logs or use a queue.
- Don’t: Send a webhook every time a player takes a step.
function SendWebhook(message)
PerformHttpRequest('https://discord.com/api/webhooks/YOUR_WEBHOOK', function(err, text, headers) end, 'POST', json.encode({
username = "Server Logger",
embeds = {{
title = "Log Entry",
description = message,
color = 16711680
}}
}), { ['Content-Type'] = 'application/json' })
endDiscord Auth (Allowlist)
Restrict access to Discord members only.
- Use
GetPlayerIdentifiers(source)to finddiscord:12345.... - If no discord ID is found, the player doesn’t have Discord open.
- Use a bot API to check if that ID is in your guild.
-- Simple check if Discord is open
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local player = source
local discordId = nil
for _, id in ipairs(GetPlayerIdentifiers(player)) do
if string.match(id, "discord:") then
discordId = id
break
end
end
if not discordId then
deferrals.done("Please open Discord to join this server.")
else
deferrals.done()
end
end)Last updated on