mirror of
https://github.com/danbulant/discord.js
synced 2026-05-24 20:42:27 +00:00
Add GuildMember.permissions/hasPermission
This commit is contained in:
parent
594836b1bf
commit
57acd4f41a
1 changed files with 29 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
const Role = require('./Role');
|
||||
const EvaluatedPermissions = require('./EvaluatedPermissions');
|
||||
const Constants = require('../util/Constants');
|
||||
const Collection = require('../util/Collection');
|
||||
|
||||
/**
|
||||
|
|
@ -148,6 +150,33 @@ class GuildMember {
|
|||
return this.user.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The overall set of permissions for the guild member, taking only roles into account
|
||||
* @type {EvaluatedPermissions}
|
||||
*/
|
||||
get permissions() {
|
||||
if (this.guild.owner.id === this.user.id) return new EvaluatedPermissions(this, Constants.ALL_PERMISSIONS);
|
||||
|
||||
let permissions = 0;
|
||||
const roles = this.roles;
|
||||
for (const role of roles.values()) permissions |= role.permissions;
|
||||
|
||||
const admin = Boolean(permissions & (Constants.PermissionFlags.ADMINISTRATOR));
|
||||
if (admin) permissions = Constants.ALL_PERMISSIONS;
|
||||
|
||||
return new EvaluatedPermissions(this, permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any of the member's roles have a permission
|
||||
* @param {PermissionResolvable} permission The permission to check for
|
||||
* @param {boolean} [explicit=false] Whether to require the roles to explicitly have the exact permission
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasPermission(permission, explicit = false) {
|
||||
return this.roles.some(r => r.hasPermission(permission, explicit));
|
||||
}
|
||||
|
||||
/**
|
||||
* Mute/unmute a user
|
||||
* @param {boolean} mute Whether or not the member should be muted
|
||||
|
|
|
|||
Loading…
Reference in a new issue