Skip to content

Message

Class  ·  Sharkord\Models\Message

Class Message

Represents a received chat message.

Message constructor.

Parameters

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

Factory method to create a Message from raw API data.

Parameters

ParameterTypeDescription
$rawarray
$sharkordSharkord

Returns self


Replies to this message in the same channel.

Parameters

ParameterTypeDescription
$textstringThe reply content.

Returns \PromiseInterface — Resolves when the message is sent.


Adds or toggles an emoji reaction on a specific message.

Parameters

ParameterTypeDescription
$emojistringThe emoji character(s) to use for the reaction.

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


Edits the content of this message.

Parameters

ParameterTypeDescription
$newContentstringThe new message text.

Returns \PromiseInterface — Resolves with true when the message is edited.


Deletes this message.

Returns \PromiseInterface — Resolves with true when the message is deleted.


Toggles the pinned state of this message.

Sends the togglePin mutation and waits for the subsequent messages.onUpdate subscription event to confirm and return the new pinned state.

Parameters

ParameterTypeDescription
$timeout (optional)intSeconds to wait for the onUpdate confirmation before rejecting.

Returns \PromiseInterface — Resolves with a bool indicating the new pinned state (true = pinned, false = unpinned).


Checks whether this message is currently pinned.

Returns bool — True if the message is pinned, false otherwise.


Returns a complete array of the message data, including fully expanded User, Channel, and Server objects for debugging.

The base attributes array (including raw scalar fields such as reactions) is always present in the return value — expanded keys are layered on top. This makes toArray()['reactions'] ?? [] a safe way to read the raw reactions array before it is wrapped into a Reactions collection.

Returns array

Example

// Full debug dump
var_dump($message->toArray());
// Read the raw reactions array directly
$raw = $message->toArray()['reactions'] ?? [];

Determines whether this message contains any user mentions.

Returns bool — True if the message mentions one or more users, false otherwise.


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 for dynamic properties.

Resolves virtual relational properties before falling through to the raw attributes array, so model consumers never need to know how data is stored internally.

Virtual properties:

  • $message->server Returns the first cached Server via ServerManager.
  • $message->channel Resolves the Channel from ChannelManager using channelId.
  • $message->author Resolves the User from UserManager using userId.
  • $message->user Alias for $message->author.
  • $message->mentions Returns an array of resolved User objects for all user mentions found in the message content.
  • $message->reactions Returns a Reactions collection keyed by emoji shortcode, built from the raw reactions array on this message.

Any other property name is looked up directly in the raw attributes array, returning null if not present.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns mixed