Skip to content

Events

Class  ·  Sharkord\Events

Class Events

Centralised registry of every event name emitted by the SharkordPHP framework.

Use these constants anywhere you register a listener via {@see \Sharkord\Sharkord::on()} to benefit from IDE autocompletion, static analysis, and a single source of truth for event name strings.

Each constant’s value is the exact string passed to {@see \Evenement\EventEmitter::emit()} internally, so the two styles are always interchangeable:

$sharkord->on('message', $handler);
$sharkord->on(Events::MESSAGE_CREATE, $handler);

Value 'ready'

Fired once the bot has fully connected, hydrated its caches, and is ready to receive and dispatch events.

Callback signature: function(\Sharkord\Models\User $bot): void

Example

$sharkord->on(Events::READY, function(\Sharkord\Models\User $bot): void {
echo "Logged in as {$bot->name}!";
});

Value 'message'

Fired when a new message is posted to any channel.

Callback signature: function(\Sharkord\Models\Message $message): void

Example

$sharkord->on(Events::MESSAGE_CREATE, function(\Sharkord\Models\Message $message): void {
echo "{$message->author->name}: {$message->content}";
});

Value 'messageupdate'

Fired when an existing message is edited.

Callback signature: function(\Sharkord\Models\Message $message): void

Example

$sharkord->on(Events::MESSAGE_UPDATE, function(\Sharkord\Models\Message $message): void {
echo "Message {$message->id} was updated.";
});

Value 'messagedelete'

Fired when a message is deleted.

Because the message no longer exists on the server, the full model cannot be reconstructed. The raw payload array is passed directly instead. The array is guaranteed to contain a scalar id key; channelId is present where the server includes it but must be treated as optional.

Callback signature: function(array $data): void

Example

$sharkord->on(Events::MESSAGE_DELETE, function(array $data): void {
$messageId = $data['id'];
$channelId = $data['channelId'] ?? null;
echo "Message {$messageId} was deleted"
. ($channelId ? " from channel {$channelId}" : '') . '.';
});

Value 'messagereaction'

Fired when the reaction set on a message changes.

Only emitted when a messageupdate payload contains a reactions key and the reaction data has actually changed since the previous state.

Callback signature: function(\Sharkord\Models\Message $message, array $reactions): void

Example

$sharkord->on(Events::MESSAGE_REACTION, function(
\Sharkord\Models\Message $message,
array $reactions,
): void {
echo "Message {$message->id} reactions updated.";
});

Value 'messagetyping'

Fired when a user begins typing in a channel.

Both the User and Channel must be resolvable from cache; if either is missing the event is silently dropped.

Callback signature: function(\Sharkord\Models\User $user, \Sharkord\Models\Channel $channel): void

Example

$sharkord->on(Events::MESSAGE_TYPING, function(
\Sharkord\Models\User $user,
\Sharkord\Models\Channel $channel,
): void {
echo "{$user->name} is typing in #{$channel->name}...";
});

Value 'channelcreate'

Fired when a new channel is created.

Callback signature: function(\Sharkord\Models\Channel $channel): void

Example

$sharkord->on(Events::CHANNEL_CREATE, function(\Sharkord\Models\Channel $channel): void {
echo "Channel #{$channel->name} was created.";
});

Value 'channelupdate'

Fired when an existing channel is updated.

Callback signature: function(\Sharkord\Models\Channel $channel): void

Example

$sharkord->on(Events::CHANNEL_UPDATE, function(\Sharkord\Models\Channel $channel): void {
echo "Channel #{$channel->name} was updated.";
});

Value 'channeldelete'

Fired just before a channel is removed from the cache.

The Channel model is still fully populated at the time the event fires.

Callback signature: function(\Sharkord\Models\Channel $channel): void

Example

$sharkord->on(Events::CHANNEL_DELETE, function(\Sharkord\Models\Channel $channel): void {
echo "Channel #{$channel->name} was deleted.";
});

Value 'usercreate'

Fired when a new user account is created on the server.

Callback signature: function(\Sharkord\Models\User $user): void

Example

$sharkord->on(Events::USER_CREATE, function(\Sharkord\Models\User $user): void {
echo "New user registered: {$user->name}.";
});

Value 'userjoin'

Fired when a user comes online (connects to the server).

The user’s status will already be set to 'online' when the callback fires.

Callback signature: function(\Sharkord\Models\User $user): void

Example

$sharkord->on(Events::USER_JOIN, function(\Sharkord\Models\User $user): void {
echo "{$user->name} just came online.";
});

Value 'userleave'

Fired when a user goes offline (disconnects from the server).

The user’s status will already be set to 'offline' when the callback fires.

Callback signature: function(\Sharkord\Models\User $user): void

Example

$sharkord->on(Events::USER_LEAVE, function(\Sharkord\Models\User $user): void {
echo "{$user->name} went offline.";
});

Value 'userdelete'

Fired just before a user is permanently removed from the cache.

The User model is still fully populated at the time the event fires.

Callback signature: function(\Sharkord\Models\User $user): void

Example

$sharkord->on(Events::USER_DELETE, function(\Sharkord\Models\User $user): void {
echo "User {$user->name} was deleted from the server.";
});

Value 'namechange'

Fired when a user changes their display name.

The User model reflects the new name at the time the callback fires.

Callback signature: function(\Sharkord\Models\User $user): void

Example

$sharkord->on(Events::USER_NAME_CHANGE, function(\Sharkord\Models\User $user): void {
echo "A user changed their name to {$user->name}.";
});

Value 'ban'

Fired when a user is banned from the server.

Callback signature: function(\Sharkord\Models\User $user): void

Example

$sharkord->on(Events::USER_BAN, function(\Sharkord\Models\User $user): void {
echo "{$user->name} has been banned.";
});

Value 'unban'

Fired when a user’s ban is lifted.

Callback signature: function(\Sharkord\Models\User $user): void

Example

$sharkord->on(Events::USER_UNBAN, function(\Sharkord\Models\User $user): void {
echo "{$user->name} has been unbanned.";
});

Value 'rolecreate'

Fired when a new role is created.

Callback signature: function(\Sharkord\Models\Role $role): void

Example

$sharkord->on(Events::ROLE_CREATE, function(\Sharkord\Models\Role $role): void {
echo "Role '{$role->name}' was created.";
});

Value 'roleupdate'

Fired when an existing role is updated.

Callback signature: function(\Sharkord\Models\Role $role): void

Example

$sharkord->on(Events::ROLE_UPDATE, function(\Sharkord\Models\Role $role): void {
echo "Role '{$role->name}' was updated.";
});

Value 'roledelete'

Fired just before a role is removed from the cache.

The Role model is still fully populated at the time the event fires.

Callback signature: function(\Sharkord\Models\Role $role): void

Example

$sharkord->on(Events::ROLE_DELETE, function(\Sharkord\Models\Role $role): void {
echo "Role '{$role->name}' was deleted.";
});

Value 'categorycreate'

Fired when a new category is created.

Callback signature: function(\Sharkord\Models\Category $category): void

Example

$sharkord->on(Events::CATEGORY_CREATE, function(\Sharkord\Models\Category $category): void {
echo "Category '{$category->name}' was created.";
});

Value 'categoryupdate'

Fired when an existing category is updated.

Callback signature: function(\Sharkord\Models\Category $category): void

Example

$sharkord->on(Events::CATEGORY_UPDATE, function(\Sharkord\Models\Category $category): void {
echo "Category '{$category->name}' was updated.";
});

Value 'categorydelete'

Fired just before a category is removed from the cache.

The Category model is still fully populated at the time the event fires.

Callback signature: function(\Sharkord\Models\Category $category): void

Example

$sharkord->on(Events::CATEGORY_DELETE, function(\Sharkord\Models\Category $category): void {
echo "Category '{$category->name}' was deleted.";
});

Value 'serverupdate'

Fired when the server’s public settings are updated (e.g. name, description).

Callback signature: function(\Sharkord\Models\Server $server): void

Example

$sharkord->on(Events::SERVER_UPDATE, function(\Sharkord\Models\Server $server): void {
echo "Server settings updated. Name is now: {$server->name}";
});