DmManager
Class · Sharkord\Managers\DmManager
Class DmManager
Manages direct message interactions with the Sharkord API. Accessible via $sharkord->dms.
Examples
Section titled “Examples”// 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!");});Methods
Section titled “Methods”__construct()
Section titled “__construct()”DmManager constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | The main bot instance. |
open()
Section titled “open()”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
| Parameter | Type | Description |
|---|---|---|
$userId | int | The 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"; }});