From 3d7b026f4cebc1e1caa558cce5ddbfc4d6139801 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 27 Aug 2024 14:33:22 -0600 Subject: [PATCH] add some error handling to startup in case of api breakage --- src/index.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index f3363fa..a8bda75 100644 --- a/src/index.js +++ b/src/index.js @@ -149,11 +149,15 @@ bot.once("ready", async () => { logger.info("hf:main", "Connected to Discord."); logger.info("hf:main", `Logged in as: ${formatUsername(bot.user)} (${bot.user.id})`); - const channel = await bot.getDMChannel(config.owner_id); - if (channel) { - channel.createMessage({ - content: "<:ms_tick:503341995348066313> Loaded HiddenPhox.", - }); + try { + const channel = await bot.getDMChannel(config.owner_id); + if (channel) { + channel.createMessage({ + content: "<:ms_tick:503341995348066313> Loaded HiddenPhox.", + }); + } + } catch (err) { + logger.error("hf:main", `Failed to send startup message, API probably broken currently.\n${err}`); } bot.on("ready", () => { logger.info("hf:main", "Reconnected to Discord."); @@ -170,6 +174,7 @@ bot.once("ready", async () => { } // stupid hack + // FIXME: make send optional, check if it is send const send = options.shift(); options.push(send); @@ -198,7 +203,11 @@ bot.once("ready", async () => { commands.push(formattedCommand); } - await bot.requestHandler.request("PUT", APIEndpoints.COMMANDS(bot.application.id), true, commands); + try { + await bot.requestHandler.request("PUT", APIEndpoints.COMMANDS(bot.application.id), true, commands); + } catch (err) { + logger.error("hf:main", `Failed to update interaction commands, API probably broken currently.\n${err}`); + } } });