DiscordPHP-BridgeBot Documentation

Permissions
in package

FinalYes

Works out which rung of {@see Access} a Discord message's author stands on.

Channel-aware on purpose: getPermissions($channel) resolves the channel's overwrites, so someone denied Manage Messages in one channel is not treated as a moderator there merely because a role grants it server-wide.

Tags
author

Valithor Obsidion valithor@discordphp.org

Table of Contents

Constants

ADMINISTRATOR  : mixed = 1 << 3
Administrator.
MANAGE_GUILD  : mixed = 1 << 5
Manage Server.
MANAGE_MESSAGES  : mixed = 1 << 13
Manage Messages — the closest Discord has to a chat moderator.

Methods

accessFor()  : Access
accessForInteraction()  : Access
The same ladder, for a slash command.
accessIn()  : Access|null
The rung a message's author stands on in *another* channel of the same server — or `null` when they cannot see that channel at all.
bitsFromInteraction()  : string|null
The `member.permissions` decimal string off an interaction payload, or `null` when unreachable (a DM, or a shape we do not know).
bitsGrant()  : bool
Whether a permissions bitfield carries any of `$mask`.
rawPermValue()  : string|null
Pulls `permissions` out of whatever shape a `member` attribute took — a gateway `stdClass`, an array, or a Part (raw attributes, not the getter) — normalised to a decimal string.

Constants

ADMINISTRATOR

Administrator.

public mixed ADMINISTRATOR = 1 << 3

MANAGE_GUILD

Manage Server.

public mixed MANAGE_GUILD = 1 << 5

MANAGE_MESSAGES

Manage Messages — the closest Discord has to a chat moderator.

public mixed MANAGE_MESSAGES = 1 << 13

Methods

accessFor()

public static accessFor(Message $message, string|null $ownerId) : Access
Parameters
$message : Message
$ownerId : string|null

The configured bot operator's Discord user id.

Return values
Access

accessForInteraction()

The same ladder, for a slash command.

public static accessForInteraction(object $interaction, string|null $ownerId) : Access

An interaction carries its own resolved permissions rather than a cached Member, and it is the better source: Discord has already folded channel overwrites into the bitfield, so it is correct even when the member cache is cold or the bot lacks the members intent.

Parameters
$interaction : object
$ownerId : string|null
Return values
Access

accessIn()

The rung a message's author stands on in *another* channel of the same server — or `null` when they cannot see that channel at all.

public static accessIn(Message $message, Channel|null $channel, string|null $ownerId) : Access|null

For acting on a room from somewhere other than the channel it is bridged to. Rank in one channel says nothing about another: Manage Messages can be granted in a single channel, and a room bridged to #staff must not be reachable by somebody who cannot open #staff.

Parameters
$message : Message
$channel : Channel|null
$ownerId : string|null
Return values
Access|null

bitsFromInteraction()

The `member.permissions` decimal string off an interaction payload, or `null` when unreachable (a DM, or a shape we do not know).

public static bitsFromInteraction(object $interaction) : string|null

Reads the raw attributes first: DiscordPHP's ->member getter runs a transform that does not preserve permissions, so going through it alone silently loses the value and every check quietly fails closed.

Parameters
$interaction : object
Return values
string|null

bitsGrant()

Whether a permissions bitfield carries any of `$mask`.

public static bitsGrant(int|string|null $bits, int $mask) : bool
Parameters
$bits : int|string|null
$mask : int
Return values
bool

rawPermValue()

Pulls `permissions` out of whatever shape a `member` attribute took — a gateway `stdClass`, an array, or a Part (raw attributes, not the getter) — normalised to a decimal string.

private static rawPermValue(mixed $member) : string|null
Parameters
$member : mixed
Return values
string|null
On this page

Search results