Discord error 4007: Invalid seq
Last verified against Discord Developer Docs - Opcodes and status codes
The sequence sent when resuming the session was invalid. Reconnect and start a new session.What error 4007 means
You tried to Resume (op 6) with a sequence number Discord does not accept for that session. Every Dispatch event carries an incrementing s value; on resume you send the last one you processed so Discord can replay what you missed. If the number is ahead of what Discord ever sent, far behind the replay buffer, zero/null, or belongs to a different session, the resume is rejected with 4007 and you must start over with a fresh Identify.
Libraries handle this transparently: on 4007 they reconnect and identify, and you lose any events that happened during the gap. If you see it regularly, the cause is usually state handling: the bot persisted a stale sequence across restarts and tried to resume a long-dead session, or a sharded deployment mixed up session IDs and sequences between shards, or a proxy in front of the gateway (a gateway proxy or "gateway relay") desynchronized.
What it looks like
// WebSocket close frame
code: 4007
reason: "Invalid seq"Why it happens
- Stale session_id and seq persisted across process restarts and reused long after the session expired
- Sequence counter reset to 0 on reconnect but session_id reused
- Shards sharing storage and overwriting each other's seq
- Gateway proxy or relay forwarding inconsistent sequence numbers
How to fix Discord error 4007
- 1Let the library reconnect and re-identify; no manual action needed for occasional occurrences
- 2If you persist sessions for fast resume, store session_id, resume_gateway_url and seq together and invalidate them after a few minutes or on any failed resume
- 3Key persisted session state by shard ID
- 4Update the stored seq on every dispatch, not just periodically
How to stop it recurring
Resume state must be atomic and per-connection. Unless you are building infrastructure, do not persist it across process restarts at all; a clean Identify on startup is simpler and safe under the identify rate limit for small and medium bots.
Resume state is a cache with a very short shelf life; treat it accordingly. The session and resume mechanics, including what a resume replays and what it costs, are summarized on the Discord limits page, and a session that expired server-side rather than desynced produces 4009.
Official reference: Discord Developer Docs - Opcodes and status codes. See all Discord error codes or the Discord limits and quotas.
Related codes
Error 4007 - quick answers
What does Discord error 4007 mean?
You tried to Resume (op 6) with a sequence number Discord does not accept for that session. Every Dispatch event carries an incrementing s value; on resume you send the last one you processed so Discord can replay what you missed.
How do I fix Discord error 4007?
1. Let the library reconnect and re-identify; no manual action needed for occasional occurrences 2. If you persist sessions for fast resume, store session_id, resume_gateway_url and seq together and invalidate them after a few minutes or on any failed resume 3. Key persisted session state by shard ID 4. Update the stored seq on every dispatch, not just periodically
Can I retry after error 4007?
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.