Skip to content

DmManager

Class  ·  Sharkord\Managers\DmManager

Class DmManager

Manages direct message interactions with the Sharkord API. Accessible via $sharkord->dms.

// Send a DM directly from a User object
$user->sendDm("Hey there!");
// Open a DM channel and use it directly
$user->openDm()->then(function(Channel $channel) {
$channel->sendMessage("Hello from the channel object!");
$channel->markAsRead();
});
// List all existing DM threads
$sharkord->dms->get()->then(function(array $dms) {
foreach ($dms as $dm) {
echo "{$dm->user->name}: {$dm->unreadCount} unread\n";
$dm->markRead();
}
});
// Open a DM channel by user ID
$sharkord->dms->open(5)->then(function(Channel $channel) {
$channel->sendMessage("Hello!");
});

DmManager constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordThe main bot instance.

Opens a DM channel with the specified user.

If the DM channel does not yet exist on the server it will be created. The resolved Channel may not be present in the channel cache if this is the first time a DM has been opened with this user — in that case the returned Channel is constructed directly from the response data.

Parameters

ParameterTypeDescription
$userIdintThe ID of the user to open a DM with.

Returns \PromiseInterface — Resolves with a Channel object, rejects on failure.

Example

$sharkord->dms->open(5)->then(function(Channel $channel) {
$channel->sendMessage("Hello!");
});

Retrieves all DM threads the bot currently has open.

Returns \PromiseInterface — Resolves with an array of DirectMessage objects, rejects on failure.

Example

$sharkord->dms->get()->then(function(array $dms) {
foreach ($dms as $dm) {
echo "{$dm->user->name} — last message: {$dm->lastMessageAt}\n";
}
});