Skip to content

ChannelManager

Class  ·  Sharkord\Managers\ChannelManager

Class ChannelManager

Manages channel lifecycle events and exposes actions for creating channels. Delegates all cache storage to a Channels collection instance.

Accessible via $sharkord->channels.

// Create a new text channel
$sharkord->channels->add('announcements', \Sharkord\ChannelType::TEXT, 3)
->then(function(\Sharkord\Models\Channel $channel) {
echo "Created #{$channel->name} (ID: {$channel->id})\n";
});
// Look up a cached channel and edit it
$sharkord->channels->get('announcements')?->edit('news', 'Official news feed.');
// Delete a channel by name
$sharkord->channels->get('old-channel')?->delete();

ChannelManager constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordThe main bot instance.

Creates a new channel on the server.

Sends the channels.add mutation, then immediately fetches the full channel data via channels.get and hydrates it into the local cache. The returned Channel model is ready for use without waiting for a server-pushed event.

Requires the MANAGE_CHANNELS permission.

Parameters

ParameterTypeDescription
$namestringThe name for the new channel.
$type (optional)ChannelTypeThe channel type. Defaults to TEXT.
$categoryId (optional)?intThe ID of the category to place the channel in, or null.

Returns \PromiseInterface — Resolves with the new Channel model, rejects on failure.

Example

// Create a basic text channel
$sharkord->channels->add('bot-logs')->then(function(\Sharkord\Models\Channel $channel) {
$channel->sendMessage("Channel ready.");
});
// Create a voice channel inside a specific category
$sharkord->channels->add('Voice Chat', \Sharkord\ChannelType::VOICE, 3);

Retrieves a cached channel by ID or name.

Parameters

ParameterTypeDescription
$idOrName`intstring`

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

Example

$channel = $sharkord->channels->get('general');
$channel?->sendMessage("Hello!");
$channel = $sharkord->channels->get(42);
$channel?->sendMessage("Hello by ID!");

Returns the number of channels currently held in the cache.

Returns int

Example

echo "Cached channels: " . $sharkord->channels->count() . "\n";

Returns the underlying Channels collection.

Returns \ChannelsCollection

Example

foreach ($sharkord->channels->collection() as $id => $channel) {
echo "#{$channel->name}\n";
}