Skip to content

Commit

Permalink
fix(discord.js-utilities): added null checks for permission checks (#523
Browse files Browse the repository at this point in the history
)
  • Loading branch information
favna committed Nov 19, 2022
1 parent 7fb7d2c commit 1abc270
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/discord.js-utilities/src/lib/utilities.ts
Expand Up @@ -107,5 +107,15 @@ export function canJoinVoiceChannel(channel: VoiceBasedChannel | Nullish): boole
}

function canDoUtility(channel: ChannelTypes, permissionsToPass: Permissions) {
return isGuildBasedChannel(channel) ? channel.permissionsFor(channel.guild.me!)!.has(permissionsToPass) : true;
if (!isGuildBasedChannel(channel)) {
return true;
}

const { me } = channel.guild;
if (!me) return false;

const permissionsFor = channel.permissionsFor(me);
if (!permissionsFor) return false;

return permissionsFor.has(permissionsToPass);
}

0 comments on commit 1abc270

Please sign in to comment.