Browse Source

Revert removal of restart on unhandled exception

Turns out maybe it is actually somewhat useful after all
master
benji7425 3 years ago
parent
commit
65d2745cdc
  1. 10
      discord-bot-core/Client.js

10
discord-bot-core/Client.js

@ -32,6 +32,7 @@ module.exports = class Client extends Discord.Client {
this.on("debug", this._onDebug);
this.on("guildCreate", this._onGuildCreate);
this.on("guildDelete", this._onGuildDelete);
process.on("uncaughtException", err => this._onUnhandledException(this, err));
}
bootstrap() {
@ -70,6 +71,15 @@ module.exports = class Client extends Discord.Client {
CoreUtil.dateLog(`Removed from guild ${guild.name}, removing data for this guild`);
}
_onUnhandledException(client, err) {
CoreUtil.dateError("Unhandled exception!\n", err);
CoreUtil.dateLog("Destroying existing client...");
client.destroy().then(() => {
CoreUtil.dateLog("Client destroyed, recreating...");
setTimeout(() => client.login(client._token), InternalConfig.reconnectTimeout);
});
}
};
function compactCollections() {

Loading…
Cancel
Save