Skip to main content

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.
31Request Soundboard SoundsSendRequest information about soundboard sounds in a set of guilds.
Gateway Close Event Codes
In order to prevent broken reconnect loops, you should consider some close codes as a signal to stop reconnecting. This can be because your token expired, or your identification is invalid. This table explains what the application defined close codes for the gateway are, and which close codes you should not attempt to reconnect.
CodeDescriptionExplanationReconnect
4000Unknown errorWe’re not sure what went wrong. Try reconnecting?true
4001Unknown opcodeYou sent an invalid Gateway opcode or an invalid payload for an opcode. Don’t do that!true
4002Decode errorYou sent an invalid payload to Discord. Don’t do that!true
4003Not authenticatedYou sent us a payload prior to identifying, or this session has been invalidated.true
4004Authentication failedThe account token sent with your identify payload is incorrect.false
4005Already authenticatedYou sent more than one identify payload. Don’t do that!true
4007Invalid seqThe sequence sent when resuming the session was invalid. Reconnect and start a new session.true
4008Rate limitedWoah nelly! You’re sending payloads to us too quickly. Slow it down! You will be disconnected on receiving this.true
4009Session timed outYour session timed out. Reconnect and start a new one.true
4010Invalid shardYou sent us an invalid shard when identifying.false
4011Sharding requiredThe session would have handled too many guilds - you are required to shard your connection in order to connect.false
4012Invalid API versionYou sent an invalid version for the gateway.false
4013Invalid intent(s)You sent an invalid intent for a Gateway Intent. You may have incorrectly calculated the bitwise value.false
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.false

Voice

Our voice gateways have their own set of opcodes and close codes.
Voice Opcodes
CodeNameSent ByDescriptionBinary
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.
11Clients ConnectserverOne or more clients have connected to the voice channel
13Client DisconnectserverA client has disconnected from the voice channel
21DAVE Prepare TransitionserverA downgrade from the DAVE protocol is upcoming
22DAVE Execute TransitionserverExecute a previously announced protocol transition
23DAVE Transition ReadyclientAcknowledge readiness previously announced transition
24DAVE Prepare EpochserverA DAVE protocol version or group change is upcoming
25DAVE MLS External SenderserverCredential and public key for MLS external senderX
26DAVE MLS Key PackageclientMLS Key Package for pending group memberX
27DAVE MLS ProposalsserverMLS Proposals to be appended or revokedX
28DAVE MLS Commit WelcomeclientMLS Commit with optional MLS Welcome messagesX
29DAVE MLS Announce Commit TransitionserverMLS Commit to be processed for upcoming transitionX
30DAVE MLS WelcomeserverMLS Welcome to group for upcoming transitionX
31DAVE MLS Invalid Commit WelcomeclientFlag invalid commit or welcome, request re-add
Voice Close Event Codes
CodeDescriptionExplanation
4001Unknown opcodeYou sent an invalid opcode.
4002Failed to decode payloadYou sent an 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.
4014DisconnectedDisconnect individual client (you were kicked, the main gateway session was dropped, etc.). Should not reconnect.
4015Voice server crashedThe server crashed. Our bad! Try resuming.
4016Unknown encryption modeWe didn’t recognize your encryption.
4020Bad requestYou sent a malformed request
4021Disconnected: Rate LimitedDisconnect due to rate limit exceeded. Should not reconnect.
4022Disconnected: Call TerminatedDisconnect all clients due to call terminated (channel deleted, voice server changed, etc.). Should not reconnect.

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. Some of these errors may include additional details in the form of Error Messages provided by an errors object.
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
10021Unknown Asset
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
10061Unknown sticker pack
10062Unknown interaction
10063Unknown application command
10065Unknown voice state
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
10087Unknown Tag
10097Unknown sound
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
20024Under minimum age
20028The channel you are writing has hit the write rate limit
20029The write action you are performing on the server 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 (15)
30008Maximum number of emojis reached
30010Maximum number of reactions reached (20)
30011Maximum number of group DMs reached (10)
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
30032Maximum number of application commands reached
30033Maximum number of thread participants has been reached (1000)
30034Maximum number of daily application command creates has been reached (200)
30035Maximum number of bans for non-guild members have been exceeded
30037Maximum number of bans fetches has been reached
30038Maximum number of uncompleted guild scheduled events reached (100)
30039Maximum number of stickers reached
30040Maximum number of prune requests has been reached. Try again later
30042Maximum number of guild widget settings updates has been reached. Try again later
30045Maximum number of soundboard sounds reached
30046Maximum number of edits to messages older than 1 hour reached. Try again later
30047Maximum number of pinned threads in a forum channel has been reached
30048Maximum number of tags in a forum channel has been reached
30052Bitrate is too high for channel of this type
30056Maximum number of premium emojis reached (25)
30058Maximum number of webhooks per guild reached (1000)
30060Maximum number of channel permission overwrites reached (1000)
30061The channels for this guild are too large
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
40004Send messages has been temporarily disabled
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
40012Connection has been revoked
40018Only consumable SKUs can be consumed
40019You can only delete sandbox entitlements.
40032Target user is not connected to voice
40033This message has already been crossposted
40041An application command with that name already exists
40043Application interaction failed to send
40058Cannot send a message in a forum channel
40060Interaction has already been acknowledged
40061Tag names must be unique
40062Service resource is being rate limited
40066There are no tags available that can be set by non-moderators
40067A tag is required to create a forum post in this channel
40074An entitlement has already been granted for this resource
40094This interaction has hit the maximum number of follow up messages
40333Cloudflare is blocking your request. This can often be resolved by setting a proper User Agent
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 non-text 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
50017Invalid MFA Level
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
50033Invalid 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
50039Invalid Activity Action
50041Invalid API version provided
50045File uploaded exceeds the maximum size
50046Invalid file uploaded
50054Cannot self-redeem this gift
50055Invalid Guild
50057Invalid SKU
50067Invalid request origin
50068Invalid message type
50070Payment source required to redeem gift
50073Cannot modify a system webhook
50074Cannot delete a channel required for Community guilds
50080Cannot edit stickers within a message
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
50086Community server channels must be text channels
50091The entity type of the event is different from the entity you are trying to start the event for
50095This server is not available in your location
50097This server needs monetization enabled in order to perform this action
50101This server needs more boosts to perform this action
50109The request body contains invalid JSON.
50110The provided file is invalid.
50123The provided file type is invalid.
50124The provided file duration exceeds maximum of 5.2 seconds.
50131Owner cannot be pending member
50132Ownership cannot be transferred to a bot user
50138Failed to resize asset below the maximum size: 262144
50144Cannot mix subscription and non subscription roles for an emoji
50145Cannot convert between premium emoji and normal emoji
50146Uploaded file not found.
50151The specified emoji is invalid
50159Voice messages do not support additional content.
50160Voice messages must have a single audio attachment.
50161Voice messages must have supporting metadata.
50162Voice messages cannot be edited.
50163Cannot delete guild subscription integration
50173You cannot send voice messages in this channel.
50178The user account must first be verified
50192The provided file does not have a valid duration.
50600You do not have permission to send this sticker.
60003Two factor is required for this operation
80004No users with DiscordTag exist
90001Reaction was blocked
90002User cannot use burst reactions
110001Application not yet available. Try again later
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
180000Cannot update a finished event
180002Failed to create stage needed for stage event
200000Message was blocked by automatic moderation
200001Title was blocked by automatic moderation
220001Webhooks posted to forum channels must have a thread_name or thread_id
220002Webhooks posted to forum channels cannot have both a thread_name and thread_id
220003Webhooks can only create threads in forum channels
220004Webhook services cannot be used in forum channels
240000Message blocked by harmful links filter
350000Cannot enable onboarding, requirements are not met
350001Cannot update onboarding while below requirements
400001Access to file uploads has been limited for this guild
500000Failed to ban users
520000Poll voting blocked
520001Poll expired
520002Invalid channel type for poll creation
520003Cannot edit a poll message
520004Cannot use an emoji included with the poll
520006Cannot expire a non-poll message
Example JSON Error Response
{
  "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.