From 8099fd7ac494c12860145f021c46326a1c784ea0 Mon Sep 17 00:00:00 2001 From: destruc7i0n Date: Wed, 29 Dec 2021 16:57:59 -0500 Subject: fallback to bot message if webhook fails --- src/Discord.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Discord.ts b/src/Discord.ts index 3a4dab8..8071d7e 100644 --- a/src/Discord.ts +++ b/src/Discord.ts @@ -292,17 +292,20 @@ class Discord { const webhook = await this.makeDiscordWebhook(username, message) try { await axios.post(this.config.WEBHOOK_URL, webhook, { headers: { 'Content-Type': 'application/json' } }) + return } catch (e) { - console.log('[ERROR] Could not send Discord message through WebHook!') + console.log('[ERROR] Could not send Discord message through WebHook! Falling back to sending through bot.') if (this.config.DEBUG) console.log(e) } - } else { - try { - await this.channel!.send(this.makeDiscordMessage(username, message)) - } catch (e) { - console.log('[ERROR] Could not send Discord message through bot!') - process.exit(1) - } + } + + const messageContent = this.makeDiscordMessage(username, message) + + try { + await this.channel!.send(messageContent) + } catch (e) { + console.log('[ERROR] Could not send Discord message through bot!') + process.exit(1) } } } -- cgit 1.4.1