Skip to content

Category

Class  ·  Sharkord\Models\Category

Class Category

Represents a channel category on the server.

// Rename a category
$sharkord->categories->get(3)?->edit('Renamed Category')->then(function() {
echo "Category renamed.\n";
});
// Delete a category
$sharkord->categories->get(3)?->delete()->then(function() {
echo "Category deleted.\n";
});
// Re-fetch the latest data from the server
$sharkord->categories->get(3)?->fetch()->then(function(\Sharkord\Models\Category $category) {
echo "Refreshed: {$category->name}\n";
});

Category constructor.

Parameters

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

Factory method to create a Category from raw API data.

Parameters

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

Returns self


Re-fetches this category’s data from the server and updates the local model.

Useful when you need guaranteed up-to-date data outside of a subscription event (e.g. after a reorder).

Returns \PromiseInterface — Resolves with this Category model (updated in place), rejects on failure.

Example

$sharkord->categories->get(3)?->fetch()->then(function(\Sharkord\Models\Category $category) {
echo "Current position: {$category->position}\n";
});

Renames this category.

The server will push a categories.onUpdate event once the change is accepted. The cached model is updated automatically via the subscription handler.

Requires the MANAGE_CATEGORIES permission.

Parameters

ParameterTypeDescription
$namestringThe new category name.

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

Example

$sharkord->categories->get(3)?->edit('🏉 Footy Talk')->then(function() {
echo "Category renamed.\n";
});

Permanently deletes this category from the server.

Requires the MANAGE_CATEGORIES permission. The category is removed from the local cache once the server emits the corresponding categorydelete event.

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

Example

$sharkord->categories->get(7)?->delete()->then(function() {
echo "Category deleted.\n";
});

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

Returns array<string,mixed>

Example

var_dump($sharkord->categories->get(3)?->toArray());

Magic isset check. Allows isset() and empty() to work correctly against dynamic properties stored in the attributes array.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns bool


Magic getter. Triggered whenever you try to access a property that isn’t explicitly defined (e.g. $category->name or $category->position).

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns mixed