ServerManager
Class · Sharkord\Managers\ServerManager
Class ServerManager
Manages server lifecycle events, delegating all cache storage to a Servers collection instance.
Accessible via $sharkord->servers.
Examples
Section titled “Examples”// Most bots only operate in one server — getFirst() is the common pattern.$server = $sharkord->servers->getFirst();echo "Connected to: {$server->name}\n";
$sharkord->on(\Sharkord\Events::SERVER_UPDATE, function(\Sharkord\Models\Server $server): void { echo "Server settings updated. Name is now: {$server->name}\n";});Methods
Section titled “Methods”__construct()
Section titled “__construct()”ServerManager constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | The main bot instance. |
getSettings()
Section titled “getSettings()”Fetches the full administrative settings for the server via others.getSettings.
Returns a {@see \ServerSettings} model containing privileged fields such as
secretToken and allowNewUsers that are not included in the public
settings payload available on the {@see \Sharkord\Models\Server} model.
Requires the MANAGE_SETTINGS permission. The guard check runs locally before any network request is made, so callers receive a rejected Promise immediately rather than waiting for a round-trip API error.
Always performs a live API request — settings are not cached between calls.
Returns \PromiseInterface — Resolves with a {@see \ServerSettings} instance, rejects on failure.
Example
$sharkord->servers->getSettings()->then(function (\Sharkord\Models\ServerSettings $settings) { echo "Name: {$settings->name}\n"; echo "Allow signup: " . ($settings->allowNewUsers ? 'Yes' : 'No') . "\n"; echo "DMs enabled: " . ($settings->directMessagesEnabled ? 'Yes' : 'No') . "\n";
if ($settings->logo) { echo "Logo file: {$settings->logo->originalName}\n"; }})->catch(function (\Throwable $e) { // Fires immediately (no round-trip) if the bot lacks MANAGE_SETTINGS. echo "Access denied: {$e->getMessage()}\n";});getFirst()
Section titled “getFirst()”Retrieves the first (or only) server in the cache.
The preferred pattern for single-server bots.
Returns \Server|null — The first cached Server model, or null if the cache is empty.
Example
$server = $sharkord->servers->getFirst();
if ($server) { echo "Connected to: {$server->name}\n";}Retrieves a server by ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
$serverId | string | The server ID. |
Returns \Server|null — The cached Server model, or null if not found.
Example
$server = $sharkord->servers->get('abc123');
if ($server) { echo "Server: {$server->name}\n";}collection()
Section titled “collection()”Returns the underlying Servers collection.
Returns \ServersCollection
Example
foreach ($sharkord->servers->collection() as $id => $server) { echo "{$id}: {$server->name}\n";}