LizardGlobalGH

payload discord sync

by LizardGlobalGH
Third-party services
v3
^3.0.0
MIT

Overview

Summary generated from the README

Syncs Discord guilds, channels, members and roles into dedicated Payload collections through a bot token and discord.js. Syncs can be started from the admin panel, a programmatic API, an HTTP endpoint or scheduled Payload jobs. It targets Payload 3 and needs a Discord bot with the Server Members Intent enabled. The plugin is marked experimental and does not listen to live gateway events.

Features

  • Creates collections for Discord guilds, channels, members and roles
  • Sync Discord button on the guilds list in the admin panel
  • POST endpoint and programmatic functions to run or queue syncs
  • Scheduled recurring sync through Payload jobs with a cron setting
  • Optional linking of Discord members to a users collection by Discord ID or email
  • Limit sync to selected guild IDs and override collection slugs and fields

Use cases

  • Display or manage Discord community members and roles inside Payload
  • Link Discord accounts to site users after Discord OAuth sign-in
  • Keep a periodically refreshed copy of server channels and roles for a website

From the author

Payload CMS plugin to sync Discord guilds, channels, members, and roles via discord.js

Installation

npm i @lizardglobal/payload-discord-sync

0

Stars

0

Forks

1

Open Issues

3 months ago

Last Updated

3

Weekly Downloads

v0.1.7

npm Version

181.2 KB

Unpacked Size

1

Dependencies

GitHub stars

Trends appear after 7 days of data. Collecting since Oct 22 — 5 daily snapshots so far.

npm weekly downloads

Trends appear after 7 days of data. Collecting since Oct 22 — 5 daily snapshots so far.

Each point is npm's rolling 7-day download count.

Health Score

38/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1313834549-root.svg)](https://payloaddirectory.dev/plugins/1313834549-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1313834549-root"><img src="https://payloaddirectory.dev/badge/1313834549-root.svg" alt="Payload Directory"></a>
Updated Jul 28, 2026Created Jul 27, 2026Published Jul 27, 2026

README

@lizardglobal/payload-discord-sync

Payload CMS plugin that syncs Discord guilds, channels, members, and roles into Payload collections using discord.js.

npm

Release

[!WARNING] This plugin is still experimental. APIs, collection schemas, and behavior may change without a stable compatibility guarantee. Use in production with caution and pin versions deliberately.

Features

  • Syncs Discord guilds, channels, members, and roles into Payload collections
  • Triggers: admin UI, programmatic API, HTTP endpoint, or scheduled Payload jobs
  • Scope syncs to all guilds the bot is in, or a subset of guild IDs
  • Optional user linking (automatic and/or programmatic) to your auth/users collection
  • Member email field (from OAuth — Discord bots cannot read emails from guild member lists)
  • Typed config with collection slug/field overrides

Sync is on-demand or scheduled. The plugin does not listen to live Discord gateway events (guildUpdate, channelUpdate, etc.).

Requirements

  • Payload 3.x
  • Node.js ^18.20.2 || >=20.9.0
  • A Discord bot with the Server Members Intent enabled (for member sync)

Install

pnpm add @lizardglobal/payload-discord-sync discord.js
# or
npm install @lizardglobal/payload-discord-sync discord.js

Discord bot setup

  1. Create an application in the Discord Developer Portal
  2. Create a bot and copy the bot token
  3. Under Bot → Privileged Gateway Intents, enable Server Members Intent
  4. Invite the bot to your guild(s) with permission to view channels and members

Quick start

import { buildConfig } from 'payload'
import { discordSyncPlugin } from '@lizardglobal/payload-discord-sync'

export default buildConfig({
  // ...
  plugins: [
    discordSyncPlugin({
      botToken: process.env.DISCORD_BOT_TOKEN!,
      // Optional: omit to sync every guild the bot is in
      guildIds: ['123456789012345678'],
      linkUsers: {
        collection: 'users',
      },
      schedule: {
        enabled: true,
        cron: '0 */6 * * *',
        seedOnInit: true, // avoid in busy serverless environments
      },
    }),
  ],
})

Configuration

OptionTypeDescription
botTokenstringDiscord bot token (required unless disabled)
disabledbooleanKeep collections in the schema but skip sync, endpoints, and jobs
guildIdsstring[]Limit sync to these guilds; empty/omitted = all bot guilds
resourcesobjectEnable/disable or customize guilds, channels, members, roles
linkUsersobjectLink Discord members to your users collection
scheduleboolean | objectRecurring sync via Payload jobs (cron, queue, seedOnInit, …)
admin.groupstringAdmin sidebar group (default Discord)
admin.syncActionbooleanShow Sync Discord on the guilds list (default true)
intentsnumber[]Override discord.js gateway intents
onSyncCompletefnCallback after a successful sync
onSyncErrorfnCallback when a sync fails

Resources

discordSyncPlugin({
  botToken: process.env.DISCORD_BOT_TOKEN!,
  resources: {
    members: false, // skip this collection
    guilds: {
      slug: 'servers',
      fields: ({ defaultFields }) => [
        ...defaultFields,
        { name: 'notes', type: 'textarea' },
      ],
    },
  },
})

Linking users

discordSyncPlugin({
  botToken: process.env.DISCORD_BOT_TOKEN!,
  linkUsers: {
    collection: 'users', // your users / auth collection slug
    discordIdField: 'discordId', // injected on users (default)
    userField: 'user', // relationship on discord-members (default)
    autoLink: true, // link on sync when discordId matches
    matchByEmail: false, // also match member.email → users.email
    injectUserFields: true,
  },
})

Automatic: on member sync, if a user already has discordId (or email when matchByEmail is on), the member’s user relationship is set.

Programmatic (typical after Discord OAuth with identify + email):

import { linkDiscordUser, unlinkDiscordUser } from '@lizardglobal/payload-discord-sync'

await linkDiscordUser({
  payload,
  userId: req.user.id,
  discordUserId: discordProfile.id,
  email: discordProfile.email,
})

await unlinkDiscordUser({
  payload,
  userId: req.user.id,
})

Triggering syncs

Admin panel

Open Discord Guilds and click Sync Discord (queues a job on the discord-sync queue).

Programmatic

import { syncDiscord, queueDiscordSync } from '@lizardglobal/payload-discord-sync'

// Inline
await syncDiscord({
  payload,
  input: {
    guildIds: ['123'], // optional
    resources: ['guilds', 'channels'], // optional
  },
})

// Via jobs queue
await queueDiscordSync({
  payload,
  input: { guildIds: ['123'] },
  reschedule: true,
})

HTTP

POST /api/discord-sync (authenticated admin/user session)

{
  "guildIds": ["123"],
  "resources": ["guilds", "channels", "members", "roles"],
  "async": true
}

Omit async or set false to run inline and return the result in the response.

Scheduled jobs

With schedule.enabled, the plugin registers a discordSync task and an autoRun entry on the discord-sync queue. Your app must process Payload jobs (via jobs.autoRun or a worker).

Seed the first job with schedule.seedOnInit: true, the admin button, or queueDiscordSync({ reschedule: true }).

Collections

ResourceDefault slugKey fields
Guildsdiscord-guildsdiscordId, name, icon, ownerId, memberCount
Channelsdiscord-channelsdiscordId, name, type, guild
Membersdiscord-membersdiscordId (guildId:userId), userDiscordId, username, email, user (if linkUsers), guild
Rolesdiscord-rolesdiscordId, name, permissions, guild

Every document also has lastSyncedAt and a raw JSON snapshot from Discord.

Contributing

See CONTRIBUTING.md for local setup, PR guidelines, and how releases work.

License

MIT

Similar plugins