Skip to content

Commit

Permalink
Fix delete previous events with auto delete
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed May 8, 2021
1 parent 9f0470b commit e360fff
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,21 @@ UrlWatcher(urlToWatch, intervalM, async (): Promise<void> => {
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) {
console.error('Error:', err);
}
}
}
}
}).catch(err => {
console.error(`Failed to get webhook data for ${webhook}: ${err}`);
});
}
await post(<string>webhook, payload);
}
Expand Down

0 comments on commit e360fff

Please sign in to comment.