Module: Discordrb::Opcodes

Defined in:
lib/discordrb/gateway.rb

Overview

Gateway packet opcodes

Constant Summary collapse

DISPATCH =

Received when Discord dispatches an event to the gateway (like MESSAGE_CREATE, PRESENCE_UPDATE or whatever). The vast majority of received packets will have this opcode.

0
HEARTBEAT =

Two-way: The client has to send a packet with this opcode every ~40 seconds (actual interval specified in READY or RESUMED) and the current sequence number, otherwise it will be disconnected from the gateway. In certain cases Discord may also send one, specifically if two clients are connected at once.

1
IDENTIFY =

Sent: This is one of the two possible ways to initiate a session after connecting to the gateway. It should contain the authentication token along with other stuff the server has to know right from the start, such as large_threshold and, for older gateway versions, the desired version.

2
PRESENCE =

Sent: Packets with this opcode are used to change the user's status and played game. (Sending this is never necessary for a gateway client to behave correctly)

3
VOICE_STATE =

Sent: Packets with this opcode are used to change a user's voice state (mute/deaf/unmute/undeaf/etc.). It is also used to connect to a voice server in the first place. (Sending this is never necessary for a gateway client to behave correctly)

4
VOICE_PING =

Sent: This opcode is used to ping a voice server, whatever that means. The functionality of this opcode isn't known well but non-user clients should never send it.

5
RESUME =

Sent: This is the other of two possible ways to initiate a gateway session (other than IDENTIFY). Rather than starting an entirely new session, it resumes an existing session by replaying all events from a given sequence number. It should be used to recover from a connection error or anything like that when the session is still valid - sending this with an invalid session will cause an error to occur.

6
RECONNECT =

Received: Discord sends this opcode to indicate that the client should reconnect to a different gateway server because the old one is currently being decommissioned. Counterintuitively, this opcode also invalidates the session - the client has to create an entirely new session with the new gateway instead of resuming the old one.

7
REQUEST_MEMBERS =

Sent: This opcode identifies packets used to retrieve a list of members from a particular server. There is also a REST endpoint available for this, but it is inconvenient to use because the client has to implement pagination itself, whereas sending this opcode lets Discord handle the pagination and the client can just add members when it receives them. (Sending this is never necessary for a gateway client to behave correctly)

8
INVALIDATE_SESSION =

Received: Sent by Discord when the session becomes invalid for any reason. This may include improperly resuming existing sessions, attempting to start sessions with invalid data, or something else entirely. The client should handle this by simply starting a new session.

9
HELLO =

Received: Sent immediately for any opened connection; tells the client to start heartbeating early on, so the server can safely search for a session server to handle the connection without the connection being terminated. As a side-effect, large bots are less likely to disconnect because of very large READY parse times.

10
HEARTBEAT_ACK =

Received: Returned after a heartbeat was sent to the server. This allows clients to identify and deal with zombie connections that don't dispatch any events anymore.

11