Role
Class · Sharkord\Models\Role
Class Role
Represents a user role on the server.
Examples
Section titled “Examples”$role = $sharkord->roles->get(3);
echo $role->name; // "Admins"echo $role->color; // "#0085de"echo $role->isDefault; // falseecho $role->isPersistent; // falseMethods
Section titled “Methods”__construct()
Section titled “__construct()”Role constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
$rawData | array | The raw array of data from the API. |
static fromArray()
Section titled “static fromArray()”Factory method to create a Role from raw API data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | array | The raw role data from the server. |
$sharkord | Sharkord | Reference to the main bot instance. |
Returns self
edit()
Section titled “edit()”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
| Parameter | Type | Description |
|---|---|---|
$name | string | The new role name. |
$color | string | The new role colour as a CSS hex string (e.g. “#ff0000”). |
...$permissions | Permission | Zero 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";});setAsDefault()
Section titled “setAsDefault()”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";});delete()
Section titled “delete()”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";});toArray()
Section titled “toArray()”Returns all the attributes as a plain array. Useful for debugging.
Returns array
Example
var_dump($sharkord->roles->get(3)?->toArray());__isset()
Section titled “__isset()”Magic isset check. Allows isset() and empty() to work correctly against dynamic properties stored in the attributes array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns bool
__get()
Section titled “__get()”Magic getter. Triggered whenever you try to access a property that isn’t explicitly defined (e.g. $role->name or $role->color).
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns mixed