Skip to content

bug(discord): close code 4014 (missing Privileged Gateway Intents) crashes entire gateway process #20714

Closed

Description

@mudrii

Summary

When a Discord bot is missing Privileged Gateway Intents (e.g. Message Content Intent), Discord sends WebSocket close code 4014. OpenClaw does not catch this error — it propagates as an uncaught exception that kills the entire gateway process, taking down all channels (Telegram, Slack, WhatsApp, etc.) alongside Discord.

This is a critical reliability issue: a misconfigured Discord bot should only disable the Discord channel, not crash the whole bot.


Error

[openclaw] Uncaught exception: Error: Fatal Gateway error: 4014
  at GatewayPlugin.handleReconnectionAttempt (.../@buape/carbon/GatewayPlugin.ts:420:7)
  at GatewayPlugin.handleClose (.../@buape/carbon/GatewayPlugin.ts:469:8)

When It Is Encountered

  • User enables the Discord channel plugin in OpenClaw
  • The Discord bot token is valid, but one or more Privileged Gateway Intents are not enabled in the Discord Developer Portal (e.g. Message Content Intent, Server Members Intent, Presence Intent)
  • OpenClaw connects to Discord; Discord immediately sends close code 4014 during handshake
  • The @buape/carbon GatewayPlugin.handleReconnectionAttempt throws Fatal Gateway error: 4014
  • This throw happens before OpenClaw attaches an error listener to the gateway emitter
  • Node.js treats unhandled EventEmitter "error" events as uncaught exceptions → process exits

How to Reproduce

  1. Go to Discord Developer Portal → your application → Bot
  2. Under Privileged Gateway Intents, disable Message Content Intent (or leave it disabled)
  3. Configure OpenClaw with that bot token:
channels: {
  discord: {
    enabled: true,
    token: "<your-bot-token>",
    // ...
  }
}
  1. Start or restart the OpenClaw gateway
  2. Result: Gateway process exits with Uncaught exception: Error: Fatal Gateway error: 4014
  3. Expected: Discord channel fails gracefully with an actionable error message; all other channels (Telegram, Slack, etc.) continue working

Root Cause

Error propagation path:

Carbon GatewayPlugin.handleClose()
  → handleReconnectionAttempt() throws Error("Fatal Gateway error: 4014")
  → surfaces as "error" event on the gateway EventEmitter
  → OpenClaw attaches its error listener too late (after several awaits:
     deployDiscordCommands, identity fetch, etc.)
  → no listener attached at event time
  → Node.js default: unhandled EventEmitter "error" → uncaught exception → process crash

Close code 4014 is non-recoverable — reconnection attempts will always fail until the user manually enables intents in the Discord Developer Portal. The gateway should stop reconnecting and surface a clear diagnostic instead.


Expected Behavior

  1. Attach an early gatewayEmitter.on("error", ...) listener before any async operations that could allow gateway events to fire
  2. On close code 4014: log a clear, actionable message:

    Discord: Missing Privileged Gateway Intents. Go to Discord Developer Portal → Your App → Bot → enable required intents (e.g. Message Content Intent).

  3. Disable reconnection attempts (non-recoverable error)
  4. Shut down only the Discord channel — all other channels remain running
  5. Do NOT propagate as uncaught exception

Comparison with Other Providers

Telegram and Slack providers use explicit bot.catch(...) / monitor catch patterns to contain provider-level failures. The Discord provider should follow the same containment principle for gateway error events rather than relying on uncaught exception behavior.


Prior Issues

This issue persists across all prior reports and has never been resolved.


Environment

  • OpenClaw version: v2026.2.18+
  • Channel: Discord (plugin: @buape/carbon GatewayPlugin)
  • Trigger: Any bot with missing Privileged Gateway Intents
  • Impact: Full gateway crash — all channels go down

Activity

  1. thewilloftheshadow commented on Feb 19, 2026

    @thewilloftheshadow
    Member

    Fixed in f7a8c2d

  2. mudrii commented on Feb 20, 2026

    @mudrii
    Author
  3. thewilloftheshadow commented on Feb 20, 2026

    @thewilloftheshadow
    Member

    Sorry, I didn't see that PR. We're all getting swarmed by dozens of people constantly pinging us every hour to review things and also constantly having to look at bug reports as well as implement the other things we were planning to implement.

    I actually hadn't seen this issue yet either when I made the commit, I implemented it on my own and then saw the issue while I was searching

  4. mudrii commented on Feb 20, 2026

    @mudrii
    Author
  5. thewilloftheshadow commented on Feb 20, 2026

    @thewilloftheshadow
    Member

    @mudrii if you have it happen again with the commit that I pushed, please open a new PR and ping me with it in our discord in the collaborators channel

    (to everyone else reading this, no don't do this with your own PRs smh)

  6. locked as resolved and limited conversation to collaborators on Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions