Skip to content

Commit 37ef57b

Browse files
authored
fix(WebSocketManager): always emit shardDisconnect on unresumable close (#10826)
1 parent e3c247e commit 37ef57b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/discord.js/src/client/websocket/WebSocketManager.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ const BeforeReadyWhitelist = [
3636

3737
const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
3838

39-
const UNRESUMABLE_CLOSE_CODES = [
40-
CloseCodes.Normal,
41-
GatewayCloseCodes.AlreadyAuthenticated,
42-
GatewayCloseCodes.InvalidSeq,
39+
const UNRECOVERABLE_CLOSE_CODES = [
40+
GatewayCloseCodes.AuthenticationFailed,
41+
GatewayCloseCodes.InvalidShard,
42+
GatewayCloseCodes.ShardingRequired,
43+
GatewayCloseCodes.InvalidAPIVersion,
44+
GatewayCloseCodes.InvalidIntents,
45+
GatewayCloseCodes.DisallowedIntents,
4346
];
4447

4548
const reasonIsDeprecated = 'the reason property is deprecated, use the code property to determine the reason';
@@ -242,7 +245,7 @@ class WebSocketManager extends EventEmitter {
242245
this._ws.on(WSWebSocketShardEvents.Closed, ({ code, shardId }) => {
243246
const shard = this.shards.get(shardId);
244247
shard.emit(WebSocketShardEvents.Close, { code, reason: reasonIsDeprecated, wasClean: true });
245-
if (UNRESUMABLE_CLOSE_CODES.includes(code) && this.destroyed) {
248+
if (UNRECOVERABLE_CLOSE_CODES.includes(code)) {
246249
shard.status = Status.Disconnected;
247250
/**
248251
* Emitted when a shard's WebSocket disconnects and will no longer reconnect.
@@ -251,7 +254,7 @@ class WebSocketManager extends EventEmitter {
251254
* @param {number} id The shard id that disconnected
252255
*/
253256
this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId);
254-
this.debug([`Shard not resumable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`], shardId);
257+
this.debug([`Shard not recoverable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`], shardId);
255258
return;
256259
}
257260

0 commit comments

Comments
 (0)