Table of Contents
- Getting Started
- Player Data
- Role Checking
- Role Management
- Guild Data
- Permission System
- Webhooks
- Cache Management
- Utilities
- Server Utilities
- Emergency Calls
- Tags System
- Activity System
Getting Started
Basic Usage
All exports are called viaexports.LonexDiscordAPI:ExportName(...).
Important Notes
- All role functions use Role IDs only (not role names)
- To get a Role ID: Enable Developer Mode in Discord → Right-click role → Copy Role ID
- Most functions return
nilif the player doesn’t have Discord linked to FiveM - Functions with “ById” suffix accept a Discord ID instead of player source
Player Data
GetDiscordId
Get a player’s Discord ID from their FiveM source.GetDiscordUser
Get full Discord user data.GetDiscordUserById
Get user data by Discord ID (doesn’t require player to be online).GetDiscordMember
Get full guild member data (includes server-specific info).GetDiscordMemberById
Get member data by Discord ID.GetDiscordName
Get display name (nickname → global name → username).GetDiscordNickname
Get server nickname only.GetDiscordUsername
Get Discord username only.GetDiscordAvatar
Get avatar URL (uses server avatar if set, falls back to user avatar).GetDiscordAvatarById
Get avatar URL by Discord ID.IsInDiscordGuild
Check if player is in the Discord server.Role Checking
GetDiscordRoles
Get all roles as full role objects (sorted by position).GetDiscordRoleIds
Get array of role IDs.GetDiscordRoleNames
Get array of role names (for display purposes).HasDiscordRole
Check if player has a specific role.HasAnyDiscordRole
Check if player has any of the specified roles.HasAllDiscordRoles
Check if player has all of the specified roles.Role Management
All role management functions support audit log reasons (visible in Discord’s audit log).AddRole
Add a role to a player.AddRoleById
Add a role by Discord ID (player doesn’t need to be online).RemoveRole
Remove a role from a player.RemoveRoleById
Remove a role by Discord ID.SetRoles
Replace all roles for a player (use with caution).SetRolesById
Replace all roles by Discord ID.SetNickname
Set a player’s Discord nickname.SetNicknameById
Set nickname by Discord ID.Reset Nickname
Pass empty string or nil to reset nickname.MoveToVoiceChannel
Move a player to a voice channel.MoveToVoiceChannelById
Move by Discord ID. Passnil as channel to disconnect from voice.
Guild Data
GetGuildInfo
Get information about the Discord server.GetAllRoles
Get all roles in the server.GetRoleById
Get a specific role by ID.GetRoleByName
Get a role by name (for display/lookup purposes).GetRoleIdFromName
Get role ID from name.GetRoleNameFromId
Get role name from ID.GetRolesAbovePosition
Get all roles above a certain position.GetRolesWithPermission
Get roles that have a specific Discord permission.RefreshRoles
Force refresh roles from Discord API.Permission System
The permission system automatically maps Discord roles to FiveM ACE permissions.Configuration
Inconfig.lua, define role mappings using Role IDs:
HasPermission
Check if player has a specific permission.HasAnyPermission
Check if player has any of the specified permissions.HasAllPermissions
Check if player has all specified permissions.IsInGroup
Check if player is in an ACE group.GetPermissions
Get all permissions assigned to a player.GetGroups
Get all ACE groups assigned to a player.SyncPermissions
Manually re-sync a player’s permissions from Discord.ResyncAllPermissions
Re-sync permissions for all connected players.Webhooks
Send messages and embeds to Discord channels via webhooks.Configuration
Inconfig.lua, define your webhooks:
SendWebhookMessage
Send a simple text message.SendWebhookEmbed
Send an embed.SendWebhookTemplate
Send using a pre-defined template with placeholders.SendWebhook
Send a full webhook payload (advanced).SendWebhookDirect
Send directly to a URL (bypasses named webhooks).BuildEmbed
Build an embed object for use elsewhere.BuildEmbedFromTemplate
Build an embed from a template.Embed Options
| Option | Type | Description |
|---|---|---|
title | string | Embed title |
description | string | Embed description |
color | number | Decimal color (e.g., 16711680 for red) |
url | string | URL for the title |
thumbnail | string | Thumbnail image URL |
image | string | Large image URL |
author | table | { name, url, icon_url } |
footer | string/table | "text" or { text, icon_url } |
fields | table | Array of { name, value, inline } |
timestamp | string | ISO timestamp (auto-added by default) |
Color Reference
Common colors in decimal:- Red:
16711680 - Green:
5763719 - Blue:
5793266 - Yellow:
16776960 - Orange:
16744448 - Purple:
10181046
Cache Management
InvalidatePlayer
Clear cached data for a player (forces re-fetch on next request).InvalidatePlayerById
Clear cache by Discord ID.PrefetchAllPlayers
Fetch and cache data for all connected players.ClearCache
Clear all cached data.GetCacheStats
Get cache statistics.GetHttpStats
Get HTTP request statistics.Utilities
IsInitialized
Check if the API is ready.GetInitializationError
Get initialization error if any.Server Utilities
LonexDiscordAPI includes built-in server utilities for AOP, PeaceTime, Announcements, Postals, and HUD. These are managed via config and chat commands, but you can also listen to events from your own resources.AOP (Area of Play)
Command:/aop <zone> - Change the current AOP
Events:
PeaceTime
Commands:/peacetime or /pt - Toggle PeaceTime
Features (v1.2.0):
- Weapons are automatically disabled during PeaceTime
- Speed limit warnings when driving over the configured limit
Announcements
Command:/announce <message> - Send a server-wide announcement
Events:
Postals
Command:/postal <code> - Set waypoint to postal code, /postal - Cancel waypoint
Events:
Server HUD
The Server HUD displays compass, street, zone, postal, AOP, PeaceTime status, and player info. Command:/togglehud - Toggle HUD visibility
Placeholders available:
{COMPASS}- Direction (N, NE, E, etc.){STREET}- Current street name{ZONE}- Current zone/area{POSTAL}- Nearest postal code{POSTAL_DIST}- Distance to nearest postal{AOP}- Current Area of Play{PEACETIME}- PeaceTime status{ID}- Player’s server ID{PLAYERS}- Online player count{TAG}- Player’s current tag
Emergency Calls
The emergency calls system (911/311) allows players to request assistance with location tracking.Commands
/911 <message>- Send emergency call/311 <message>- Send non-emergency call (if enabled)/resp <call_id>- Respond to a call (sets waypoint)/duty- Toggle duty status (if duty system enabled)
Events
Tags System
The unified tags system provides head tags, chat prefixes, and pma-voice integration.Commands
/tags- Open the tag selection menu
Events
Server Events (for custom integrations)
Activity System
The Activity System provides comprehensive duty tracking for emergency services with live blips, loadouts, database logging, and HTTP API access.Commands
/duty [department]- Clock in/out of duty/bliptag [id]- Change your displayed blip tag/units- List all on-duty players by department
IsOnDuty
Check if a player is currently on duty.GetPlayerDepartment
Get the department a player is currently on duty for.GetDutyInfo
Get full duty information for a player.GetOnDutyPlayers
Get all currently on-duty players.GetOnDutyByDepartment
Get on-duty players for a specific department.GetDepartmentCounts
Get count of on-duty players per department.SetDutyStatus
Programmatically set a player’s duty status.GetDutyDuration
Get how long a player has been on duty (in seconds).GetPlayerDepartments
Get list of departments a player has access to (based on Discord roles).Activity System Events
HTTP API Endpoints
WhenConfig.ActivitySystem.API.Enabled = true, the following endpoints are available:
Get Online Units
Blip Features
The Activity System provides live blips for on-duty players:- Dynamic Sprites: Different icons for on-foot vs in-vehicle
- Siren Detection: Blips flash red/blue when lights & sirens are active
- Heading Indicator: Shows which direction the player is facing
- Department Tags: Display department abbreviation on blip
Loadout System
When players clock in, they automatically receive configured weapons and armor:Error Handling
Most functions that can fail returnvalue, error:
Events
The resource triggers these events that you can listen for:Debug Commands
Available whenConfig.Debug = true:
| Command | Description |
|---|---|
lonex_discord_status | Show initialization status |
lonex_discord_guild | Show guild information |
lonex_discord_roles | List all cached roles |
lonex_discord_test | Test player exports (in-game) |
lonex_discord_testid <discord_id> | Test by Discord ID |
lonex_discord_addrole <discord_id> <role_id> | Add role |
lonex_discord_removerole <discord_id> <role_id> | Remove role |
lonex_discord_setnick <discord_id> [nickname] | Set nickname |
lonex_discord_perms <player_id> | Show player permissions |
lonex_debug_vehicles <player_id> | Debug vehicle permissions |
lonex_discord_hasperm <player_id> <perm> | Check permission |
lonex_discord_syncperms <player_id/all> | Sync permissions |
lonex_discord_testwebhook <webhook_name> | Test webhook |
lonex_discord_webhook <name> <message> | Send webhook message |

