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.
Examples
Section titled “Examples”$reactions = $message->reactions;
// Total number of distinct emoji typesecho count($reactions);
// Iterate over all emoji groupsforeach ($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 directlyif (isset($reactions['olive'])) { $group = $reactions['olive']; echo $group->count; echo $group->hasUser($sharkord->bot->id);}
// Check whether the message has any reactions at allif ($message->reactions->isEmpty()) { echo "No reactions yet.";}Methods
Section titled “Methods”__construct()
Section titled “__construct()”Reactions constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sharkord | Sharkord | Reference to the main bot instance. |
$rawReactions | array | The raw reactions array from the API payload. |
emojis()
Section titled “emojis()”Returns all emoji shortcode names present on the message.
Returns string[]
isEmpty()
Section titled “isEmpty()”Returns true if the message has no reactions at all.
Returns bool
offsetExists()
Section titled “offsetExists()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | The emoji shortcode name. |
Returns bool
offsetGet()
Section titled “offsetGet()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | The emoji shortcode name. |
Returns \ReactionGroup|null
offsetSet()
Section titled “offsetSet()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed |
Throws
\LogicException— Reaction collections are read-only.
offsetUnset()
Section titled “offsetUnset()”Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
Throws
\LogicException— Reaction collections are read-only.
count()
Section titled “count()”Returns the number of distinct emoji types on the message.
Returns int
getIterator()
Section titled “getIterator()”Returns \ArrayIterator<string,\Sharkord\Collections\Groups\Reactions>