Skip to content

Channel

Class  ·  Sharkord\Models\Channel

Class Channel

Represents a chat channel on the server.

PropertyTypeDescription
$category (read-only)`\Categorynull`

Channel constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordReference to the main bot instance.
$rawDataarrayThe raw array of data from the API.

Factory method to create a Channel from raw API data.

Parameters

ParameterTypeDescription
$rawarrayThe raw channel data from the server.
$sharkordSharkordReference to the main bot instance.

Returns self


Sends a message to this channel.

Parameters

ParameterTypeDescription
$textstringThe message content.

Returns \PromiseInterface — Resolves with true on success, rejects on failure.

Example

$sharkord->channels->get('general')->sendMessage('Hello, world!');

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.


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

ParameterTypeDescription
$promisePromiseInterfaceThe operation to show a typing indicator for.

Returns \PromiseInterface — Resolves or rejects with the same value as the given Promise.


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();

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";
});

Edits this channel’s name, topic, and/or visibility.

Requires the MANAGE_CHANNELS permission.

Parameters

ParameterTypeDescription
$namestringThe new channel name.
$topic (optional)?stringThe new channel topic, or null to leave it unchanged.
$private (optional)?boolWhether 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);

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";
});

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";
}
});

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

ParameterTypeDescription
$roleIdintThe 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,
);
});

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

ParameterTypeDescription
$roleIdintThe ID of the role to update.
...$permissionsChannelPermissionFlagOne 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,
);

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

ParameterTypeDescription
$roleIdintThe 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";
});

Returns all the attributes as a plain array. Useful for debugging.

Returns array


Magic isset check. Allows isset() and empty() to work correctly against both stored attributes and virtual relational properties.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns bool


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

ParameterTypeDescription
$namestringProperty name.

Returns mixed