Improve guildFromChannel

This commit is contained in:
Logan Cusano
2023-03-26 20:14:23 -04:00
parent 8d68f87ec0
commit f5076d40cc

View File

@@ -19,7 +19,7 @@ function getGuilds(req) {
* @param {*} req The request object to use to check the discord client
*/
function getChannels(guildId, req) {
const guild = req.discordClient.guilds.cache.get(guildId);
const guild = req.discordClient.guilds.find(guildId);
log.DEBUG("Found Guild channels with guild", guild.channels, guild);
return guild.channels;
}
@@ -40,13 +40,12 @@ function checkIfGuildHasChannel(guildId, channelId, req){
}
function getGuildFromChannel(channelId, req){
const guilds = getGuilds(req);
for (const guild in guilds){
if (checkIfGuildHasChannel(guild.id, channelId, req)) {
return guild;
break;
}
}
const channel = req.discordClient.channels.cache.get(channelId);
if (!channel) return undefined;
if (channel.guild) return channel.guild;
return new Error("No Guild found with the given ID");
}