From baef08bc9b25934de2bc815fb1978611d209e0e6 Mon Sep 17 00:00:00 2001 From: Matt Burchett Date: Wed, 22 Mar 2017 20:44:57 -0500 Subject: [PATCH] adding some disconnect code --- bot.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bot.js b/bot.js index 6164d10..136496d 100644 --- a/bot.js +++ b/bot.js @@ -48,3 +48,20 @@ client.Dispatcher.on(Events.MESSAGE_CREATE, e => { // log the guild name, the channel name, the username, and the message to the channels log chancon.info(e.message.guild.name + ":" + " #" + e.message.channel.name + ": " + "<" + e.message.displayUsername + ">: "+ e.message.content); }); + +// if connection is lost to Discord, issue a reconnect. + +client.Dispatcher.on(Events.DISCONNECTED, e => { + // set some variables for log4js + var logcon = log4js.getLogger('console'); + + // force disconnection to Discord + client.disconnect(); + logcon.info('Disconnected from server ...'); + + // reconnect to Discord + logcon.info('Reconnecting to Discord ... '); + client.connect({ + token: config.bot_token + }); +});