Connecting your server to Discord builds community and aids administration.
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')Syncing Discord roles (Admin, Police, VIP) to FiveM permissions (aces).
server.cfg.roles = {
['112233445566778899'] = 'group.admin',
['998877665544332211'] = 'group.vip',
}Send server logs to Discord channels.
Warning: Discord has strict rate limits (30 requests/sec globally, but 5/sec per channel is safe).
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' })
endRestrict access to Discord members only.
GetPlayerIdentifiers(source) to find discord:12345....-- 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)