mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
Add GuildMember.permissionsIn and make ChannelResolvables more lenient
This commit is contained in:
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:
|
* Data that can be resolved to give a Channel. This can be:
|
||||||
* * An instance of a Channel
|
* * 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
|
* * An ID of a Channel
|
||||||
* @typedef {Channel|string} ChannelResolvable
|
* @typedef {Channel|Guild|Message|string} ChannelResolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,6 +126,8 @@ class ClientDataResolver {
|
|||||||
*/
|
*/
|
||||||
resolveChannel(channel) {
|
resolveChannel(channel) {
|
||||||
if (channel instanceof Channel) return 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);
|
if (typeof channel === 'string') return this.client.channels.get(channel.id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,6 +167,19 @@ class GuildMember {
|
|||||||
return new EvaluatedPermissions(this, permissions);
|
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
|
* Checks if any of the member's roles have a permission
|
||||||
* @param {PermissionResolvable} permission The permission to check for
|
* @param {PermissionResolvable} permission The permission to check for
|
||||||
|
|||||||
Reference in New Issue
Block a user