diff --git a/src/handlers/cron/deliverUpdates.ts b/src/handlers/cron/deliverUpdates.ts index 2cdff84..eddb526 100644 --- a/src/handlers/cron/deliverUpdates.ts +++ b/src/handlers/cron/deliverUpdates.ts @@ -11,6 +11,7 @@ import {config, helldiversConfig} from '../../config'; import {planetNameTransform} from '../custom'; import {validateChannelArr} from '../discord'; import {majorOrderEmbed} from '../embed'; +import {logger} from '../logging'; const {SUBSCRIBE_FOOTER} = config; const {factionSprites, altSprites} = helldiversConfig; @@ -58,7 +59,13 @@ export async function newCampaignUpdate( ]; // send new updates to subscribed channels const promises: Promise[] = []; - for (const channel of channels) promises.push(channel.send({embeds})); + for (const channel of channels) { + try { + await channel.send({embeds}); + } catch (err) { + logger.error(err); + } + } await Promise.all(promises); return; } @@ -123,7 +130,14 @@ export async function wonPlanetUpdate( ]; // send new updates to subscribed channels const promises: Promise[] = []; - for (const channel of channels) promises.push(channel.send({embeds})); + for (const channel of channels) { + try { + await channel.send({embeds}); + } catch (err) { + logger.error(err); + } + } + await Promise.all(promises); return; } @@ -188,7 +202,13 @@ export async function lostPlanetUpdate( ]; // send new updates to subscribed channels const promises: Promise[] = []; - for (const channel of channels) promises.push(channel.send({embeds})); + for (const channel of channels) { + try { + await channel.send({embeds}); + } catch (err) { + logger.error(err); + } + } await Promise.all(promises); return; } @@ -209,8 +229,13 @@ export async function newEventUpdate(event: GlobalEvent, channelIds: string[]) { // send new updates to subscribed channels const promises: Promise[] = []; - for (const channel of channels) - promises.push(channel.send({embeds: [eventEmbed]})); + for (const channel of channels) { + try { + await channel.send({embeds: [eventEmbed]}); + } catch (err) { + logger.error(err); + } + } await Promise.all(promises); return; } @@ -226,7 +251,13 @@ export async function newMajorOrderUpdater( // send new updates to subscribed channels const promises: Promise[] = []; - for (const channel of channels) promises.push(channel.send({embeds: embeds})); + for (const channel of channels) { + try { + await channel.send({embeds}); + } catch (err) { + logger.error(err); + } + } await Promise.all(promises); return; } diff --git a/src/handlers/discord/channels.ts b/src/handlers/discord/channels.ts index 0489118..bdee7bf 100644 --- a/src/handlers/discord/channels.ts +++ b/src/handlers/discord/channels.ts @@ -1,17 +1,29 @@ -import {TextChannel, PublicThreadChannel, ChannelType} from 'discord.js'; +import { + TextChannel, + PublicThreadChannel, + ChannelType, + DiscordAPIError, +} from 'discord.js'; import {client} from '../client'; +import {logger} from '../logging'; export async function validateChannel( id: string ): Promise { - const channel = await client.channels.fetch(id); - if (!channel) return; - if ( - channel.type === ChannelType.GuildText || - channel.type === ChannelType.PublicThread - ) - return channel as TextChannel | PublicThreadChannel; - return; + try { + const channel = await client.channels.fetch(id); + if (!channel) return; + if ( + channel.type === ChannelType.GuildText || + channel.type === ChannelType.PublicThread + ) + return channel as TextChannel | PublicThreadChannel; + return; + } catch (err) { + const discordErr = err as DiscordAPIError; + logger.error(discordErr.message, {type: 'error'}); + return; + } } export async function validateChannelArr(