Invite
Class · Sharkord\Models\Invite
Class Invite
Represents a server invite link.
Instances are returned by {@see \Sharkord\Managers\InviteManager::getAll()} and {@see \Sharkord\Managers\InviteManager::create()}, and are cached by {@see \Sharkord\Collections\Invites}.
Examples
Section titled “Examples”$sharkord->invites->getAll()->then(function (array $invites) { foreach ($invites as $invite) { $uses = $invite->maxUses !== null ? "{$invite->uses}/{$invite->maxUses}" : "{$invite->uses}/∞"; $expiry = $invite->expiresAt !== null ? date('Y-m-d', (int) ($invite->expiresAt / 1000)) : 'never'; $creator = $invite->creator?->name ?? "Unknown (ID {$invite->creatorId})";
echo "[{$invite->code}] by {$creator} — used {$uses} — expires {$expiry}\n"; }});Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
$id (read-only) | int | Unique invite ID. |
$code (read-only) | string | The invite code used in join URLs. |
$creatorId (read-only) | int | User ID of the user who created the invite. |
$roleId (read-only) | `int | null` |
$maxUses (read-only) | `int | null` |
$uses (read-only) | int | Number of times this invite has been used. |
$expiresAt (read-only) | `int | null` |
$createdAt (read-only) | int | Creation timestamp in milliseconds. |
$creator (read-only) | `\Sharkord\Models\User | null` |
$role (read-only) | `\Sharkord\Models\Role | null` |
Methods
Section titled “Methods”__construct()
Section titled “__construct()”Invite constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
$rawData | array | The raw invite payload from the API. |
static fromArray()
Section titled “static fromArray()”Factory method to create an Invite from a raw API data array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | array | The raw invite payload. |
$sharkord | Sharkord | Reference to the main bot instance. |
Returns self
delete()
Section titled “delete()”Deletes this invite via the invites.delete RPC.
Requires either ownership of the invite (i.e. the bot created it) or the MANAGE_INVITES permission.
Returns \PromiseInterface — Resolves with true on success, rejects on failure.
Example
$sharkord->invites->getAll()->then(function (array $invites) { foreach ($invites as $invite) { if ($invite->uses === 0) { $invite->delete()->then(function () use ($invite) { echo "Deleted unused invite: {$invite->code}\n"; }); } }});toArray()
Section titled “toArray()”Returns the invite data as a plain array.
Returns array<string,mixed>
__isset()
Section titled “__isset()”Magic isset check. Supports virtual relational properties creator and role.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns bool
__get()
Section titled “__get()”Magic getter.
Virtual properties:
$invite->creatorResolves the creator User from the UserManager cache.$invite->roleResolves the assigned Role from the RoleManager cache.
All other names are looked up in the raw attributes array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Property name. |
Returns mixed