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
$rawarrayThe raw user data from the server.
$sharkordSharkordReference to the main bot instance.

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.

Example

if ($user->hasPermission(\Sharkord\Permission::MANAGE_CHANNELS)) {
echo "{$user->name} can manage channels.\n";
}

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";
}

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.

Example

if ($user->hasRole(3)) {
echo "{$user->name} has the Moderator role.\n";
}

Bans a user from the server.

Parameters

ParameterTypeDescription
$reason (optional)stringThe 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";
});

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

Kicks a user from the server.

Parameters

ParameterTypeDescription
$reason (optional)stringThe 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";
});

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.

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

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

Example

var_dump($user->toArray());

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