Opcodes and Status Codes


All gateway events in Discord are tagged with an opcode that denotes the payload type. Your connection to our gateway may also sometimes close. When it does, you will receive a close code that tells you what happened.
Gateway Opcodes
CodeNameClient ActionDescription
0DispatchReceivedispatches an event
1HeartbeatSend/Receiveused for ping checking
2IdentifySendused for client handshake
3Status UpdateSendused to update the client status
4Voice State UpdateSendused to join/move/leave voice channels
5Voice Server PingSendused for voice ping checking
6ResumeSendused to resume a closed connection
7ReconnectReceiveused to tell clients to reconnect to the gateway
8Request Guild MembersSendused to request guild members
9Invalid SessionReceiveused to notify client they have an invalid session id
10HelloReceivesent immediately after connecting, contains heartbeat and server debug information
11Heartbeat ACKReceivesent immediately following a client heartbeat that was received
Gateway Close Event Codes
4000unknown errorWe're not sure what went wrong. Try reconnecting?
4001unknown opcodeYou sent an invalid Gateway opcode or an invalid payload for an opcode. Don't do that!
4002decode errorYou sent an invalid payload to us. Don't do that!
4003not authenticatedYou sent us a payload prior to identifying.
4004authentication failedThe account token sent with your identify payload is incorrect.
4005already authenticatedYou sent more than one identify payload. Don't do that!
4007invalid seqThe sequence sent when resuming the session was invalid. Reconnect and start a new session.
4008rate limitedWoah nelly! You're sending payloads to us too quickly. Slow it down!
4009session timeoutYour session timed out. Reconnect and start a new one.
4010invalid shardYou sent us an invalid shard when identifying.
4011sharding requiredThe session would have handled too many guilds - you are required to shard your connection in order to connect.


Our voice gateways have their own set of opcodes and close codes.
Voice Opcodes
CodeNameSent ByDescription
0Identifyclientbegin a voice websocket connection
1Select Protocolclientselect the voice protocol
2Readyservercomplete the websocket handshake
3Heartbeatclientkeep the websocket connection alive
4Session Descriptionserverdescribe the session
5Speakingclient and serverindicate which users are speaking
6Heartbeat ACKserversent immediately following a received client heartbeat
7Resumeclientresume a connection
8Helloserverthe continuous interval in milliseconds after which the client should send a heartbeat
9Resumedserveracknowledge Resume
13Client Disconnectservera client has disconnected from the voice channel
Voice Close Event Codes
4001Unknown opcodeYou sent an invalid opcode.
4003Not authenticatedYou sent a payload before identifying with the Gateway.
4004Authentication failedThe token you sent in your identify payload is incorrect.
4005Already authenticatedYou sent more than one identify payload. Stahp.
4006Session no longer validYour session is no longer valid.
4009Session timeoutYour session has timed out.
4011Server not foundWe can't find the server you're trying to connect to.
4012Unknown ProtocolWe didn't recognize the protocol you sent.
4014DisconnectedOh no! You've been disconnected! Try resuming.
4015Voice server crashedThe server crashed. Our bad! Try resuming.
4016Unknown Encryption ModeWe didn't recognize your encryption.


Our API will return semantically valid HTTP response codes based on the success of your request. The following table can be used as a reference for response codes it will return.
HTTP Response Codes
200 (OK)The request completed successfully
201 (CREATED)The entity was created successfully
204 (NO CONTENT)The request completed successfully but returned no content
304 (NOT MODIFIED)The entity was not modified (no action was taken)
400 (BAD REQUEST)The request was improperly formatted, or the server couldn't understand it
401 (UNAUTHORIZED)The Authorization header was missing or invalid
403 (FORBIDDEN)The Authorization token you passed did not have permission to the resource
404 (NOT FOUND)The resource at the location specified doesn't exist
405 (METHOD NOT ALLOWED)The HTTP method used is not valid for the location specified
429 (TOO MANY REQUESTS)You've made too many requests, see Rate Limits
502 (GATEWAY UNAVAILABLE)There was not a gateway available to process your request. Wait a bit and retry
5xx (SERVER ERROR)The server had an error processing your request (these are rare)


Along with the HTTP error code, our API can also return more detailed error codes through a code key in the JSON error response. The response will also contain a message key containing a more friendly error string.
JSON Error Codes
10001Unknown account
10002Unknown application
10003Unknown channel
10004Unknown guild
10005Unknown integration
10006Unknown invite
10007Unknown member
10008Unknown message
10009Unknown overwrite
10010Unknown provider
10011Unknown role
10012Unknown token
10013Unknown user
10014Unknown Emoji
20001Bots cannot use this endpoint
20002Only bots can use this endpoint
30001Maximum number of guilds reached (100)
30002Maximum number of friends reached (1000)
30003Maximum number of pins reached (50)
30005Maximum number of guild roles reached (250)
30010Maximum number of reactions reached (20)
30013Maximum number of guild channels reached (500)
50001Missing access
50002Invalid account type
50003Cannot execute action on a DM channel
50004Widget Disabled
50005Cannot edit a message authored by another user
50006Cannot send an empty message
50007Cannot send messages to this user
50008Cannot send messages in a voice channel
50009Channel verification level is too high
50010OAuth2 application does not have a bot
50011OAuth2 application limit reached
50012Invalid OAuth state
50013Missing permissions
50014Invalid authentication token
50015Note is too long
50016Provided too few or too many messages to delete. Must provide at least 2 and fewer than 100 messages to delete.
50019A message can only be pinned to the channel it was sent in
50021Cannot execute action on a system message
50034A message provided was too old to bulk delete
50035Invalid Form Body
50036An invite was accepted to a guild the application's bot is not in
50041Invalid API version
90001Reaction blocked
Example JSON Error Response
    "code": 50014,
    "message": "Invalid authentication token"


RPC is the local Discord server running on localhost. Access to the RPC server is gated behind a whitelist.
RPC Error Codes
1000Unknown Errorsent when an unknown error occurred
4000Invalid Payloadsent when an invalid payload is received
4002Invalid Commandsent when the command name specified is invalid
4003Invalid Guildsent when the guild id specified is invalid
4004Invalid Eventsent when the event name specified is invalid
4005Invalid Channelsent when the channel id specified is invalid
4006Invalid Permissionssent when the user doesn't have the permission required to access the requested resource
4007Invalid Client IDsent when an invalid OAuth2 application ID is used to authorize or authenticate with
4008Invalid Originsent when an invalid OAuth2 application origin is used to authorize or authenticate with
4009Invalid Tokensent when an invalid OAuth2 token is used to authorize or authenticate with
4010Invalid Usersent when the user id specified is invalid
5000OAuth2 Errorsent when a standard OAuth2 error occurred; check the data object for the OAuth 2 error information
5001Select Channel Timed Outsent when an asyncronous SELECT_TEXT_CHANNEL/SELECT_VOICE_CHANNEL command times out
5002Get Guild Timed Outsent when an asyncronous GET_GUILD command times out
5003Select Voice Force Requiredsent when you try to join a user to a voice channel but the user is already in one
5004Capture Shortcut Already Listeningsent when you try to capture a shortcut key when already capturing one
RPC Close Event Codes
4000Invalid Client IDsent when you connect to the RPC server with an invalid client ID
4001Invalid Originsent when you connect to the RPC server with an invalid origin
4002Ratelimitedsent when the RPC Server rejects your connection to a ratelimit
4003Token Revokesent when the OAuth2 token associated with a connection is revoked
4004Invalid Versionsent when the RPC Server version specified in the connection string is not valid
4005Invalid Encodingsent when the encoding specified in the connection string is not valid