Opcodes and Status Codes

Gateway

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
0DispatchReceiveAn event was dispatched.
1HeartbeatSend/ReceiveFired periodically by the client to keep the connection alive.
2IdentifySendStarts a new session during the initial handshake.
3Presence UpdateSendUpdate the client's presence.
4Voice State UpdateSendUsed to join/leave or move between voice channels.
6ResumeSendResume a previous session that was disconnected.
7ReconnectReceiveYou should attempt to reconnect and resume immediately.
8Request Guild MembersSendRequest information about offline guild members in a large guild.
9Invalid SessionReceiveThe session has been invalidated. You should reconnect and identify/resume accordingly.
10HelloReceiveSent immediately after connecting, contains the heartbeat_interval to use.
11Heartbeat ACKReceiveSent in response to receiving a heartbeat to acknowledge that it has been received.
Gateway Close Event Codes
CodeDescriptionExplanation
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! You will be disconnected on receiving this.
4009Session timed outYour 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.
4012Invalid API versionYou sent an invalid version for the gateway.
4013Invalid intent(s)You sent an invalid intent for a Gateway Intent. You may have incorrectly calculated the bitwise value.
4014Disallowed intent(s)You sent a disallowed intent for a Gateway Intent. You may have tried to specify an intent that you have not enabled or are not approved for.

Voice

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 to acknowledge a received client heartbeat.
7ResumeclientResume a connection.
8HelloserverTime to wait between sending heartbeats in milliseconds.
9ResumedserverAcknowledge a successful session resume.
13Client DisconnectserverA client has disconnected from the voice channel
Voice Close Event Codes
CodeDescriptionExplanation
4001Unknown opcodeYou sent an invalid opcode.
4002Failed to decode payloadYou sent a invalid payload in your identifying to the Gateway.
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.
4014DisconnectedChannel was deleted, you were kicked, voice server changed, or the main gateway session was dropped. Should not reconnect.
4015Voice server crashedThe server crashed. Our bad! Try resuming.
4016Unknown encryption modeWe didn't recognize your encryption.

HTTP

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
CodeMeaning
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 are being rate limited, 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).

JSON

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
CodeMeaning
0General error (such as a malformed request body, amongst other things)
10001Unknown account
10002Unknown application
10003Unknown channel
10004Unknown guild
10005Unknown integration
10006Unknown invite
10007Unknown member
10008Unknown message
10009Unknown permission overwrite
10010Unknown provider
10011Unknown role
10012Unknown token
10013Unknown user
10014Unknown emoji
10015Unknown webhook
10016Unknown webhook service
10020Unknown session
10026Unknown ban
10027Unknown SKU
10028Unknown Store Listing
10029Unknown entitlement
10030Unknown build
10031Unknown lobby
10032Unknown branch
10033Unknown store directory layout
10036Unknown redistributable
10038Unknown gift code
10049Unknown stream
10050Unknown premium server subscribe cooldown
10057Unknown guild template
10059Unknown discoverable server category
10060Unknown sticker
10062Unknown interaction
10063Unknown application command
10066Unknown application command permissions
10067Unknown Stage Instance
10068Unknown Guild Member Verification Form
10069Unknown Guild Welcome Screen
10070Unknown Guild Scheduled Event
10071Unknown Guild Scheduled Event User
20001Bots cannot use this endpoint
20002Only bots can use this endpoint
20009Explicit content cannot be sent to the desired recipient(s)
20012You are not authorized to perform this action on this application
20016This action cannot be performed due to slowmode rate limit
20018Only the owner of this account can perform this action
20022This message cannot be edited due to announcement rate limits
20028The channel you are writing has hit the write rate limit
20031Your Stage topic, server name, server description, or channel names contain words that are not allowed
20035Guild premium subscription level too low
30001Maximum number of guilds reached (100)
30002Maximum number of friends reached (1000)
30003Maximum number of pins reached for the channel (50)
30004Maximum number of recipients reached (10)
30005Maximum number of guild roles reached (250)
30007Maximum number of webhooks reached (10)
30008Maximum number of emojis reached
30010Maximum number of reactions reached (20)
30013Maximum number of guild channels reached (500)
30015Maximum number of attachments in a message reached (10)
30016Maximum number of invites reached (1000)
30018Maximum number of animated emojis reached
30019Maximum number of server members reached
30030Maximum number of server categories has been reached (5)
30031Guild already has a template
30033Max number of thread participants has been reached
30035Maximum number of bans for non-guild members have been exceeded
30037Maximum number of bans fetches has been reached
30039Maximum number of stickers reached
30040Maximum number of prune requests has been reached. Try again later
40001Unauthorized. Provide a valid token and try again
40002You need to verify your account in order to perform this action
40003You are opening direct messages too fast
40005Request entity too large. Try sending something smaller in size
40006This feature has been temporarily disabled server-side
40007The user is banned from this guild
40032Target user is not connected to voice
40033This message has already been crossposted
40041An application command with that name already exists
50001Missing access
50002Invalid account type
50003Cannot execute action on a DM channel
50004Guild widget 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 for you to gain access
50010OAuth2 application does not have a bot
50011OAuth2 application limit reached
50012Invalid OAuth2 state
50013You lack permissions to perform that action
50014Invalid authentication token provided
50015Note was 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
50020Invite code was either invalid or taken
50021Cannot execute action on a system message
50024Cannot execute action on this channel type
50025Invalid OAuth2 access token provided
50026Missing required OAuth2 scope
50027Invalid webhook token provided
50028Invalid role
50033"Invalid Recipient(s)"
50034A message provided was too old to bulk delete
50035Invalid form body (returned for both application/json and multipart/form-data bodies), or invalid Content-Type provided
50036An invite was accepted to a guild the application's bot is not in
50041Invalid API version provided
50045File uploaded exceeds the maximum size
50046Invalid file uploaded
50054Cannot self-redeem this gift
50070Payment source required to redeem gift
50074Cannot delete a channel required for Community guilds
50081Invalid sticker sent
50083Tried to perform an operation on an archived thread, such as editing a message or adding a user to the thread
50084Invalid thread notification settings
50085before value is earlier than the thread creation date
50095This server is not available in your location
50097This server needs monetization enabled in order to perform this action
60003Two factor is required for this operation
80004No users with DiscordTag exist
90001Reaction was blocked
130000API resource is currently overloaded. Try again a little later
150006The Stage is already open
160002Cannot reply without permission to read message history
160004A thread has already been created for this message
160005Thread is locked
160006Maximum number of active threads reached
160007Maximum number of active announcement threads reached
170001Invalid JSON for uploaded Lottie file
170002Uploaded Lotties cannot contain rasterized images such as PNG or JPEG
170003Sticker maximum framerate exceeded
170004Sticker frame count exceeds maximum of 1000 frames
170005Lottie animation maximum dimensions exceeded
170006Sticker frame rate is either too small or too large
170007Sticker animation duration exceeds maximum of 5 seconds
Example JSON Error Response
json
{
"message": "Invalid authentication token",
"code": 50014
}

RPC

RPC is the local Discord server running on localhost. Access to the RPC server requires approval from Discord.

RPC Error Codes
CodeNameDescription
1000Unknown errorAn unknown error occurred.
4000Invalid payloadYou sent an invalid payload.
4002Invalid commandInvalid command name specified.
4003Invalid guildInvalid guild ID specified.
4004Invalid eventInvalid event name specified.
4005Invalid channelInvalid channel ID specified.
4006Invalid permissionsYou lack permissions to access the given resource.
4007Invalid client IDAn invalid OAuth2 application ID was used to authorize or authenticate with.
4008Invalid originAn invalid OAuth2 application origin was used to authorize or authenticate with.
4009Invalid tokenAn invalid OAuth2 token was used to authorize or authenticate with.
4010Invalid userThe specified user ID was invalid.
5000OAuth2 errorA standard OAuth2 error occurred; check the data object for the OAuth2 error details.
5001Select channel timed outAn asynchronous SELECT_TEXT_CHANNEL/SELECT_VOICE_CHANNEL command timed out.
5002GET_GUILD timed outAn asynchronous GET_GUILD command timed out.
5003Select voice force requiredYou tried to join a user to a voice channel but the user was already in one.
5004Capture shortcut already listeningYou tried to capture more than one shortcut key at once.
RPC Close Event Codes
CodeNameDescription
4000Invalid client IDYou connected to the RPC server with an invalid client ID.
4001Invalid originYou connected to the RPC server with an invalid origin.
4002Rate limitedYou are being rate limited.
4003Token revokedThe OAuth2 token associated with a connection was revoked, get a new one!
4004Invalid versionThe RPC Server version specified in the connection string was not valid.
4005Invalid encodingThe encoding specified in the connection string was not valid.