Permissions

A collection of multiple Permissions.

Creating an instance of Permissions

You can create an instance of Permissions using the following methods:

// from individual Permissions
val permissions1 = Permissions(Permission.CreateInstantInvite, Permission.KickMembers)

// from an Iterable
val iterable: Iterable<Permission> = TODO()
val permissions2 = Permissions(iterable)

// using a builder
val permissions3 = Permissions {
+permissions2
+Permission.CreateInstantInvite
-Permission.KickMembers
}

Modifying an existing instance of Permissions

You can create a modified copy of an existing instance of Permissions using the copy method:

permissions.copy {
+Permission.CreateInstantInvite
}

Mathematical operators

All Permissions objects can use +/- operators:

val permissions1 = permissions + Permission.CreateInstantInvite
val permissions2 = permissions - Permission.KickMembers
val permissions3 = permissions1 + permissions2

Checking for Permissions

You can use the contains operator to check whether an instance of Permissions contains specific Permissions:

val hasPermission = Permission.CreateInstantInvite in permissions
val hasPermissions = Permissions(Permission.CreateInstantInvite, Permission.KickMembers) in permissions

Unknown Permissions

Whenever Permissions haven't been added to Kord yet, they will be deserialized as instances of Permission.Unknown.

You can also use Permission.fromShift to check for unknown Permissions.

val hasUnknownPermission = Permission.fromShift(23) in permissions

See also

Types

Link copied to clipboard
class Builder(code: DiscordBitSet = EmptyBitSet())
Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The raw code used by Discord.

Link copied to clipboard

A Set of all Permissions contained in this instance of Permissions.

Functions

Link copied to clipboard
operator fun contains(flag: Permission): Boolean

Checks if this instance of Permissions has all bits set that are set in flag.

operator fun contains(flags: Permissions): Boolean

Checks if this instance of Permissions has all bits set that are set in flags.

Link copied to clipboard
inline fun copy(builder: Permissions.Builder.() -> Unit): Permissions

Returns a copy of this instance of Permissions modified with builder.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
operator fun minus(flag: Permission): Permissions

Returns an instance of Permissions that has all bits set that are set in this except the bits that are set in flag.

operator fun minus(flags: Permissions): Permissions

Returns an instance of Permissions that has all bits set that are set in this except the bits that are set in flags.

Link copied to clipboard
operator fun plus(flag: Permission): Permissions

Returns an instance of Permissions that has all bits set that are set in this and flag.

operator fun plus(flags: Permissions): Permissions

Returns an instance of Permissions that has all bits set that are set in this and flags.

Link copied to clipboard
open override fun toString(): String