From e360fff88f62b1dff7c4d38fe5e3d0c59331c47e Mon Sep 17 00:00:00 2001 From: versx Date: Fri, 7 May 2021 19:27:28 -0700 Subject: [PATCH] Fix delete previous events with auto delete --- src/index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 65191e5..80ac8de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -174,12 +174,11 @@ UrlWatcher(urlToWatch, intervalM, async (): Promise => { for (const webhook of config.webhooks) { // Delete previous event messages if set if (config.deletePreviousEvents) { - const whData = await getWebhookData(webhook); - if (whData != null) { - const guild = client.guilds.cache.get(whData.guild_id); - if (guild) { - const channel = guild.channels.cache.get(whData.channel_id); - if (channel) { + getWebhookData(webhook)?.then(whData => { + if (whData?.guild_id && whData?.channel_id) { + const guild = client.guilds.cache.get(whData.guild_id); + if (guild) { + const channel = guild.channels.cache.get(whData.channel_id); try { (channel as TextChannel).bulkDelete(100); } catch (err) { @@ -187,7 +186,9 @@ UrlWatcher(urlToWatch, intervalM, async (): Promise => { } } } - } + }).catch(err => { + console.error(`Failed to get webhook data for ${webhook}: ${err}`); + }); } await post(webhook, payload); }