Channel
Class · Sharkord\Models\Channel
Class Channel
Represents a chat channel on the server.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
$category (read-only) | `\Category | null` |
Methods
Section titled “Methods”__construct()
Section titled “__construct()”Channel constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
$rawData | array | The raw array of data from the API. |
static fromArray()
Section titled “static fromArray()”Factory method to create a Channel from raw API data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | array | The raw channel data from the server. |
$sharkord | Sharkord | Reference to the main bot instance. |
Returns self
sendMessage()
Section titled “sendMessage()”Sends a message to this channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
$text | string | The message content. |
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$sharkord->channels->get('general')->sendMessage('Hello, world!');sendTyping()
Section titled “sendTyping()”Sends a single typing indicator signal to this channel.
The indicator will be visible to other users for approximately 800ms. For longer operations, use sendTypingWhile() instead.
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
sendTypingWhile()
Section titled “sendTypingWhile()”Sends a repeating typing indicator for the duration of a pending Promise.
Fires a typing signal immediately and then every 700ms until the given Promise resolves or rejects, ensuring the indicator stays visible throughout. The result or rejection of the given Promise is passed through transparently.
Parameters
| Parameter | Type | Description |
|---|---|---|
$promise | PromiseInterface | The operation to show a typing indicator for. |
Returns \PromiseInterface — Resolves or rejects with the same value as the given Promise.
markAsRead()
Section titled “markAsRead()”Marks all messages in this channel (or DM thread) as read.
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$sharkord->channels->get('general')->markAsRead();fetch()
Section titled “fetch()”Fetches the latest channel data from the server and updates the local cache.
Useful after making changes to a channel to confirm the server’s current state. The cached Channel model is updated in-place; any existing references remain valid.
Returns \PromiseInterface — Resolves with the updated Channel model, rejects on failure.
Example
$channel->edit('Renamed Channel')->then(function() use ($channel) { return $channel->fetch();})->then(function(\Sharkord\Models\Channel $channel) { echo "Server confirms name: {$channel->name}\n";});edit()
Section titled “edit()”Edits this channel’s name, topic, and/or visibility.
Requires the MANAGE_CHANNELS permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The new channel name. |
$topic (optional) | ?string | The new channel topic, or null to leave it unchanged. |
$private (optional) | ?bool | Whether the channel should be private, or null to leave it unchanged. |
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
// Rename and set a topic$sharkord->channels->get('general')->edit('general', 'Welcome to general chat!');
// Make a channel private$sharkord->channels->get('staff')->edit('staff', null, true);
// Rename, set a topic, and make private in one call$sharkord->channels->get('announcements')->edit('news', 'Official news feed.', true);delete()
Section titled “delete()”Permanently deletes this channel from the server.
Requires the MANAGE_CHANNELS permission. The channel is removed from the local cache once the server emits the corresponding channeldelete event.
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$sharkord->channels->get('old-channel')->delete()->then(function() { echo "Channel deleted.\n";});getPermissions()
Section titled “getPermissions()”Retrieves all current role and user permission entries for this channel.
Requires the MANAGE_CHANNEL_PERMISSIONS permission.
Resolves with an associative array containing:
rolePermissions— array of {@see \ChannelRolePermission} objects, one per flag per role.userPermissions— raw array of user-level overrides (not yet modelled).
Returns \PromiseInterface — Resolves with array{rolePermissions: ChannelRolePermission[], userPermissions: array}, rejects on failure.
Example
$channel->getPermissions()->then(function(array $permissions) { foreach ($permissions['rolePermissions'] as $entry) { $state = $entry->allow ? 'allow' : 'deny'; echo "Role {$entry->roleId} — {$entry->permission->value}: {$state}\n"; }});addRolePermission()
Section titled “addRolePermission()”Adds a role to this channel’s permission set, initialising all flags at their defaults.
This must be called before setRolePermissions() when granting a role access to a channel for the first time. Subsequent permission changes should use setRolePermissions().
Requires the MANAGE_CHANNEL_PERMISSIONS permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleId | int | The ID of the role to add. |
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$channel->addRolePermission(2)->then(function() use ($channel) { return $channel->setRolePermissions( 2, \Sharkord\ChannelPermissionFlag::VIEW_CHANNEL, \Sharkord\ChannelPermissionFlag::SEND_MESSAGES, );});setRolePermissions()
Section titled “setRolePermissions()”Sets the allowed permission flags for a role on this channel.
Replaces the role’s current permission set with the provided flags. Any flag not included in the list will be set to denied. The role must already have been added via addRolePermission() before calling this method.
Requires the MANAGE_CHANNEL_PERMISSIONS permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleId | int | The ID of the role to update. |
...$permissions | ChannelPermissionFlag | One or more permission flags to allow. |
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$channel->setRolePermissions( 2, \Sharkord\ChannelPermissionFlag::VIEW_CHANNEL, \Sharkord\ChannelPermissionFlag::SEND_MESSAGES, \Sharkord\ChannelPermissionFlag::JOIN,);removeRolePermission()
Section titled “removeRolePermission()”Removes a role entirely from this channel’s permission set.
All per-flag entries for the role are deleted. Requires the MANAGE_CHANNEL_PERMISSIONS permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleId | int | The ID of the role to remove. |
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$channel->removeRolePermission(2)->then(function() { echo "Role removed from channel.\n";});toArray()
Section titled “toArray()”Returns all the attributes as a plain array. Useful for debugging.
Returns array
__isset()
Section titled “__isset()”Magic isset check. Allows isset() and empty() to work correctly against both stored attributes and virtual relational properties.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns bool
__get()
Section titled “__get()”Magic getter. Triggered when accessing any property not explicitly defined.
Virtual properties:
- $channel->category Returns the resolved Category via CategoryManager.
Any other name is looked up directly in the raw attributes array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns mixed