mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
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:
@@ -64,6 +64,17 @@ class Permissions {
|
|||||||
return (this.bitfield & permission) === permission;
|
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.
|
* Gets all given permissions that are missing from the bitfield.
|
||||||
* @param {PermissionResolvable} permissions Permissions to check for
|
* @param {PermissionResolvable} permissions Permissions to check for
|
||||||
|
|||||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -984,6 +984,7 @@ declare module 'discord.js' {
|
|||||||
public bitfield: number;
|
public bitfield: number;
|
||||||
public member: GuildMember;
|
public member: GuildMember;
|
||||||
public add(...permissions: PermissionResolvable[]): this;
|
public add(...permissions: PermissionResolvable[]): this;
|
||||||
|
public any(permissions: PermissionResolvable, checkAdmin?: boolean): boolean;
|
||||||
public freeze(): this;
|
public freeze(): this;
|
||||||
public has(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
|
public has(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
|
||||||
public hasPermission(permission: PermissionResolvable, explicit?: boolean): boolean;
|
public hasPermission(permission: PermissionResolvable, explicit?: boolean): boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user