Skip to content

User

Class  ·  Sharkord\Models\User

Class User

Represents a user entity on the server.

PropertyTypeDescription
$roles (read-only)arrayThe roles assigned to this user.

User constructor.

Parameters

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

Factory method to create a User from raw API data.

Parameters

ParameterTypeDescription
$rawarray
$sharkordSharkord

Returns self


Updates the user’s status specifically.

Parameters

ParameterTypeDescription
$statusstringThe new status.

Determine if the user possesses a specific permission through any of their roles.

Parameters

ParameterTypeDescription
$permissionPermissionThe permission enum case to check.

Returns bool — True if any of the user’s roles have the permission, false otherwise.


Checks if the user is a server owner.

Returns bool — True if the user is an owner, false otherwise.


Checks if the user has a specific role via their assigned role ids.

Parameters

ParameterTypeDescription
$roleIdintThe role id to check.

Returns bool — True if the user has the role, false otherwise.


Bans a user from the server.

Parameters

ParameterTypeDescription
$reason (optional)stringThe reason for the ban.

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


Unbans a user from the server.

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


Kicks a user from the server.

Parameters

ParameterTypeDescription
$reason (optional)stringThe reason for the kick.

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


Deletes a user from the server.

Parameters

ParameterTypeDescription
$wipe (optional)boolWhether to delete all associated user data (posts, files, emoji, etc.).

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


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();
});
});

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

ParameterTypeDescription
$textstringThe 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.");
}
});

Returns all the attributes as an array. Perfect for debugging!

Returns array


Magic isset check. Allows isset() and empty() to work correctly against both stored attributes and virtual relational properties.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns bool


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

ParameterTypeDescription
$namestringProperty name.

Returns mixed