diff --git a/src/util/BitField.js b/src/util/BitField.js index 424a8443d..757da7ab9 100644 --- a/src/util/BitField.js +++ b/src/util/BitField.js @@ -17,6 +17,15 @@ class BitField { this.bitfield = this.constructor.resolve(bits); } + /** + * Checks whether the bitfield has a bit, or any of multiple bits. + * @param {BitFieldResolvable} bit Bit(s) to check for + * @returns {boolean} + */ + any(bit) { + return (this.bitfield & this.constructor.resolve(bit)) !== 0; + } + /** * Checks if this bitfield equals another * @param {BitFieldResolvable} bit Bit(s) to check for diff --git a/src/util/Permissions.js b/src/util/Permissions.js index ef5273ffd..831f17386 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -18,6 +18,16 @@ class Permissions extends BitField { * @typedef {string|number|Permissions|PermissionResolvable[]} PermissionResolvable */ + /** + * Checks whether the bitfield has a permission, or any of multiple permissions. + * @param {PermissionResolvable} permission Permission(s) to check for + * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override + * @returns {boolean} + */ + any(permission, checkAdmin = true) { + return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.any(permission); + } + /** * Checks whether the bitfield has a permission, or multiple permissions. * @param {PermissionResolvable} permission Permission(s) to check for @@ -25,8 +35,7 @@ class Permissions extends BitField { * @returns {boolean} */ has(permission, checkAdmin = true) { - if (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) return true; - return super.has(permission); + return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission); } } diff --git a/typings/index.d.ts b/typings/index.d.ts index aaf9f524d..13405c3f0 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -99,6 +99,7 @@ declare module 'discord.js' { constructor(bits?: BitFieldResolvable); public bitfield: number; public add(...bits: BitFieldResolvable[]): BitField; + public any(bit: BitFieldResolvable): boolean; public equals(bit: BitFieldResolvable): boolean; public freeze(): Readonly>; public has(bit: BitFieldResolvable): boolean; @@ -1111,6 +1112,7 @@ declare module 'discord.js' { } export class Permissions extends BitField { + public any(permission: PermissionResolvable, checkAdmin?: boolean): boolean; public has(permission: PermissionResolvable, checkAdmin?: boolean): boolean; public static ALL: number;