Skip to main content
Version: 0.6.4

Class: Permissions

Extends​

Constructors​

Constructor​

new Permissions(bits?): Permissions

Parameters​

ParameterType
bits?BitFieldResolvable

Returns​

Permissions

Inherited from​

BitField.constructor

Properties​

bitfield​

bitfield: number | bigint

Inherited from​

BitField.bitfield


DefaultBit​

static DefaultBit: bigint = 0n

Overrides​

BitField.DefaultBit


Flags​

static Flags: Record<string, number | bigint>

Overrides​

BitField.Flags

Methods​

[iterator]()​

[iterator](...hasParams): IterableIterator<string>

Iterates over the names of all flags that are set in this bitfield.

Parameters​

ParameterType
...hasParamsany[]

Returns​

IterableIterator<string>

Example​

for (const flag of perms) {
console.log(flag); // 'SendMessage', 'ViewChannel', etc.
}

Inherited from​

BitField.[iterator]


add()​

add(...bits): this

Adds one or more bits to this bitfield. If the instance is frozen, returns a new BitField with the bits added.

Parameters​

ParameterTypeDescription
...bitsPermissionResolvable[]The bit(s) to add.

Returns​

this

This instance (or a new one if frozen), with the bits added.

Example​

perms.add("SendMessage", "ViewChannel");

Overrides​

BitField.add


any()​

any(bit): boolean

Checks whether this bitfield has any of the given bits set.

Parameters​

ParameterTypeDescription
bitPermissionResolvableThe bit(s) to test against.

Returns​

boolean

true if at least one of the provided bits is set.

Example​

perms.any(["SendMessage", "ManageChannel"]); // true if either is set

Overrides​

BitField.any


equals()​

equals(bit): boolean

Checks whether this bitfield is exactly equal to the given bit value.

Parameters​

ParameterTypeDescription
bitBitFieldResolvableThe bit(s) to compare against.

Returns​

boolean

true if the resolved bit value is identical to this bitfield.

Example​

new Permissions(0n).equals(0n); // true

Inherited from​

BitField.equals


freeze()​

freeze(): Readonly<this>

Freezes this BitField instance, making it immutable. Subsequent calls to add() or remove() will return a new instance instead of mutating this one.

Returns​

Readonly<this>

This instance, frozen.

Inherited from​

BitField.freeze


has()​

has(bit): boolean

Checks whether this bitfield has all of the given bits set.

Parameters​

ParameterTypeDescription
bitPermissionResolvableThe bit(s) to check for.

Returns​

boolean

true if every provided bit is set in this bitfield.

Example​

perms.has("SendMessage");
perms.has(["SendMessage", "ViewChannel"]); // true only if both are set

Overrides​

BitField.has


missing()​

missing(bits): ("Video" | "ManageChannel" | "ManageServer" | "ManagePermissions" | "ManageRole" | "ManageCustomisation" | "KickMembers" | "BanMembers" | "TimeoutMembers" | "AssignRoles" | "ChangeNickname" | "ManageNicknames" | "ChangeAvatar" | "RemoveAvatars" | "ViewChannel" | "ReadMessageHistory" | "SendMessage" | "ManageMessages" | "ManageWebhooks" | "InviteOthers" | "SendEmbeds" | "UploadFiles" | "Masquerade" | "React" | "BypassSlowmode" | "Connect" | "Speak" | "MuteMembers" | "DeafenMembers" | "MoveMembers" | "Listen" | "MentionEveryone" | "MentionRoles" | "GrantAllSafe")[]

Returns the flag names present in bits that are missing from this bitfield.

Parameters​

ParameterTypeDescription
bitsPermissionResolvableThe bits to check against.

Returns​

("Video" | "ManageChannel" | "ManageServer" | "ManagePermissions" | "ManageRole" | "ManageCustomisation" | "KickMembers" | "BanMembers" | "TimeoutMembers" | "AssignRoles" | "ChangeNickname" | "ManageNicknames" | "ChangeAvatar" | "RemoveAvatars" | "ViewChannel" | "ReadMessageHistory" | "SendMessage" | "ManageMessages" | "ManageWebhooks" | "InviteOthers" | "SendEmbeds" | "UploadFiles" | "Masquerade" | "React" | "BypassSlowmode" | "Connect" | "Speak" | "MuteMembers" | "DeafenMembers" | "MoveMembers" | "Listen" | "MentionEveryone" | "MentionRoles" | "GrantAllSafe")[]

An array of flag name strings that are in bits but not in this bitfield.

Example​

// If perms only has SendMessage:
perms.missing(["SendMessage", "ManageChannel"]); // ['ManageChannel']

Overrides​

BitField.missing


remove()​

remove(...bits): this

Removes one or more bits from this bitfield. If the instance is frozen, returns a new BitField with the bits removed.

Parameters​

ParameterTypeDescription
...bitsPermissionResolvable[]The bit(s) to remove.

Returns​

this

This instance (or a new one if frozen), with the bits cleared.

Example​

perms.remove("ManageChannel");

Overrides​

BitField.remove


serialize()​

serialize(...hasParams): Record<string, boolean>

Serializes this bitfield to a plain object mapping each flag name to a boolean indicating whether that flag is set.

Parameters​

ParameterType
...hasParamsany[]

Returns​

Record<string, boolean>

A record of { [flagName]: boolean } for all defined flags.

Example​

perms.serialize();
// { SendMessage: true, ManageChannel: false, ... }

Inherited from​

BitField.serialize


toArray()​

toArray(...hasParams): string[]

Returns an array of flag names that are set in this bitfield.

Parameters​

ParameterType
...hasParamsany[]

Returns​

string[]

An array of string flag names.

Example​

perms.toArray(); // ['SendMessage', 'ViewChannel']

Inherited from​

BitField.toArray


toJSON()​

toJSON(): string | number

Returns the bitfield value as a JSON-safe primitive. Numbers are returned as-is; bigints are converted to their string representation to avoid JSON serialization errors.

Returns​

string | number

Inherited from​

BitField.toJSON


valueOf()​

valueOf(): number | bigint

Returns the underlying numeric value of this bitfield. Allows BitField instances to be used directly in arithmetic expressions.

Returns​

number | bigint

Inherited from​

BitField.valueOf


resolve()​

static resolve(bit?): bigint

Resolves a BitFieldResolvable into a raw number | bigint.

Resolution rules (in order):

  • undefined → DefaultBit
  • A number or bigint matching DefaultBit's type and >= 0 → returned as-is
  • A BitField instance → its .bitfield value
  • An array → each element resolved and OR'd together
  • A numeric string → parsed as BigInt or Number depending on DefaultBit's type
  • A named string flag → looked up in Flags
  • Anything else → throws RangeError

Parameters​

ParameterTypeDescription
bit?PermissionResolvableThe value to resolve.

Returns​

bigint

Throws​

If the value cannot be resolved to a valid bit.

Overrides​

BitField.resolve