Skip to content

Server

Class  ·  Sharkord\Models\Server

Class Server

Represents the server environment and its settings.

Server constructor.

Parameters

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

Factory method to create a Server from raw API data.

Parameters

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

Returns self


Fetches the full administrative settings for this server.

Convenience wrapper around {@see \Sharkord\Managers\ServerManager::getSettings()}. Returns a {@see \ServerSettings} model containing privileged fields such as secretToken and allowNewUsers that are not included in the public settings.

Requires the MANAGE_SETTINGS permission.

Returns \PromiseInterface — Resolves with a {@see \ServerSettings} instance, rejects on failure.

Example

$server->getSettings()->then(function(\Sharkord\Models\ServerSettings $settings) {
echo "Server: {$settings->name}\n";
echo "Allow signup: " . ($settings->allowNewUsers ? 'Yes' : 'No') . "\n";
});

Updates one or more server settings.

Convenience wrapper that fetches the current {@see \ServerSettings} and delegates to {@see \ServerSettings::update()}. The server will broadcast an onServerSettingsUpdate event, which updates the cached Server model automatically.

Requires the MANAGE_SETTINGS permission.

Parameters

ParameterTypeDescription
$name (optional)?stringNew server display name.
$description (optional)?stringNew server description.
$password (optional)?stringNew server password. Pass an empty string to remove.
$allowNewUsers (optional)?boolWhether to permit new user registrations.
$directMessagesEnabled (optional)?boolWhether to enable direct messaging server-wide.
$enablePlugins (optional)?boolWhether to enable server plugins.
$enableSearch (optional)?boolWhether to enable server-wide search.

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

Example

$server->edit(name: 'The Boyz', allowNewUsers: false)->then(function() {
echo "Settings updated!\n";
});

Returns all the attributes as an array. Perfect for debugging!

Returns array

Example

var_dump($sharkord->servers->getFirst()?->toArray());

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 whenever you try to access a property that isn’t explicitly defined.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns mixed