From 367c80070f0b638a8658095dd1fe5de796af4c5e Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Sun, 5 Jan 2020 18:24:08 +0100 Subject: [PATCH] feat(Permissions): add any method (#3571) * feat(Permissions): add any method * typings: add Permissions#any * fix(Permissions): resolve doesn't take a checkAdmin parameter Co-Authored-By: bdistin * docs(Permissions): remove trailing space, add returns annotation Co-authored-by: bdistin --- src/util/Permissions.js | 11 +++++++++++ typings/index.d.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/util/Permissions.js b/src/util/Permissions.js index a0835870f..f1d8cac84 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -64,6 +64,17 @@ class Permissions { return (this.bitfield & permission) === permission; } + /** + * Checks whether the bitfield has a permission, or any of multiple permissions. + * @param {PermissionResolvable} permissions Permission(s) to check for + * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override + * @returns {boolean} + */ + any(permissions, checkAdmin = true) { + return (checkAdmin && this.has(this.constructor.FLAGS.ADMINISTRATOR)) || + (this.bitfield & this.constructor.resolve(permissions)) !== 0; + } + /** * Gets all given permissions that are missing from the bitfield. * @param {PermissionResolvable} permissions Permissions to check for diff --git a/typings/index.d.ts b/typings/index.d.ts index 91eee94da..808d6c98c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -984,6 +984,7 @@ declare module 'discord.js' { public bitfield: number; public member: GuildMember; public add(...permissions: PermissionResolvable[]): this; + public any(permissions: PermissionResolvable, checkAdmin?: boolean): boolean; public freeze(): this; public has(permission: PermissionResolvable, checkAdmin?: boolean): boolean; public hasPermission(permission: PermissionResolvable, explicit?: boolean): boolean;