diff --git a/index.js b/index.js index f78ed57..562b653 100644 --- a/index.js +++ b/index.js @@ -171,6 +171,27 @@ class Remix { this.memberMap.set(member.id.server, data); }); + var sessionReconnects = 0; + this.client.on("ready", () => { sessionReconnects = 0; }); + this.client.on("error", (err) => { + console.log("Client error:", err); + if (err?.data?.type === "InvalidSession") { + if (sessionReconnects >= 3) { + console.log("Too many InvalidSession errors. Giving up."); + return; + } + sessionReconnects++; + console.log("InvalidSession error. Attempting to reconnect (" + sessionReconnects + "/3)..."); + setTimeout(() => { + if (config.token) { + this.client.loginBot(config.token); + } else { + this.client.login(config.login); + } + }, 5000); + } + }); + console.log("Loading command files..."); this.handler = new CommandHandler(this.client, config.prefix); this.handler.setReplyHandler((t, msg) => {