Discord API · error code

Discord error 4003: Not authenticated

RetryableGateway close codes (4000-4014)

Last verified against Discord Developer Docs - Opcodes and status codes

What Discord returns
You sent us a payload prior to identifying, or this session has been invalidated.

What error 4003 means

You sent something other than Identify or Resume on a connection that has not been authenticated yet, or you sent a payload on a session Discord has already invalidated. The gateway handshake is strict: after the socket opens, Discord sends Hello (op 10); you must then send Identify (op 2) or Resume (op 6) before any Presence Update, Voice State Update, or Request Guild Members. Sending those early closes the connection with 4003.

The second half of the description is the one library users meet. If Discord invalidated your session (Invalid Session op 9, or a long outage) and your client kept sending heartbeats or presence updates on the old socket, the next frame triggers 4003. Well-behaved libraries handle this by reconnecting and re-identifying. If you see it repeatedly, something is racing the handshake, often custom code that sets presence or requests members in a connect hook before READY fires.

What it looks like

// WebSocket close frame
code: 4003
reason: "Not authenticated"

Why it happens

  • Presence update, voice state update or guild member request sent before Identify completes
  • Custom startup code running before the READY event
  • Heartbeat or other payload sent on a session that received Invalid Session
  • Resume attempted with a session_id that has already been invalidated

How to fix Discord error 4003

  1. 1Move any presence or member-request code into the READY handler (or your library's ready/clientReady event)
  2. 2On Invalid Session (op 9) with d=false, wait 1-5 seconds and send a fresh Identify; do not reuse the old session
  3. 3Check the library's connection state machine and ensure your code does not send while in connecting state
  4. 4Allow the library to reconnect; 4003 is resumable in the sense that a new session can be started

How to stop it recurring

Treat READY as the earliest point at which your bot may send anything beyond the handshake. Gate all outbound gateway actions behind a ready flag, and clear that flag on every disconnect so nothing sends during reconnection.

The handshake is a state machine, and 4003 means your code has an arrow the diagram does not. Gate sends on READY, clear the gate on every disconnect. The identify and session budgets that reconnection consumes are on the Discord limits page, and a failure of the Identify itself is 4004.

Official reference: Discord Developer Docs - Opcodes and status codes. See all Discord error codes or the Discord limits and quotas.

Related codes

Error 4003 - quick answers

What does Discord error 4003 mean?

You sent something other than Identify or Resume on a connection that has not been authenticated yet, or you sent a payload on a session Discord has already invalidated. The gateway handshake is strict: after the socket opens, Discord sends Hello (op 10); you must then send Identify (op 2) or Resume (op 6) before any Presence Update, Voice State Update, or Request Guild Members.

How do I fix Discord error 4003?

1. Move any presence or member-request code into the READY handler (or your library's ready/clientReady event) 2. On Invalid Session (op 9) with d=false, wait 1-5 seconds and send a fresh Identify; do not reuse the old session 3. Check the library's connection state machine and ensure your code does not send while in connecting state 4. Allow the library to reconnect; 4003 is resumable in the sense that a new session can be started

Can I retry after error 4003?

Yes - this is a retryable condition. Back off (start around one second and double on each attempt, with jitter) and watch for a retry-after hint from the platform before resending.

Stop debugging Discord by hand

Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.