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.
Examples
Section titled “Examples”// 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();Methods
Section titled “Methods”__construct()
Section titled “__construct()”ChannelManager constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | The 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
| Parameter | Type | Description |
|---|---|---|
$name | string | The name for the new channel. |
$type (optional) | ChannelType | The channel type. Defaults to TEXT. |
$categoryId (optional) | ?int | The 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
| Parameter | Type | Description |
|---|---|---|
$idOrName | `int | string` |
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!");count()
Section titled “count()”Returns the number of channels currently held in the cache.
Returns int
Example
echo "Cached channels: " . $sharkord->channels->count() . "\n";collection()
Section titled “collection()”Returns the underlying Channels collection.
Returns \ChannelsCollection
Example
foreach ($sharkord->channels->collection() as $id => $channel) { echo "#{$channel->name}\n";}