From 9460972c0b77088b35fe64f5757f79dd33369e46 Mon Sep 17 00:00:00 2001 From: SethCohen Date: Wed, 31 Aug 2022 03:12:09 -0400 Subject: [PATCH] fix(guildCreate): added error catching for future proofing. --- src/events/guildCreate.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/events/guildCreate.js b/src/events/guildCreate.js index 0809975..31fd579 100644 --- a/src/events/guildCreate.js +++ b/src/events/guildCreate.js @@ -3,15 +3,20 @@ const { EmbedBuilder, ChannelType, PermissionsBitField } = require('discord.js') const { mediaLinks } = require('../helpers/utilities'); const postToAnyChannel = async (guild, embed) => { - const channels = await guild.channels.cache; - const foundChannel = await channels.find(channel => (channel.type === ChannelType.GuildText - && channel.permissionsFor(guild.members.me).has(PermissionsBitField.Flags.SendMessages) - && channel.permissionsFor(guild.members.me).has(PermissionsBitField.Flags.ViewChannel))); - if (foundChannel) { - foundChannel.send({ embeds: [embed] }); + try { + const channels = await guild.channels.cache; + const foundChannel = await channels.find(channel => (channel.type === ChannelType.GuildText + && channel.permissionsFor(guild.members.me).has(PermissionsBitField.Flags.SendMessages) + && channel.permissionsFor(guild.members.me).has(PermissionsBitField.Flags.ViewChannel))); + if (foundChannel) { + foundChannel.send({ embeds: [embed] }); + } + else { + console.error('No channel access found. Welcome message not sent.'); + } } - else { - console.error('No channel access found. Welcome message not sent.'); + catch (e) { + console.error(e); } };