From 702e9a743f0863719f0f5369fbe7dbd75ef6152f Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 16 May 2024 00:05:04 -0600 Subject: [PATCH] Add Discord log to error handling --- index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/index.js b/index.js index 4962622..779210d 100644 --- a/index.js +++ b/index.js @@ -1172,6 +1172,17 @@ process.on("unhandledRejection", (error, promise) => { } // write ./error/rejection_timestamp.txt fs.writeFileSync(`./error/rejection_${Date.now()}.txt`, `ERROR:\n${error}\n\nPROMISE:\n${JSON.stringify(promise)}`); + // Send discord log + const myGuild = discord.guilds.cache.get(config.discord.mainGuild); + const channel = myGuild.channels.cache.get(config.discord.logChannel); + channel.send({ + embeds: [ + { + description: `Unhandled Rejection\n\`\`\`${error}\n${JSON.stringify(promise)}\`\`\``, + color: 0xff0000 + } + ] + }) return; }); @@ -1183,6 +1194,17 @@ process.on("uncaughtException", (error) => { } // write ./error/exception_timestamp.txt fs.writeFileSync(`./error/exception_${Date.now()}.txt`, error.stack); + // Send message to log channel + const myGuild = discord.guilds.cache.get(config.discord.mainGuild); + const channel = myGuild.channels.cache.get(config.discord.logChannel); + channel.send({ + embeds: [ + { + description: `Uncaught Exception\n\`\`\`${error.message}\n${error.stack}\`\`\``, + color: 0xff0000 + } + ] + }) return; });