-
Notifications
You must be signed in to change notification settings - Fork 237
Role
Roles are part of Guild (Server). See Overwrite for specific channel role permission.
use Discord\Parts\Guild\Role;
A role defines permissions for the guild. Members can be added to the role. The role belongs to a guild.
Requires GUILDS
discord intent
Your BOT must have manage_roles
permission
You must first get the Guild object to use the code below
Create a role named "New Role" with pink color, hoisted, and mentionable:
$guild->createRole([
// All options are optional
'name' => 'New Role',
'color' => 0xFF00FF,
'hoist' => true,
'mentionable' => true,
// more options in Docs
])->then(function (Role $role) {
echo 'Created a new role - ID:', $role->id;
})->done();
https://discord.com/developers/docs/resources/guild#create-guild-role
You must first get the Guild object to use the code below. Change 123123123123123123
below with the Role ID you want to retrieve
Cached, synchronous:
$role = $guild->roles->get('id', '123123123123123123');
If the code above returns null
, you may need to freshen the RoleRepository
first (Promise, asynchronous):
$guild->roles->freshen()->then(function (RoleRepository $roles) {
$role = $roles->get('id', '123123123123123123');
})->done();
Your BOT must have manage_roles
permission
You must first get the Member object to use the code below
Add the $member
to the $role
:
$member->addRole($role)->then(function () {
// ...
})->done();
Or, change 123123123123123123
below with the Role ID:
$member->addRole('123123123123123123')->then(function () {
// ...
})->done();
https://discord.com/developers/docs/resources/guild#add-guild-member-role
Your BOT must have manage_roles
permission
You must first get the Member object to use the code below
Remove the $member
from the $role
:
$member->removeRole($role)->then(function () {
// ...
})->done();
Or, change 123123123123123123
below with the Role ID:
$member->removeRole('123123123123123123')->then(function () {
// ...
})->done();
https://discord.com/developers/docs/resources/guild#remove-guild-member-role
Note: This wiki is currently Work In Progress. Consider reading the docs instead.
- Application Command (Slash based)
Command Client (Message based)
- Activity
- Application
- Guild
- Private Channel
- User
Components
-
ActionRow
- Buttons
- Option (commands)
- SelectMenu
- TextInput
Builders