DiscordenoShard
@discordeno/bot • Docs
Documentation / @discordeno/bot / DiscordenoShard
Class: DiscordenoShard
Constructors
new DiscordenoShard()
new DiscordenoShard(
options
):DiscordenoShard
Parameters
• options: ShardCreateOptions
Returns
Defined in
packages/gateway/dist/types/Shard.d.ts:48
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
packages/gateway/dist/types/Shard.d.ts:35
connection
connection:
ShardGatewayConfig
The connection config details that this shard will used to connect to discord.
Defined in
packages/gateway/dist/types/Shard.d.ts:11
decompressionPromisesQueue
decompressionPromisesQueue: (
data
) =>void
[]
Queue for compressed payloads for Zstd Decompress
Defined in
packages/gateway/dist/types/Shard.d.ts:47
events
events:
ShardEvents
The shard related event handlers.
Defined in
packages/gateway/dist/types/Shard.d.ts:29
heart
heart:
ShardHeart
This contains all the heartbeat information
Defined in
packages/gateway/dist/types/Shard.d.ts:13
id
id:
number
The id of the shard
Defined in
packages/gateway/dist/types/Shard.d.ts:9
inflate?
optional
inflate:Inflate
ZLib Inflate instance for ZLib-stream transport payloads
Defined in
packages/gateway/dist/types/Shard.d.ts:41
inflateBuffer
inflateBuffer:
null
|Uint8Array
ZLib inflate buffer
Defined in
packages/gateway/dist/types/Shard.d.ts:43
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
packages/gateway/dist/types/Shard.d.ts:37
maxRequestsPerRateLimitTick
maxRequestsPerRateLimitTick:
number
The maximum of requests which can be send to discord per rate limit tick. Typically this value should not be changed.
Defined in
packages/gateway/dist/types/Shard.d.ts:15
offlineSendQueue
offlineSendQueue: () =>
void
[]
Cache for pending gateway requests which should have been send while the gateway went offline.
Defined in
packages/gateway/dist/types/Shard.d.ts:31
previousSequenceNumber
previousSequenceNumber:
null
|number
The previous payload sequence number.
Defined in
packages/gateway/dist/types/Shard.d.ts:17
rateLimitResetInterval
rateLimitResetInterval:
number
In which interval (in milliseconds) the gateway resets it's rate limit.
Defined in
packages/gateway/dist/types/Shard.d.ts:19
resolves
resolves:
Map
<"READY"
|"RESUMED"
|"INVALID_SESSION"
, (payload
) =>void
>
Resolve internal waiting states. Mapped by SelectedEvents => ResolveFunction
Defined in
packages/gateway/dist/types/Shard.d.ts:33
resumeGatewayUrl
resumeGatewayUrl:
string
The url provided by discord to use when resuming a connection for this this.
Defined in
packages/gateway/dist/types/Shard.d.ts:27
sessionId?
optional
sessionId:string
Current session id of the shard if present.
Defined in
packages/gateway/dist/types/Shard.d.ts:21
socket?
optional
socket:WebSocket
This contains the WebSocket connection to Discord, if currently connected.
Defined in
packages/gateway/dist/types/Shard.d.ts:23
state
state:
ShardState
Current internal state of the this.
Defined in
packages/gateway/dist/types/Shard.d.ts:25
textDecoder
textDecoder:
TextDecoder
Text decoder used for compressed payloads
Defined in
packages/gateway/dist/types/Shard.d.ts:39
zstdDecompress?
optional
zstdDecompress:Decompress
ZStd Decompress instance for ZStd-stream transport payloads
Defined in
packages/gateway/dist/types/Shard.d.ts:45
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
packages/gateway/dist/types/Shard.d.ts:52
gatewayConfig
Get Signature
get gatewayConfig():
ShardGatewayConfig
The gateway configuration which is used to connect to Discord.
Returns
Defined in
packages/gateway/dist/types/Shard.d.ts:50
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
packages/gateway/dist/types/Shard.d.ts:54
checkOffline()
checkOffline(
highPriority
):Promise
<void
>
Parameters
• highPriority: boolean
Returns
Promise
<void
>
Defined in
packages/gateway/dist/types/Shard.d.ts:55
close()
close(
code
,reason
):void
Close the socket connection to discord if present.
Parameters
• code: number
• reason: string
Returns
void
Defined in
packages/gateway/dist/types/Shard.d.ts:57
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
packages/gateway/dist/types/Shard.d.ts:59
forwardToBot()
forwardToBot(
packet
):void
Parameters
• packet: DiscordGatewayPayload
Returns
void
Defined in
packages/gateway/dist/types/Shard.d.ts:87
handleClose()
handleClose(
close
):Promise
<void
>
Handle a gateway connection close.
Parameters
• close: CloseEvent
Returns
Promise
<void
>
Defined in
packages/gateway/dist/types/Shard.d.ts:76
handleDiscordPacket()
handleDiscordPacket(
packet
):Promise
<void
>
Handles a incoming gateway packet.
Parameters
• packet: DiscordGatewayPayload
Returns
Promise
<void
>
Defined in
packages/gateway/dist/types/Shard.d.ts:86
handleError()
handleError(
error
):void
Handle a gateway connection error
Parameters
• error: Event
Returns
void
Defined in
packages/gateway/dist/types/Shard.d.ts:74
handleMessage()
handleMessage(
message
):Promise
<void
>
Handle an incoming gateway message.
Parameters
• message: MessageEvent
<any
>
Returns
Promise
<void
>
Defined in
packages/gateway/dist/types/Shard.d.ts:78
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
packages/gateway/dist/types/Shard.d.ts:61
isOpen()
isOpen():
boolean
Check whether the connection to Discord is currently open.
Returns
boolean
Defined in
packages/gateway/dist/types/Shard.d.ts:63
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
packages/gateway/dist/types/Shard.d.ts:93
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
packages/gateway/dist/types/Shard.d.ts:98
resume()
resume():
Promise
<void
>
Attempt to resume the previous shards session with the gateway.
Returns
Promise
<void
>
Defined in
packages/gateway/dist/types/Shard.d.ts:65
send()
send(
message
,highPriority
?):Promise
<void
>
Send a message to Discord.
Parameters
• message: ShardSocketRequest
• highPriority?: boolean
Whether this message should be send asap.
Returns
Promise
<void
>
Defined in
packages/gateway/dist/types/Shard.d.ts:70
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
packages/gateway/dist/types/Shard.d.ts:100
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
packages/gateway/dist/types/Shard.d.ts:72
startHeartbeating()
startHeartbeating(
interval
):void
Start sending heartbeat payloads to Discord in the provided interval.
Parameters
• interval: number
Returns
void
Defined in
packages/gateway/dist/types/Shard.d.ts:102
stopHeartbeating()
stopHeartbeating():
void
Stop the heartbeating process with discord.
Returns
void
Defined in
packages/gateway/dist/types/Shard.d.ts:104