From 7f59b666a27a914ab8b1125f57b44bda02a7030d Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Fri, 25 Feb 2022 20:00:17 +0200 Subject: [PATCH] hopefully fix discord client going into a constant loop of disconnecting due to no ack and then reconnecting in certain situations --- src/DiscordClient.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/DiscordClient.js b/src/DiscordClient.js index 6c8338b..bcbc7bf 100644 --- a/src/DiscordClient.js +++ b/src/DiscordClient.js @@ -22,6 +22,8 @@ const skipReconnectFor = [ 4004, 4010, 4011, 4012, 4013, 4014 ]; +const CLOSE_CONNECTION_ON_NO_ACK = false; + class DiscordClient extends EventEmitter { constructor(token, { intents, gatewayUrl="wss://gateway.discord.gg/?v=9&encoding=json&compress=zlib-stream", apiBase="https://discord.com/api/v9" } = {}) { super(); @@ -48,7 +50,7 @@ class DiscordClient extends EventEmitter { } this._heartbeatInterval = setInterval(() => { - if (!this.gotServerHeartbeatACK) { + if (CLOSE_CONNECTION_ON_NO_ACK && !this.gotServerHeartbeatACK) { logError("Closing due to no heartbeat ACK..."); this.ws.close(1000, "No heartbeat ACK."); return; @@ -224,6 +226,7 @@ class DiscordClient extends EventEmitter { if (this.ws) { log("a websocket connection already exists, killing..."); this.ws.removeAllListeners(); + this._setHeartbeat(-1); this.ws.close(); this.ws = null; }