From 428ee2f71824b39375a8555e0a1043e1c05b0c67 Mon Sep 17 00:00:00 2001 From: bdistin Date: Fri, 30 Sep 2016 16:08:19 -0500 Subject: [PATCH] Added .missingPermissions() (#756) * Added .missingPermissions() * Added .missingPermissions() * Fixed docs for .missingPermissions() * Fixed Travis CI trailing spaces? * Fixed Travis CI trailing spaces? --- src/structures/EvaluatedPermissions.js | 10 ++++++++++ src/structures/GuildMember.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/structures/EvaluatedPermissions.js b/src/structures/EvaluatedPermissions.js index 9deecba81..a4462692a 100644 --- a/src/structures/EvaluatedPermissions.js +++ b/src/structures/EvaluatedPermissions.js @@ -52,6 +52,16 @@ class EvaluatedPermissions { hasPermissions(permissions, explicit = false) { return permissions.map(p => this.hasPermission(p, explicit)).every(v => v); } + + /** + * Checks whether the user has all specified permissions, and lists any missing permissions. + * @param {PermissionResolvable[]} permissions The permissions to check for + * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permissions + * @returns {array} + */ + missingPermissions(permissions, explicit = false) { + return permissions.filter(p => !this.hasPermission(p, explicit)); + } } module.exports = EvaluatedPermissions; diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index d23a9d240..305e1de94 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -253,6 +253,16 @@ class GuildMember { return permissions.map(p => this.hasPermission(p, explicit)).every(v => v); } + /** + * Checks whether the roles of the member allows them to perform specific actions, and lists any missing permissions. + * @param {PermissionResolvable[]} permissions The permissions to check for + * @param {boolean} [explicit=false] Whether to require the member to explicitly have the exact permissions + * @returns {array} + */ + missingPermissions(permissions, explicit = false) { + return permissions.filter(p => !this.hasPermission(p, explicit)); + } + /** * Edit a Guild Member * @param {GuildmemberEditData} data The data to edit the member with