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 <bdistin@gmail.com>

* docs(Permissions): remove trailing space, add returns annotation

Co-authored-by: bdistin <bdistin@gmail.com>
This commit is contained in:
SpaceEEC
2020-01-05 18:24:08 +01:00
committed by GitHub
parent cbabc1663c
commit 367c80070f
2 changed files with 12 additions and 0 deletions

View File

@@ -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

1
typings/index.d.ts vendored
View File

@@ -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;