DiscordenoShard
Documentation / @discordeno/bot / DiscordenoShard
Class: DiscordenoShard
Defined in: packages/gateway/dist/types/Shard.d.ts:7
Constructors
new DiscordenoShard()
new DiscordenoShard(
options
):DiscordenoShard
Defined in: packages/gateway/dist/types/Shard.d.ts:55
Parameters
options
Returns
Properties
bucket
bucket:
LeakyBucket
Defined in: packages/gateway/dist/types/Shard.d.ts:35
Shard bucket. Only access this if you know what you are doing. Bucket for handling shard request rate limits.
connection
connection:
ShardGatewayConfig
Defined in: packages/gateway/dist/types/Shard.d.ts:11
The connection config details that this shard will used to connect to discord.
decompressionPromisesQueue
decompressionPromisesQueue: (
data
) =>void
[]
Defined in: packages/gateway/dist/types/Shard.d.ts:47
Queue for compressed payloads for Zstd Decompress
Parameters
data
Returns
void
events
events:
ShardEvents
Defined in: packages/gateway/dist/types/Shard.d.ts:29
The shard related event handlers.
heart
heart:
ShardHeart
Defined in: packages/gateway/dist/types/Shard.d.ts:13
This contains all the heartbeat information
id
id:
number
Defined in: packages/gateway/dist/types/Shard.d.ts:9
The id of the shard.
inflate?
optional
inflate:Inflate
Defined in: packages/gateway/dist/types/Shard.d.ts:41
ZLib Inflate instance for ZLib-stream transport payloads.
inflateBuffer
inflateBuffer:
null
|Uint8Array
Defined in: packages/gateway/dist/types/Shard.d.ts:43
ZLib inflate buffer.
logger
logger:
Pick
<{debug
: (...args
) =>void
;error
: (...args
) =>void
;fatal
: (...args
) =>void
;info
: (...args
) =>void
;log
: (level
, ...args
) =>void
;setDepth
: (level
) =>void
;setLevel
: (level
) =>void
;warn
: (...args
) =>void
; },"debug"
|"info"
|"warn"
|"error"
|"fatal"
>
Defined in: packages/gateway/dist/types/Shard.d.ts:37
Logger for the bucket.
maxRequestsPerRateLimitTick
maxRequestsPerRateLimitTick:
number
Defined in: packages/gateway/dist/types/Shard.d.ts:15
The maximum of requests which can be send to discord per rate limit tick. Typically this value should not be changed.
offlineSendQueue
offlineSendQueue: () =>
void
[]
Defined in: packages/gateway/dist/types/Shard.d.ts:31
Cache for pending gateway requests which should have been send while the gateway went offline.
Returns
void
previousSequenceNumber
previousSequenceNumber:
null
|number
Defined in: packages/gateway/dist/types/Shard.d.ts:17
The previous payload sequence number.
rateLimitResetInterval
rateLimitResetInterval:
number
Defined in: packages/gateway/dist/types/Shard.d.ts:19
In which interval (in milliseconds) the gateway resets it's rate limit.
resolveAfterClose()?
optional
resolveAfterClose: (close
) =>void
Defined in: packages/gateway/dist/types/Shard.d.ts:54
Internal
A function that will be called once the socket is closed and handleClose() has finished updating internal states.
This is for internal purposes only, and subject to breaking changes.
Parameters
close
CloseEvent
Returns
void
resolves
resolves:
Map
<"READY"
|"RESUMED"
|"INVALID_SESSION"
, (payload
) =>void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:33
Resolve internal waiting states. Mapped by SelectedEvents => ResolveFunction
resumeGatewayUrl
resumeGatewayUrl:
string
Defined in: packages/gateway/dist/types/Shard.d.ts:27
The url provided by discord to use when resuming a connection for this this.
sessionId?
optional
sessionId:string
Defined in: packages/gateway/dist/types/Shard.d.ts:21
Current session id of the shard if present.
socket?
optional
socket:WebSocket
Defined in: packages/gateway/dist/types/Shard.d.ts:23
This contains the WebSocket connection to Discord, if currently connected.
state
state:
ShardState
Defined in: packages/gateway/dist/types/Shard.d.ts:25
Current internal state of the this.
textDecoder
textDecoder:
TextDecoder
Defined in: packages/gateway/dist/types/Shard.d.ts:39
Text decoder used for compressed payloads.
zstdDecompress?
optional
zstdDecompress:Decompress
Defined in: packages/gateway/dist/types/Shard.d.ts:45
ZStd Decompress instance for ZStd-stream transport payloads.
Accessors
connectionUrl
Get Signature
get connectionUrl():
string
Defined in: packages/gateway/dist/types/Shard.d.ts:59
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
gatewayConfig
Get Signature
get gatewayConfig():
ShardGatewayConfig
Defined in: packages/gateway/dist/types/Shard.d.ts:57
The gateway configuration which is used to connect to Discord.
Returns
Methods
calculateSafeRequests()
calculateSafeRequests():
number
Defined in: packages/gateway/dist/types/Shard.d.ts:61
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
checkOffline()
checkOffline(
highPriority
):Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:62
Parameters
highPriority
boolean
Returns
Promise
<void
>
close()
close(
code
,reason
):Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:64
Close the socket connection to discord if present.
Parameters
code
number
reason
string
Returns
Promise
<void
>
connect()
connect():
Promise
<DiscordenoShard
>
Defined in: packages/gateway/dist/types/Shard.d.ts:66
Connect the shard with the gateway and start heartbeating. This will not identify the shard to the gateway.
Returns
Promise
<DiscordenoShard
>
forwardToBot()
forwardToBot(
packet
):void
Defined in: packages/gateway/dist/types/Shard.d.ts:94
Parameters
packet
Returns
void
handleClose()
handleClose(
close
):Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:83
Handle a gateway connection close.
Parameters
close
CloseEvent
Returns
Promise
<void
>
handleDiscordPacket()
handleDiscordPacket(
packet
):Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:93
Handles a incoming gateway packet.
Parameters
packet
Returns
Promise
<void
>
handleError()
handleError(
error
):void
Defined in: packages/gateway/dist/types/Shard.d.ts:81
Handle a gateway connection error
Parameters
error
Event
Returns
void
handleMessage()
handleMessage(
message
):Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:85
Handle an incoming gateway message.
Parameters
message
MessageEvent
Returns
Promise
<void
>
identify()
identify():
Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:68
Identify the shard to the gateway. If not connected, this will also connect the shard to the gateway.
Returns
Promise
<void
>
isOpen()
isOpen():
boolean
Defined in: packages/gateway/dist/types/Shard.d.ts:70
Check whether the connection to Discord is currently open.
Returns
boolean
makePresence()
makePresence():
Promise
<undefined
|BotStatusUpdate
>
Defined in: packages/gateway/dist/types/Shard.d.ts:100
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
>
requestIdentify()
requestIdentify():
Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:105
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
>
resume()
resume():
Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:72
Attempt to resume the previous shards session with the gateway.
Returns
Promise
<void
>
send()
send(
message
,highPriority
?):Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:77
Send a message to Discord.
Parameters
message
highPriority?
boolean
Whether this message should be send asap.
Returns
Promise
<void
>
shardIsReady()
shardIsReady():
Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:107
This function communicates with the management process, in order to tell it can identify the next shard.
Returns
Promise
<void
>
shutdown()
shutdown():
Promise
<void
>
Defined in: packages/gateway/dist/types/Shard.d.ts:79
Shutdown the this. Forcefully disconnect the shard from Discord. The shard may not attempt to reconnect with Discord.
Returns
Promise
<void
>
startHeartbeating()
startHeartbeating(
interval
):void
Defined in: packages/gateway/dist/types/Shard.d.ts:109
Start sending heartbeat payloads to Discord in the provided interval.
Parameters
interval
number
Returns
void
stopHeartbeating()
stopHeartbeating():
void
Defined in: packages/gateway/dist/types/Shard.d.ts:111
Stop the heartbeating process with discord.
Returns
void