Skip to content

Commit

Permalink
feat: inform users of disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Max committed Dec 4, 2021
1 parent be1d33e commit 26427d0
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,34 @@ bot.on('guildDelete', guild => {
console.log(`[G ${guild.id}] Left ${guild.name}`);
});

bot.login(token);
bot.login(token);

let inprg = false;
async function shuttingDown() {
if (inprg) return;
inprg = true;
console.log('[Warden] Shutting down...');
if (startup) {
console.log('[Warden] Disconnecting from all guilds...');
for (const pair of bot.music.players) {
const player = pair[1];
console.log(`[G ${player.guildId}] Disconnecting (restarting)`);
await player.queue.channel.send({
embeds: [
new MessageEmbed()
.setDescription('Warden is restarting and will disconnect.')
.setFooter('Sorry for the inconvenience caused.')
.setColor(defaultColor),
],
});
player.disconnect();
bot.music.destroyPlayer(player.guildId);
}
}
bot.destroy();
process.exit();
}

['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM'].forEach(eventType => {
process.on(eventType, shuttingDown);
});

0 comments on commit 26427d0

Please sign in to comment.