Skip to content

Discord (np_discord) ​

np_admin has no Discord bot of its own. Role sync, ban sync and log routing go through np_discord, which owns the bot, the member cache and the rate limits. Everything here is optional and off by default.

Discord sync

Setup ​

  1. Install and configure np_discord (bot token, guild; see np_discord → Installation) and start it before np_admin.
  2. Turn on Config.Discord.enabled, or Resource settings → np_admin → Discord → Discord role sync.
  3. Map roles to groups in Discord sync (np_admin.discord.manage), or set defaults in Config.Discord.roles:
lua
Config.Discord = {
  enabled = true,
  twoWay = false,
  syncBans = false,
  requireRole = nil,
  roles = {
    ['admin'] = { group = 'admin' },
    ['vip'] = { group = 'vip', flags = { queuePriority = 60 } },
    ['streamer'] = { flags = { streamer = true } },
  },
}

The key is one of:

  • a Discord role id: works for every guild the bot is in, and survives renames. Use ids for staff groups.
  • a role name: np_discord searches its main guild and its Config.Guilds. A guild the bot was only invited to is never searched by bare name, so a partner server's "Admin" can't hand out your admin group.
  • 'guild/name' for a role in another guild, e.g. 'lspd/Officer' (the guild names are listed by np_discord's GetBotGuilds).

Mappings made in the panel win over the config ones; only panel mappings can be deleted there.

Several guilds and adapter versions ​

np_discord can track a main guild plus team or faction guilds (LSPD, LSMD, FIB …). The current np_admin adapter's role picker lists roles from all tracked guilds, with the guild next to every role outside the main one, so an LSPD "Chief" can map to a group just like a main-guild role. It also preserves existing Discord-sourced memberships when a mapped role cannot be answered, even if another role can be answered.

These behaviors are included by the multi-guild np_admin adapter update. Older versions without that update list the configured guild in the picker and can remove an unanswered role's Discord-sourced membership when another role answers. Role IDs can still be entered in mappings; np_discord resolves the role's guild. Check that the update is included in the np_admin version you install before relying on multi-guild picking and per-role preservation.

How sync works ​

  • When: on join, on np_discord's np_discord:playerReady and np_discord:playerRolesChanged (live with np_discord's gateway, polled otherwise), when a mapping changes, and with Sync in the panel (discord.sync).
  • Groups: for each mapped role, np_admin asks np_discord HasRole and adds or removes memberships with source = 'discord'. Manual grants are never touched. If np_discord cannot answer for a role (its guild is unreachable, or a name matches roles in several guilds), the current adapter preserves the existing membership unless another mapped role confirms it. Only confirmed negative answers remove a Discord-sourced membership; see the older-version limitations above.
  • Flags: queuePriority and streamer go to Player(src).state.npAdminFlags and exports.np_admin:getFlags(src), for a queue or other resources to read.

Options ​

Option
twoWay Granting a mapped group in-game adds the Discord role (exports.np_discord:AddRole), removing it removes the role. The bot needs Manage Roles and its role must sit above the mapped roles
syncBans In-game bans ban on Discord too; revoking the ban unbans there
requireRole Refuse connecting without this role. If Discord can't be reached, players are let in. np_discord's own connect whitelist is the better place for this

Log routing ​

Config.Logs.discord maps audit log categories to np_discord log channels (exports.np_discord:Log). See Audit log.

Nodes ​

Node
np_admin.discord.view See the Discord sync view
np_admin.discord.manage Edit mappings, run a sync