Gateway
Defined in: packages/ws/src/index.ts:165
Manages a Discord Gateway connection.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Gateway(
options):Gateway
Defined in: packages/ws/src/index.ts:231
Creates a Gateway connection manager.
Parameters
Section titled “Parameters”options
Section titled “options”Gateway configuration.
Returns
Section titled “Returns”Gateway
Throws
Section titled “Throws”If configuration is invalid.
Properties
Section titled “Properties”ping:
number=-1
Defined in: packages/ws/src/index.ts:229
state:
GatewayState=GatewayState.Connect
Defined in: packages/ws/src/index.ts:167
Current Gateway lifecycle state.
Methods
Section titled “Methods”close()
Section titled “close()”close():
void
Defined in: packages/ws/src/index.ts:421
Permanently closes the Gateway connection.
Returns
Section titled “Returns”void
connect()
Section titled “connect()”connect(
url?):Promise<void>
Defined in: packages/ws/src/index.ts:368
Opens the Gateway connection.
Parameters
Section titled “Parameters”string
Gateway WebSocket URL. Defaults to the URL of the last connect(), else Discord’s main Gateway.
It is remembered: reconnects that IDENTIFY dial it again, and every reconnect (including a RESUME
on resume_gateway_url) carries its query parameters (v, encoding, compress).
Returns
Section titled “Returns”Promise<void>
Promise fulfilled when the socket opens; it rejects with a GatewayError if the Gateway was permanently closed or cannot connect.
emit()
Section titled “emit()”emit(
event,data?):void
Defined in: packages/ws/src/index.ts:434
Emits an event to all registered listeners.
Parameters
Section titled “Parameters”string
Event name.
unknown
Event payload.
Returns
Section titled “Returns”void
health()
Section titled “health()”health():
GatewayHealth
Defined in: packages/ws/src/index.ts:453
A snapshot for dashboards and health checks: connection state, last heartbeat round trip, how long the link has been silent, and how many times it has reconnected.
Returns
Section titled “Returns”off(
event,listener):this
Defined in: packages/ws/src/index.ts:444
Removes a Gateway event listener.
Parameters
Section titled “Parameters”string
Event name.
listener
Section titled “listener”Event callback.
Returns
Section titled “Returns”this
This Gateway.
on(
event,listener):this
Defined in: packages/ws/src/index.ts:437
Parameters
Section titled “Parameters”string
listener
Section titled “listener”Returns
Section titled “Returns”this
ownsGuild()
Section titled “ownsGuild()”ownsGuild(
guildId):boolean
Defined in: packages/ws/src/index.ts:534
Whether guildId maps to this Gateway’s shard ((id >> 22) % shardCount === shardId).
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
Returns
Section titled “Returns”boolean
requestGuildMembers()
Section titled “requestGuildMembers()”requestGuildMembers(
data):boolean
Defined in: packages/ws/src/index.ts:544
Requests guild members.
Parameters
Section titled “Parameters”Record<string, unknown>
Guild member request payload.
Returns
Section titled “Returns”boolean
Whether it was sent.
send()
Section titled “send()”send(
payload):boolean
Defined in: packages/ws/src/index.ts:462
Sends a Gateway payload.
Parameters
Section titled “Parameters”payload
Section titled “payload”Gateway payload.
Returns
Section titled “Returns”boolean
Whether it was sent.
sendVoiceState()
Section titled “sendVoiceState()”sendVoiceState(
guildId,channelId,options?):boolean
Defined in: packages/ws/src/index.ts:520
Joins, moves or leaves a voice channel (op 4). Returns false without
sending when the guild belongs to another shard, or when disconnected.
Parameters
Section titled “Parameters”guildId
Section titled “guildId”string
Guild snowflake.
channelId
Section titled “channelId”string | null
Channel to join, or null to leave.
options?
Section titled “options?”selfMute and selfDeaf, both default false.
selfDeaf?
Section titled “selfDeaf?”boolean
selfMute?
Section titled “selfMute?”boolean
Returns
Section titled “Returns”boolean
Whether it was sent.
setPresence()
Section titled “setPresence()”setPresence(
data):boolean
Defined in: packages/ws/src/index.ts:490
Sends a presence update.
Parameters
Section titled “Parameters”Presence payload.
Returns
Section titled “Returns”boolean
Whether it was sent.
setVoiceState()
Section titled “setVoiceState()”setVoiceState(
data):boolean
Defined in: packages/ws/src/index.ts:506
Sends a voice state update.
Parameters
Section titled “Parameters”Record<string, unknown>
Voice state payload.
Returns
Section titled “Returns”boolean
Whether it was sent.