Skip to content

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.

$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();
}
}
});

DirectMessage constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordReference to the main bot instance.
$channelIdintThe channel ID for this DM thread.
$userIdintThe ID of the other user in the DM thread.
$unreadCountintThe number of unread messages in this thread.
$lastMessageAtintUnix timestamp (ms) of the last message.

Factory method to create a DirectMessage from a raw API data array.

Parameters

ParameterTypeDescription
$rawarrayThe raw DM data array from the API.
$sharkordSharkordReference to the main bot instance.

Returns self


Sends a text message into this DM thread.

Parameters

ParameterTypeDescription
$textstringThe message content.

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

Example

$sharkord->dms->get()->then(function(array $dms) {
$dms[0]->send("Hello!");
});

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

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.


Returns the resolved Channel object for this DM thread.

Returns \Channel|null — The Channel model, or null if not found in cache.


Returns the DirectMessage data as a plain array. Useful for debugging.

Returns array


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

ParameterTypeDescription
$namestringProperty name.

Returns mixed


Magic isset check.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns bool