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 | |
$sharkord | Sharkord |
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.
isOwner()
Section titled “isOwner()”Checks if the user is a server owner.
Returns bool — True if the user is an owner, false otherwise.
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.
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.
unban()
Section titled “unban()”Unbans a user from the server.
Returns \PromiseInterface — Resolves on success, rejects on failure.
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.
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.
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
__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