Message
Class · Sharkord\Models\Message
Class Message
Represents a received chat message.
Methods
Section titled “Methods”__construct()
Section titled “__construct()”Message constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
$rawData | array | The raw array of data from the API. |
static fromArray()
Section titled “static fromArray()”Factory method to create a Message from raw API data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | array | |
$sharkord | Sharkord |
Returns self
reply()
Section titled “reply()”Replies to this message in the same channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
$text | string | The reply content. |
Returns \PromiseInterface — Resolves when the message is sent.
react()
Section titled “react()”Adds or toggles an emoji reaction on a specific message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$emoji | string | The emoji character(s) to use for the reaction. |
Returns \PromiseInterface — Resolves on success, rejects on failure.
edit()
Section titled “edit()”Edits the content of this message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$newContent | string | The new message text. |
Returns \PromiseInterface — Resolves with true when the message is edited.
delete()
Section titled “delete()”Deletes this message.
Returns \PromiseInterface — Resolves with true when the message is deleted.
togglePin()
Section titled “togglePin()”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
| Parameter | Type | Description |
|---|---|---|
$timeout (optional) | int | Seconds to wait for the onUpdate confirmation before rejecting. |
Returns \PromiseInterface — Resolves with a bool indicating the new pinned state (true = pinned, false = unpinned).
isPinned()
Section titled “isPinned()”Checks whether this message is currently pinned.
Returns bool — True if the message is pinned, false otherwise.
toArray()
Section titled “toArray()”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 dumpvar_dump($message->toArray());
// Read the raw reactions array directly$raw = $message->toArray()['reactions'] ?? [];hasMentions()
Section titled “hasMentions()”Determines whether this message contains any user mentions.
Returns bool — True if the message mentions one or more users, false otherwise.
__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 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
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns mixed