Revert removal of restart on unhandled exception

Turns out maybe it is actually somewhat useful after all
This commit is contained in:
benji7425 2017-12-07 00:19:16 +00:00
parent 9c0602bbb6
commit 65d2745cdc
1 changed files with 10 additions and 0 deletions

View File

@ -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() {