DirectMessage
Class · Sharkord\Models\DirectMessage
Class DirectMessage
Represents a direct message thread between the bot and another user, as returned by the dms.get API endpoint.
Examples
Section titled “Examples”$sharkord->dms->get()->then(function(array $dms) { foreach ($dms as $dm) { echo "{$dm->user->name}: {$dm->unreadCount} unread\n";
if ($dm->unreadCount > 0) { $dm->markRead(); } }});Methods
Section titled “Methods”__construct()
Section titled “__construct()”DirectMessage constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
$channelId | int | The channel ID for this DM thread. |
$userId | int | The ID of the other user in the DM thread. |
$unreadCount | int | The number of unread messages in this thread. |
$lastMessageAt | int | Unix timestamp (ms) of the last message. |
static fromArray()
Section titled “static fromArray()”Factory method to create a DirectMessage from a raw API data array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | array | The raw DM data array from the API. |
$sharkord | Sharkord | Reference to the main bot instance. |
Returns self
send()
Section titled “send()”Sends a text message into this DM thread.
Parameters
| Parameter | Type | Description |
|---|---|---|
$text | string | The message content. |
Returns \PromiseInterface — Resolves on success, rejects on failure.
Example
$sharkord->dms->get()->then(function(array $dms) { $dms[0]->send("Hello!");});markRead()
Section titled “markRead()”Marks all messages in this DM thread as read.
Returns \PromiseInterface — Resolves on success, rejects on failure.
Example
$sharkord->dms->get()->then(function(array $dms) { foreach ($dms as $dm) { if ($dm->unreadCount > 0) { $dm->markRead(); } }});getUser()
Section titled “getUser()”Returns the resolved User object for the other participant in this DM.
Returns \User|null — The User model, or null if not found in cache.
getChannel()
Section titled “getChannel()”Returns the resolved Channel object for this DM thread.
Returns \Channel|null — The Channel model, or null if not found in cache.
toArray()
Section titled “toArray()”Returns the DirectMessage data as a plain array. Useful for debugging.
Returns array
__get()
Section titled “__get()”Magic getter. Provides shorthand property-style access to resolved models.
Supported virtual properties:
- $dm->user Returns the resolved User object via UserManager.
- $dm->channel Returns the resolved Channel object via ChannelManager.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns mixed
__isset()
Section titled “__isset()”Magic isset check.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns bool