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); } };