Discord API Resource

Discord API

A comprehensive FiveM resource for integrating Discord functionality into your server. This resource provides easy access to Discord user data, guild membership, roles, and more through a simple API.


Table of contents
  1. πŸ“‹ Overview
  2. πŸŽ₯ Installation Tutorial
  3. πŸ›’ Purchase & Download
    1. Purchase Location
    2. Download Method
  4. βš™οΈ Installation Process
    1. Step 1: File Transfer
    2. Step 2: Server Configuration
    3. Step 3: Configuration Setup
  5. πŸ”§ Configuration
    1. Basic Configuration
    2. Configuration Details
    3. Discord Bot Token
      1. Option A: Your Own Bot
      2. Option B: Our Provided Bot
  6. πŸ€– Creating Your Own Discord Bot
    1. Step 1: Create Discord Application
    2. Step 2: Create Bot User
    3. Step 3: Configure Permissions
    4. Step 4: Invite Bot to Server
  7. πŸ“š Exports
    1. Guild Membership Functions
      1. IsUserPartOfThisGuild(src, force, guildName)
      2. IsUserPartOfAnyOfTheseGuilds(src, force, guildNames)
      3. IsUserPartOfAllOfTheseGuilds(src, force, guildNames)
    2. User Data Functions
      1. GetDiscordUser(src, force)
      2. GetDiscordMember(src, force, guildNames)
    3. Role Functions
      1. GetDiscordMemberRoles(src, force, guildNames)
      2. IsMemberPartOfThisRole(src, roleName, force, guildNames)
      3. IsMemberPartOfAnyOfTheseRoles(src, roleNames, force, guildNames)
      4. IsMemberPartOfAllOfTheseRoles(src, roleNames, force, guildNames)
    4. Guild Information Functions
      1. GetDiscordGuild(guildName, force)
  8. πŸ’‘ Usage Examples
    1. Basic Permission System
    2. Multi-Server Role Check
    3. User Information Display
    4. Guild Membership Verification
    5. Advanced Role System
  9. πŸ”— Integration with Other Resources
  10. 🚨 Troubleshooting
    1. Common Issues
      1. Bot Not Responding
      2. Role Permissions Not Working
      3. Resource Dependencies
    2. Error Messages
    3. Debug Mode
  11. πŸ“Š Performance Optimization
    1. Best Practices
    2. Monitoring
  12. πŸ“ž Support
    1. Getting Help
    2. Useful Links

πŸ“‹ Overview

The Discord API resource provides seamless integration between your FiveM server and Discord, enabling:

  • Role-based permissions across all connected resources
  • Real-time player synchronization with Discord roles
  • Automatic player management based on Discord membership
  • Cross-platform communication between Discord and FiveM
  • Discord User Management: Check if users are members of specific Discord servers
  • Role Verification: Verify user roles across multiple Discord servers
  • User Data Retrieval: Get Discord user information, avatars, and member details
  • Guild Information: Retrieve Discord server/guild information
  • Caching System: Built-in caching for improved performance
  • Rate Limiting: Automatic Discord API rate limit handling
  • Multi-Guild Support: Support for multiple Discord servers
  • Custom Role Mapping: Map Discord role IDs to custom names

Prerequisites: You’ll need a Discord bot token and basic knowledge of Discord server management.


πŸŽ₯ Installation Tutorial

Video Guide - Watch our comprehensive installation tutorial:

Installation Tutorial


πŸ›’ Purchase & Download

Purchase Location

Tebex Store: Discord API Package

Download Method

Download via CFX Portal after purchase.

Important: It may take a few minutes for the resource to appear in the CFX Portal after purchase.


βš™οΈ Installation Process

Step 1: File Transfer

Critical: Always follow this exact order to avoid parsing errors:

  1. Download the ZIP package
  2. Extract to a local folder
  3. Set FTP transfer mode to binary
  4. Upload files to your server’s resources folder
  5. Add to server.cfg
  6. Restart your server

Step 2: Server Configuration

Add the resource to your server.cfg somewhere ON TOP as one of the first starting resources:

ensure night_discordapi

Pro Tip: Place this line before any other resources that depend on Discord API.

Step 3: Configuration Setup

Configure /config/config.lua (see configuration section below).


πŸ”§ Configuration

Note: This resource requires a Discord bot to function. You can either use the default bot provided by Nights Software or set up your own Discord bot following the documentation.

Basic Configuration

Config = {
    -- Discord Bot Token (leave empty to use the provided default FiveM DC API bot, or add your own bot token)
    Discord_Bot_Token = "",
    
    -- Discord Guild/Server Configuration
    Discord_Guild_Names = {
        ["YOUR_GUILD_ID"] = "Your Guild Name",
        ["ANOTHER_GUILD_ID"] = "Another Guild Name",
    },
    
    -- Discord Role Mapping
    Discord_Role_Names = {
        ["ROLE_ID"] = "Role_Name",
        ["ANOTHER_ROLE_ID"] = "Another_Role",
    },
    
    -- Logging Level (0 = INFO/ERROR/WARN only, 1+ = includes DEBUG)
    Discord_API_Log_Level = 1,
}

Configuration Details

  • Discord_Bot_Token: Your Discord bot token (optional - uses default if empty)
  • Discord_Guild_Names: Map Discord server IDs to readable names
  • Discord_Role_Names: Map Discord role IDs to custom role names
  • Discord_API_Log_Level: Control logging verbosity

Discord Bot Token

Choose between using your own bot or our provided bot:

Option A: Your Own Bot

Discord_Bot_Token = "NzV4sQb2IEcGxY0bnPWrlHoz.E0LPvL.SJcnCkgAniGUxGXve0xrVMxv7HT"

Option B: Our Provided Bot

Discord_Bot_Token = ""

Our Bot Invite Link: Invite Nights Software Bot

Note: Our shared bot may have longer response times due to multiple server usage.


πŸ€– Creating Your Own Discord Bot

Step 1: Create Discord Application

  1. Go to Discord Developer Portal
  2. Click β€œNew Application”
  3. Name your application (e.g., β€œMy FiveM Server Bot”)

Step 2: Create Bot User

  1. Navigate to β€œBot” section
  2. Click β€œAdd Bot”
  3. Copy the bot token (keep this secure!)

Step 3: Configure Permissions

Set these bot permissions:

  • Read Messages/View Channels
  • Manage Roles (if using role-based features)
  • Send Messages (for notifications)

Step 4: Invite Bot to Server

Use this URL format (replace CLIENT_ID with your bot’s client ID):

https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=1024&scope=bot

πŸ“š Exports

The Discord API provides comprehensive exports for checking guild membership, user data, roles, and guild information.

Guild Membership Functions

IsUserPartOfThisGuild(src, force, guildName)

Check if a player is a member of a specific Discord server.

Parameters:

  • src (string): Player source ID
  • force (boolean): Force refresh cache (required)
  • guildName (string): Name of the Discord server (as defined in config) (required)

Returns: boolean - true if user is a member, false if not, nil on error

Example:

local isMember = exports['night_discordapi']:IsUserPartOfThisGuild(source, false, "Your Guild Name")
if isMember then
    print("Player is a member of the Discord server!")
end

IsUserPartOfAnyOfTheseGuilds(src, force, guildNames)

Check if a player is a member of any of the specified Discord servers.

Parameters:

  • src (string): Player source ID
  • force (boolean): Force refresh cache (optional)
  • guildNames (table): Array of Discord server names (optional)

Returns: boolean - true if user is a member of any server, false if not, nil on error

Example:

local guildNames = {"Guild 1", "Guild 2", "Guild 3"}
local isMember = exports['night_discordapi']:IsUserPartOfAnyOfTheseGuilds(source, false, guildNames)
if isMember then
    print("Player is a member of at least one Discord server!")
end

IsUserPartOfAllOfTheseGuilds(src, force, guildNames)

Check if a player is a member of all specified Discord servers.

Parameters:

  • src (string): Player source ID
  • force (boolean): Force refresh cache (optional)
  • guildNames (table): Array of Discord server names (optional)

Returns: boolean - true if user is a member of all servers, false if not, nil on error

Example:

local guildNames = {"Guild 1", "Guild 2"}
local isMember = exports['night_discordapi']:IsUserPartOfAllOfTheseGuilds(source, false, guildNames)
if isMember then
    print("Player is a member of all Discord servers!")
end

User Data Functions

GetDiscordUser(src, force)

Get Discord user information for a player.

Parameters:

  • src (string): Player source ID
  • force (boolean): Force refresh cache (optional)

Returns: table - User data containing id, name, avatar, or nil on error

Example:

local userData = exports['night_discordapi']:GetDiscordUser(source, false)
if userData then
    print("Discord ID: " .. userData.id)
    print("Username: " .. userData.name)
    print("Avatar: " .. (userData.avatar or "No avatar"))
end

GetDiscordMember(src, force, guildNames)

Get Discord member information for a player in specific servers.

Parameters:

  • src (string): Player source ID
  • force (boolean): Force refresh cache (optional)
  • guildNames (table): Array of Discord server names (optional)

Returns: table - Member data containing id, name, nick, avatar, discriminator, roles, or nil on error

Example:

local memberData = exports['night_discordapi']:GetDiscordMember(source, false, {"Your Guild Name"})
if memberData then
    print("Member ID: " .. memberData.id)
    print("Nickname: " .. (memberData.nick or "No nickname"))
    print("Roles: " .. table.concat(memberData.roles, ", "))
end

Role Functions

GetDiscordMemberRoles(src, force, guildNames)

Get all Discord roles for a player across specified servers.

Parameters:

  • src (string): Player source ID
  • force (boolean): Force refresh cache (optional)
  • guildNames (table): Array of Discord server names (optional)

Returns: table - Array of role names, or nil on error

Example:

local roles = exports['night_discordapi']:GetDiscordMemberRoles(source, false, {"Guild 1", "Guild 2"})
if roles then
    for _, role in ipairs(roles) do
        print("Role: " .. role)
    end
end

IsMemberPartOfThisRole(src, roleName, force, guildNames)

Check if a player has a specific Discord role.

Parameters:

  • src (string): Player source ID
  • roleName (string): Name of the role to check
  • force (boolean): Force refresh cache (optional)
  • guildNames (table): Array of Discord server names (optional)

Returns: boolean - true if user has the role, false if not, nil on error

Example:

local hasRole = exports['night_discordapi']:IsMemberPartOfThisRole(source, "Admin", false, {"Your Guild"})
if hasRole then
    print("Player has Admin role!")
end

IsMemberPartOfAnyOfTheseRoles(src, roleNames, force, guildNames)

Check if a player has any of the specified Discord roles.

Parameters:

  • src (string): Player source ID
  • roleNames (table): Array of role names to check
  • force (boolean): Force refresh cache (optional)
  • guildNames (table): Array of Discord server names (optional)

Returns: boolean - true if user has any of the roles, false if not, nil on error

Example:

local roleNames = {"Admin", "Moderator", "VIP"}
local hasRole = exports['night_discordapi']:IsMemberPartOfAnyOfTheseRoles(source, roleNames, false, {"Your Guild"})
if hasRole then
    print("Player has at least one of the specified roles!")
end

IsMemberPartOfAllOfTheseRoles(src, roleNames, force, guildNames)

Check if a player has all of the specified Discord roles.

Parameters:

  • src (string): Player source ID
  • roleNames (table): Array of role names to check
  • force (boolean): Force refresh cache (optional)
  • guildNames (table): Array of Discord server names (optional)

Returns: boolean - true if user has all roles, false if not, nil on error

Example:

local roleNames = {"Admin", "Moderator"}
local hasAllRoles = exports['night_discordapi']:IsMemberPartOfAllOfTheseRoles(source, roleNames, false, {"Your Guild"})
if hasAllRoles then
    print("Player has all specified roles!")
end

Guild Information Functions

GetDiscordGuild(guildName, force)

Get information about a Discord server/guild.

Parameters:

  • guildName (string): Name of the Discord server (as defined in config)
  • force (boolean): Force refresh cache (optional)

Returns: table - Guild data containing id, name, icon, ownerid, roles, or nil on error

Example:

local guildData = exports['night_discordapi']:GetDiscordGuild("Your Guild Name", false)
if guildData then
    print("Guild ID: " .. guildData.id)
    print("Guild Name: " .. guildData.name)
    print("Owner ID: " .. guildData.ownerid)
end

πŸ’‘ Usage Examples

Basic Permission System

-- Check if player has admin role
local hasAdmin = exports['night_discordapi']:IsMemberPartOfThisRole(source, "Admin", false, {"Your Guild"})
if hasAdmin then
    -- Give admin permissions
    TriggerClientEvent('chat:addMessage', source, {
        color = {255, 0, 0},
        multiline = true,
        args = {"System", "You have admin permissions!"}
    })
end

Multi-Server Role Check

-- Check if player has role in any of multiple servers
local guildNames = {"Main Server", "Staff Server", "VIP Server"}
local roleNames = {"Admin", "Moderator", "VIP"}
local hasPermission = exports['night_discordapi']:IsMemberPartOfAnyOfTheseRoles(source, roleNames, false, guildNames)

if hasPermission then
    -- Example: Grant access to restricted area
    TriggerClientEvent('restrictedArea:grantAccess', source)
end

User Information Display

-- Get and display user information
local userData = exports['night_discordapi']:GetDiscordUser(source, false)
if userData then
    TriggerClientEvent('chat:addMessage', -1, {
        color = {0, 255, 0},
        multiline = true,
        args = {"Discord", userData.name .. " joined the server!"}
    })
end

Guild Membership Verification

-- Verify player is member of specific guild
local isMember = exports['night_discordapi']:IsUserPartOfThisGuild(source, false, "Whitelisted Guild")
if not isMember then
    DropPlayer(source, "You must be a member of our Discord server to join this server.")
end

Advanced Role System

-- Check multiple roles across multiple servers
local guildNames = {"Police Department", "Fire Department", "EMS"}
local requiredRoles = {"Officer", "Firefighter", "Paramedic"}

local hasRequiredRole = exports['night_discordapi']:IsMemberPartOfAnyOfTheseRoles(source, requiredRoles, false, guildNames)
if hasRequiredRole then
    -- Allow access to emergency services
    TriggerClientEvent('emergency:grantAccess', source)
else
    TriggerClientEvent('chat:addMessage', source, {
        color = {255, 0, 0},
        multiline = true,
        args = {"System", "You need to be verified in our Discord server to access emergency services."}
    })
end

πŸ”— Integration with Other Resources

The Discord API serves as the foundation for these resources:

| Resource | Purpose | |β€”β€”β€”-|β€”β€”β€”| | Player List | Display players with Discord roles | | Player Names | Sync Discord usernames | | Garage System | Role-based vehicle access | | Vehicle Permissions (vPerms) | Role-based vehicle permissions | | Weapon Permissions (wPerms) | Role-based weapon permissions | | Discord Spawn | Role-based spawning system | | Discord Lockers | Role-based locker access | | Discord Allowlist | Discord-based allowlist system | | Emergency Response Simulator | A PvE Emergency Simulator | | Night Shifts MDT | An system managing Emergency Services & Registrations | β€”

🚨 Troubleshooting

Common Issues

Bot Not Responding

  • Verify bot token is correct
  • Ensure bot is online and has proper permissions
  • Check bot is invited to your Discord server

Role Permissions Not Working

  • Confirm role IDs are correct
  • Verify bot has been given the required permission
  • Verify the guild names match between the scripts, if applicable.
  • Verify the role names match between the scripts.

Resource Dependencies

  • Ensure Discord API loads before dependent resources
  • Check server.cfg load order

Error Messages

Error Solution
Discord API not found Check resource name in server.cfg
Invalid bot token Verify token format and validity
Guild not found Confirm guild ID and bot membership

Debug Mode

Enable debug logging by setting Discord_API_Log_Level = 1 in your config to see detailed API request information.

Need Help? Join our Discord community for support.


πŸ“Š Performance Optimization

Best Practices

  • Use your own custom bot token, which is not used for any other purposes.

Monitoring

  • Check F8 console for error messages
  • Monitor the txAdmin console for the Discord API status & installation feedback.

πŸ“ž Support

Getting Help

  1. Check this documentation for common solutions
  2. Search our Discord for similar issues
  3. Create a support ticket with detailed information

Back to top

Copyright © 2025 Nights Software

Page last modified: July 22, 2025 at 04:00 PM.