User
Class · Sharkord\Models\User
Class User
Represents a user entity on the server.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
$roles (read-only) | array | The roles assigned to this user. |
Methods
Section titled “Methods”__construct()
Section titled “__construct()”User constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the bot instance. |
$rawData | array | The raw array of data from the API. |
static fromArray()
Section titled “static fromArray()”Factory method to create a User from raw API data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | array | The raw user data from the server. |
$sharkord | Sharkord | Reference to the main bot instance. |
Returns self
updateStatus()
Section titled “updateStatus()”Updates the user’s status specifically.
Parameters
| Parameter | Type | Description |
|---|---|---|
$status | string | The new status. |
hasPermission()
Section titled “hasPermission()”Determine if the user possesses a specific permission through any of their roles.
Parameters
| Parameter | Type | Description |
|---|---|---|
$permission | Permission | The permission enum case to check. |
Returns bool — True if any of the user’s roles have the permission, false otherwise.
Example
if ($user->hasPermission(\Sharkord\Permission::MANAGE_CHANNELS)) { echo "{$user->name} can manage channels.\n";}isOwner()
Section titled “isOwner()”Checks if the user is a server owner.
Returns bool — True if the user is an owner, false otherwise.
Example
if ($user->isOwner()) { echo "{$user->name} is a server owner.\n";}hasRole()
Section titled “hasRole()”Checks if the user has a specific role via their assigned role ids.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleId | int | The role id to check. |
Returns bool — True if the user has the role, false otherwise.
Example
if ($user->hasRole(3)) { echo "{$user->name} has the Moderator role.\n";}Bans a user from the server.
Parameters
| Parameter | Type | Description |
|---|---|---|
$reason (optional) | string | The reason for the ban. |
Returns \PromiseInterface — Resolves on success, rejects on failure.
Throws
\RuntimeException— If the bot lacks MANAGE_USERS or the target is the server owner.
Example
$user->ban('Spamming in #general')->then(function() use ($user) { echo "{$user->name} has been banned.\n";});unban()
Section titled “unban()”Unbans a user from the server.
Returns \PromiseInterface — Resolves on success, rejects on failure.
Throws
\RuntimeException— If the bot lacks MANAGE_USERS.
Example
$user->unban()->then(function() use ($user) { echo "{$user->name} has been unbanned.\n";});kick()
Section titled “kick()”Kicks a user from the server.
Parameters
| Parameter | Type | Description |
|---|---|---|
$reason (optional) | string | The reason for the kick. |
Returns \PromiseInterface — Resolves on success, rejects on failure.
Throws
\RuntimeException— If the bot lacks MANAGE_USERS or the target is the server owner.
Example
$user->kick('Violating server rules')->then(function() use ($user) { echo "{$user->name} has been kicked.\n";});delete()
Section titled “delete()”Deletes a user from the server.
Parameters
| Parameter | Type | Description |
|---|---|---|
$wipe (optional) | bool | Whether to delete all associated user data (posts, files, emoji, etc.). |
Returns \PromiseInterface — Resolves on success, rejects on failure.
Throws
\RuntimeException— If the bot lacks MANAGE_USERS or the target is the server owner.
Example
$user->delete(wipe: true)->then(function() use ($user) { echo "{$user->name} and all their data have been removed.\n";});openDm()
Section titled “openDm()”Opens a direct message channel with this user.
Delegates to DmManager::open() and resolves to a Channel object that can be used for sending messages, typing indicators, and more.
Returns \PromiseInterface — Resolves with a Channel object, rejects on failure.
Example
$sharkord->on('message', function(Message $message) use ($sharkord) { $message->author->openDm()->then(function(Channel $channel) { $channel->sendMessage("Hey, I got your message!"); $channel->markAsRead(); });});sendDm()
Section titled “sendDm()”Opens a DM channel with this user and sends a message in one call.
This is a convenience wrapper around openDm() + Channel::sendMessage(). Use openDm() directly when you need access to the Channel object itself.
Parameters
| Parameter | Type | Description |
|---|---|---|
$text | string | The message content. |
Returns \PromiseInterface — Resolves on success, rejects on failure.
Example
$sharkord->on('message', function(Message $message) { if ($message->content === '!hello') { $message->author->sendDm("Hey! This is a private message just for you."); }});toArray()
Section titled “toArray()”Returns all the attributes as an array. Perfect for debugging!
Returns array
Example
var_dump($user->toArray());__isset()
Section titled “__isset()”Magic isset check. Allows isset() and empty() to work correctly against both stored attributes and virtual relational properties.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns bool
__get()
Section titled “__get()”Magic getter. This is triggered whenever you try to access a property that isn’t explicitly defined (e.g., $user->bio or $user->id).
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns mixed