hopefully fix discord client going into a constant loop of disconnecting due to no ack and then reconnecting in certain situations
This commit is contained in:
parent
fb721481e7
commit
7f59b666a2
1 changed files with 4 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue