Skip to content

Reactions

Class  ·  Sharkord\Collections\Reactions

Class Reactions

An array-accessible, iterable collection of reaction group objects keyed by emoji shortcode name.

Built from the raw reactions array on a Message, grouping individual reactions by their emoji so callers can work with them naturally.

$reactions = $message->reactions;
// Total number of distinct emoji types
echo count($reactions);
// Iterate over all emoji groups
foreach ($reactions as $emoji => $group) {
echo ":{$emoji}: — {$group->count} reaction(s)\n";
foreach ($group->users as $user) {
echo " {$user->name}\n";
}
}
// Access a specific emoji group directly
if (isset($reactions['olive'])) {
$group = $reactions['olive'];
echo $group->count;
echo $group->hasUser($sharkord->bot->id);
}
// Check whether the message has any reactions at all
if ($message->reactions->isEmpty()) {
echo "No reactions yet.";
}

Reactions constructor.

Parameters

ParameterTypeDescription
$sharkordSharkordReference to the main bot instance.
$rawReactionsarrayThe raw reactions array from the API payload.

Returns all emoji shortcode names present on the message.

Returns string[]


Returns true if the message has no reactions at all.

Returns bool


Parameters

ParameterTypeDescription
$offsetmixedThe emoji shortcode name.

Returns bool


Parameters

ParameterTypeDescription
$offsetmixedThe emoji shortcode name.

Returns \ReactionGroup|null


Parameters

ParameterTypeDescription
$offsetmixed
$valuemixed

Throws

  • \LogicException — Reaction collections are read-only.

Parameters

ParameterTypeDescription
$offsetmixed

Throws

  • \LogicException — Reaction collections are read-only.

Returns the number of distinct emoji types on the message.

Returns int


Returns \ArrayIterator<string,\Sharkord\Collections\Groups\Reactions>