Skip to content

Role

Class  ·  Sharkord\Models\Role

Class Role

Represents a user role on the server.

$role = $sharkord->roles->get(3);
echo $role->name; // "Admins"
echo $role->color; // "#0085de"
echo $role->isDefault; // false
echo $role->isPersistent; // false

Role constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordReference to the main bot instance.
$rawDataarrayThe raw array of data from the API.

Factory method to create a Role from raw API data.

Parameters

ParameterTypeDescription
$rawarrayThe raw role data from the server.
$sharkordSharkordReference to the main bot instance.

Returns self


Edits this role’s name, colour, and permission set.

Sends the roles.update mutation. The server will push a roles.onUpdate event that updates the cached model automatically.

Requires the MANAGE_ROLES permission.

Parameters

ParameterTypeDescription
$namestringThe new role name.
$colorstringThe new role colour as a CSS hex string (e.g. “#ff0000”).
...$permissionsPermissionZero or more permissions to grant to the role. Any permission not listed will be revoked. Passing no permissions will revoke all permissions from the role.

Returns \PromiseInterface — Resolves with true on success, rejects on failure.

Example

$sharkord->roles->get(3)?->edit(
'Moderators',
'#00aaff',
\Sharkord\Permission::MANAGE_MESSAGES,
\Sharkord\Permission::MANAGE_USERS,
\Sharkord\Permission::PIN_MESSAGES,
)->then(function() {
echo "Role updated.\n";
});

Sets this role as the server default.

The server will push two roles.onUpdate events: one to unset the previous default role and one to mark this role as default. Both cached models are updated automatically via the subscription handler.

Requires the MANAGE_ROLES permission.

Returns \PromiseInterface — Resolves with true on success, rejects on failure.

Example

$sharkord->roles->get(3)?->setAsDefault()->then(function() {
echo "Role is now the server default.\n";
});

Permanently deletes this role from the server.

Requires the MANAGE_ROLES permission. The role is removed from the local cache once the server emits the corresponding roles.onDelete event. Persistent roles (e.g. Owner, default role) cannot be deleted.

Returns \PromiseInterface — Resolves with true on success, rejects on failure.

Example

$sharkord->roles->get(5)?->delete()->then(function() {
echo "Role deleted.\n";
});

Returns all the attributes as a plain array. Useful for debugging.

Returns array

Example

var_dump($sharkord->roles->get(3)?->toArray());

Magic isset check. Allows isset() and empty() to work correctly against dynamic properties stored in the attributes array.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns bool


Magic getter. Triggered whenever you try to access a property that isn’t explicitly defined (e.g. $role->name or $role->color).

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns mixed