mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(WebSocketManager): available sessions check (#9823)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -293,18 +293,20 @@ export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {
|
|||||||
|
|
||||||
public async connect() {
|
public async connect() {
|
||||||
const shardCount = await this.getShardCount();
|
const shardCount = await this.getShardCount();
|
||||||
|
// Spawn shards and adjust internal state
|
||||||
|
await this.updateShardCount(shardCount);
|
||||||
|
|
||||||
|
const shardIds = await this.getShardIds();
|
||||||
const data = await this.fetchGatewayInformation();
|
const data = await this.fetchGatewayInformation();
|
||||||
if (data.session_start_limit.remaining < shardCount) {
|
|
||||||
|
if (data.session_start_limit.remaining < shardIds.length) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Not enough sessions remaining to spawn ${shardCount} shards; only ${
|
`Not enough sessions remaining to spawn ${shardIds.length} shards; only ${
|
||||||
data.session_start_limit.remaining
|
data.session_start_limit.remaining
|
||||||
} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`,
|
} remaining; resets at ${new Date(Date.now() + data.session_start_limit.reset_after).toISOString()}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, make sure all our shards are spawned
|
|
||||||
await this.updateShardCount(shardCount);
|
|
||||||
await this.strategy.connect();
|
await this.strategy.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user