DiscordenoShard
@discordeno/gateway • Docs
Documentation / @discordeno/gateway / DiscordenoShard
Class: DiscordenoShard
Constructors
new DiscordenoShard()
new DiscordenoShard(
options
):DiscordenoShard
Parameters
• options: ShardCreateOptions
Returns
Defined in
Properties
bucket
bucket:
LeakyBucket
Shard bucket. Only access this if you know what you are doing. Bucket for handling shard request rate limits.
Defined in
connection
connection:
ShardGatewayConfig
The connection config details that this shard will used to connect to discord.
Defined in
decompressionPromisesQueue
decompressionPromisesQueue: (
data
) =>void
[] =[]
Queue for compressed payloads for Zstd Decompress
Defined in
events
events:
ShardEvents
={}
The shard related event handlers.
Defined in
heart
heart:
ShardHeart
This contains all the heartbeat information
Defined in
id
id:
number
The id of the shard
Defined in
inflate?
optional
inflate:Inflate
ZLib Inflate instance for ZLib-stream transport payloads
Defined in
inflateBuffer
inflateBuffer:
null
|Uint8Array
=null
ZLib inflate buffer
Defined in
logger
logger:
Pick
<object
,"debug"
|"info"
|"warn"
|"error"
|"fatal"
>
Logger for the bucket
Type declaration
debug()
debug: (...
args
) =>void
Parameters
• ...args: any
[]
Returns
void
error()
error: (...
args
) =>void
Parameters
• ...args: any
[]
Returns
void
fatal()
fatal: (...
args
) =>void
Parameters
• ...args: any
[]
Returns
void
info()
info: (...
args
) =>void
Parameters
• ...args: any
[]
Returns
void
log()
log: (
level
, ...args
) =>void
Parameters
• level: LogLevels
• ...args: any
[]
Returns
void
setDepth()
setDepth: (
level
) =>void
Parameters
• level: LogDepth
Returns
void
setLevel()
setLevel: (
level
) =>void
Parameters
• level: LogLevels
Returns
void
warn()
warn: (...
args
) =>void
Parameters
• ...args: any
[]
Returns
void
Defined in
maxRequestsPerRateLimitTick
maxRequestsPerRateLimitTick:
number
=120
The maximum of requests which can be send to discord per rate limit tick. Typically this value should not be changed.
Defined in
offlineSendQueue
offlineSendQueue: () =>
void
[] =[]
Cache for pending gateway requests which should have been send while the gateway went offline.
Defined in
previousSequenceNumber
previousSequenceNumber:
null
|number
=null
The previous payload sequence number.
Defined in
rateLimitResetInterval
rateLimitResetInterval:
number
=60000
In which interval (in milliseconds) the gateway resets it's rate limit.
Defined in
resolves
resolves:
Map
<"READY"
|"RESUMED"
|"INVALID_SESSION"
, (payload
) =>void
>
Resolve internal waiting states. Mapped by SelectedEvents => ResolveFunction
Defined in
resumeGatewayUrl
resumeGatewayUrl:
string
=''
The url provided by discord to use when resuming a connection for this this.
Defined in
sessionId?
optional
sessionId:string
Current session id of the shard if present.
Defined in
socket?
optional
socket:WebSocket
This contains the WebSocket connection to Discord, if currently connected.
Defined in
state
state:
ShardState
=ShardState.Offline
Current internal state of the this.
Defined in
textDecoder
textDecoder:
TextDecoder
Text decoder used for compressed payloads
Defined in
zstdDecompress?
optional
zstdDecompress:Decompress
ZStd Decompress instance for ZStd-stream transport payloads
Defined in
Accessors
connectionUrl
Get Signature
get connectionUrl():
string
The url to connect to. Initially this is the discord gateway url, and then is switched to resume gateway url once a READY is received.
Returns
string
Defined in
gatewayConfig
Get Signature
get gatewayConfig():
ShardGatewayConfig
The gateway configuration which is used to connect to Discord.
Returns
Defined in
Methods
calculateSafeRequests()
calculateSafeRequests():
number
Calculate the amount of requests which can safely be made per rate limit interval, before the gateway gets disconnected due to an exceeded rate limit.
Returns
number
Defined in
checkOffline()
checkOffline(
highPriority
):Promise
<void
>
Parameters
• highPriority: boolean
Returns
Promise
<void
>
Defined in
close()
close(
code
,reason
):void
Close the socket connection to discord if present.
Parameters
• code: number
• reason: string
Returns
void
Defined in
connect()
connect():
Promise
<DiscordenoShard
>
Connect the shard with the gateway and start heartbeating. This will not identify the shard to the gateway.
Returns
Promise
<DiscordenoShard
>
Defined in
forwardToBot()
forwardToBot(
packet
):void
Parameters
• packet: DiscordGatewayPayload
Returns
void
Defined in
handleClose()
handleClose(
close
):Promise
<void
>
Handle a gateway connection close.
Parameters
• close: CloseEvent
Returns
Promise
<void
>
Defined in
handleDiscordPacket()
handleDiscordPacket(
packet
):Promise
<void
>
Handles a incoming gateway packet.
Parameters
• packet: DiscordGatewayPayload
Returns
Promise
<void
>
Defined in
handleError()
handleError(
error
):void
Handle a gateway connection error
Parameters
• error: Event
Returns
void
Defined in
handleMessage()
handleMessage(
message
):Promise
<void
>
Handle an incoming gateway message.
Parameters
• message: MessageEvent
<any
>
Returns
Promise
<void
>
Defined in
identify()
identify():
Promise
<void
>
Identify the shard to the gateway. If not connected, this will also connect the shard to the gateway.
Returns
Promise
<void
>
Defined in
isOpen()
isOpen():
boolean
Check whether the connection to Discord is currently open.
Returns
boolean
Defined in
makePresence()
makePresence():
Promise
<undefined
|BotStatusUpdate
>
Override in order to make the shards presence. async in case devs create the presence based on eg. database values. Passing the shard's id there to make it easier for the dev to use this function.
Returns
Promise
<undefined
| BotStatusUpdate
>
Defined in
requestIdentify()
requestIdentify():
Promise
<void
>
This function communicates with the management process, in order to know whether its free to identify. When this function resolves, this means that the shard is allowed to send an identify payload to discord.
Returns
Promise
<void
>
Defined in
resume()
resume():
Promise
<void
>
Attempt to resume the previous shards session with the gateway.
Returns
Promise
<void
>
Defined in
send()
send(
message
,highPriority
):Promise
<void
>
Send a message to Discord.
Parameters
• message: ShardSocketRequest
• highPriority: boolean
= false
Whether this message should be send asap.
Returns
Promise
<void
>
Defined in
shardIsReady()
shardIsReady():
Promise
<void
>
This function communicates with the management process, in order to tell it can identify the next shard.
Returns
Promise
<void
>
Defined in
shutdown()
shutdown():
Promise
<void
>
Shutdown the this. Forcefully disconnect the shard from Discord. The shard may not attempt to reconnect with Discord.
Returns
Promise
<void
>
Defined in
startHeartbeating()
startHeartbeating(
interval
):void
Start sending heartbeat payloads to Discord in the provided interval.
Parameters
• interval: number
Returns
void
Defined in
stopHeartbeating()
stopHeartbeating():
void
Stop the heartbeating process with discord.
Returns
void