Skip to content

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}.

$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";
}
});
PropertyTypeDescription
$id (read-only)intUnique invite ID.
$code (read-only)stringThe invite code used in join URLs.
$creatorId (read-only)intUser ID of the user who created the invite.
$roleId (read-only)`intnull`
$maxUses (read-only)`intnull`
$uses (read-only)intNumber of times this invite has been used.
$expiresAt (read-only)`intnull`
$createdAt (read-only)intCreation timestamp in milliseconds.
$creator (read-only)`\Sharkord\Models\Usernull`
$role (read-only)`\Sharkord\Models\Rolenull`

Invite constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordReference to the main bot instance.
$rawDataarrayThe raw invite payload from the API.

Factory method to create an Invite from a raw API data array.

Parameters

ParameterTypeDescription
$rawarrayThe raw invite payload.
$sharkordSharkordReference to the main bot instance.

Returns self


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

Returns the invite data as a plain array.

Returns array<string,mixed>


Magic isset check. Supports virtual relational properties creator and role.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns bool


Magic getter.

Virtual properties:

  • $invite->creator Resolves the creator User from the UserManager cache.
  • $invite->role Resolves the assigned Role from the RoleManager cache.

All other names are looked up in the raw attributes array.

Parameters

ParameterTypeDescription
$namestringProperty name.

Returns mixed