Added in DiscordPHP 10.71.0 with discord-php/http
10.9.9 or newer.
These endpoints follow the still-open
Discord API documentation PR #8695
(reviewed revision a668a51dc1c8177684a7b6fa5a36b698ed655845
).
All four operations are already present in Discord's stable OpenAPI
description at 4e75626a4cedfbc397d66f5491c79a9a62a71fd5
.
The prose documentation may still change. Offline request tests do not
establish live endpoint availability.
Permissions
There are two types of permissions - channel permissions and role permissions. They are represented by their individual classes, but both extend the same abstract permission class.
Properties
| name | type | description |
|---|---|---|
| bitwise | int | bitwise representation |
| create_instant_invite | bool | |
| manage_channels | bool | |
| view_channel | bool | |
| manage_roles | bool |
The rest of the properties are listed under each permission type, all are type of bool
.
Methods
Fetch effective permissions from Discord
Guild::fetchMemberPermissions($member)
and
Guild::fetchRolePermissions($role)
fetch Discord's calculated guild-level
permissions. Member results cascade all of the member's roles, including
@everyone
. Role results combine the selected role with @everyone
.
They do not simply return the selected role's own $role->permissions
.
Channel::fetchMemberPermissions($member, $implicit = true)
and
Channel::fetchRolePermissions($role, $implicit = true)
fetch permissions
after channel overwrites. These methods are also available on threads and
use the thread's own channel ID. Discord requires the calling bot to have
VIEW_CHANNEL
. Pass false
as the second argument to request a result
without implicit permissions; the default includes them. See Discord's
implicit permissions documentation.
DM and group DM channels reject these operations.
All four methods return a promise resolving to a RolePermission
snapshot,
so the full set of known guild and channel flags remains accessible. Members
may be given as a Member
, User
or user ID string; roles may be given
as a Role
or role ID string. They do not require cached roles or overwrites,
and they do not overwrite cached role permissions, interaction permissions,
or member data. API errors reject the promise.
use Discord\Parts\Permissions\RolePermission;
$guild->fetchMemberPermissions('user_id')->then(function (RolePermission $permissions) {
var_dump($permissions->manage_guild);
}, function (Throwable $error) {
echo $error->getMessage(), PHP_EOL;
});
$channel->fetchRolePermissions('role_id', false)->then(function (RolePermission $permissions) {
var_dump($permissions->view_channel);
echo (string) $permissions, PHP_EOL; // Decimal bitfield.
}, function (Throwable $error) {
echo $error->getMessage(), PHP_EOL;
});
$member->getPermissions($channel)
and getBotPermissions()
still calculate
permissions synchronously from the local cache. Use the fetch methods when you
need Discord's calculation without relying on a complete local cache.
Get all valid permissions
Returns a list of valid permissions, in key value form. Static method.
var_dump(ChannelPermission::getPermissions());
// [
// 'priority_speaker' => 8,
// // ...
// ]
Channel Permission
Represents permissions for text, voice, and stage instance channels.
Text Channel Permissions
create_instant_invitemanage_channelsview_channelmanage_rolesadd_reactionssend_messagessend_tts_messagesmanage_messagesembed_linksattach_filesread_message_historymention_everyoneuse_external_emojismanage_webhooksuse_application_commandsmanage_threadscreate_public_threadscreate_private_threadsuse_external_stickerssend_messages_in_threads
Voice Channel Permissions
create_instant_invitemanage_channelsview_channelmanage_rolespriority_speakerstreamconnectspeakmute_membersdeafen_membersmove_membersuse_vadmanage_eventscreate_eventsuse_embedded_activitieswasstart_embedded_activities
Stage Instance Channel Permissions
create_instant_invitemanage_channelsview_channelmanage_rolesconnectmute_membersdeafen_membersmove_membersrequest_to_speakmanage_eventscreate_events
Role Permissions
Represents permissions for roles.
Permissions
create_instant_invitemanage_channelsview_channelmanage_roleskick_membersban_membersadministratormanage_guildview_audit_logview_guild_insightschange_nicknamemanage_nicknamesmanage_emojis_and_stickersmoderate_members