mirror of
https://github.com/danbulant/discord.js
synced 2026-05-25 04:52:22 +00:00
Add GuildMember.permissionsIn and make ChannelResolvables more lenient
This commit is contained in:
parent
7933d755be
commit
3fba72107b
3 changed files with 19 additions and 2 deletions
File diff suppressed because one or more lines are too long
|
|
@ -113,8 +113,10 @@ class ClientDataResolver {
|
|||
/**
|
||||
* Data that can be resolved to give a Channel. This can be:
|
||||
* * An instance of a Channel
|
||||
* * An instance of a Message (the channel the message was sent in)
|
||||
* * An instance of a Guild (the #general channel)
|
||||
* * An ID of a Channel
|
||||
* @typedef {Channel|string} ChannelResolvable
|
||||
* @typedef {Channel|Guild|Message|string} ChannelResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -124,6 +126,8 @@ class ClientDataResolver {
|
|||
*/
|
||||
resolveChannel(channel) {
|
||||
if (channel instanceof Channel) return channel;
|
||||
if (channel instanceof Message) return channel.channel;
|
||||
if (channel instanceof Guild) return channel.channels.get(channel.id);
|
||||
if (typeof channel === 'string') return this.client.channels.get(channel.id);
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,19 @@ class GuildMember {
|
|||
return new EvaluatedPermissions(this, permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `guildChannel.permissionsFor(guildMember)`. Returns evaluated permissions for a member in a guild channel.
|
||||
* @param {ChannelResolvable} guildChannel the guild channel to use as context
|
||||
* @returns {?EvaluatedPermissions}
|
||||
*/
|
||||
permissionsIn(guildChannel) {
|
||||
guildChannel = this.client.resolver.resolveChannel(guildChannel);
|
||||
if (!guildChannel) {
|
||||
throw new Error('supply a channel resolvable that resolves to a GuildChannel!');
|
||||
}
|
||||
return guildChannel.permissionsFor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any of the member's roles have a permission
|
||||
* @param {PermissionResolvable} permission The permission to check for
|
||||
|
|
|
|||
Loading…
Reference in a new issue