Skip to content

Commit

Permalink
fix(guildCreate): added error catching for future proofing.
Browse files Browse the repository at this point in the history
  • Loading branch information
SethCohen committed Aug 31, 2022
1 parent d67972b commit 9460972
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/events/guildCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down

0 comments on commit 9460972

Please sign in to comment.