Skip to content
SQKo edited this page Dec 9, 2023 · 3 revisions

Reactions are part of Message.

use Discord\Parts\Channel\Reaction;

Represents a reaction to a message by members(s).

Requires GUILD_MESSAGE_REACTIONS intent for guild, or DIRECT_MESSAGE_REACTIONS intent for direct message

MESSAGE_REACTION_ADD

MESSAGE_REACTION_REMOVE

MESSAGE_REACTION_REMOVE_ALL

MESSAGE_REACTION_REMOVE_EMOJI


React to a message

Your BOT must have add_reactions permission

You must first get the Message object to use the code below

Adds a reaction $emoji to the $message:

$message->react($emoji)->then(function () {
    // ...
})->done();

https://discord.com/developers/docs/resources/channel#create-reaction

Or with Unicode Emoji:

$message->react('😀')->then(function () {
    // ...
})->done();

Or with Custom Emoji:

$message->react(':michael:251127796439449631')->then(function () {
    // ...
})->done();

Delete Reaction(s) from a Message

Your BOT must have manage_messages permission (except REACT_DELETE_ME)

You must first get the Message object to use the code below

Delete all reactions

(e.g. delete all [😀1][❤️2])

$message->deleteReaction(Message::REACT_DELETE_ALL)->then(function () {
    // ...
})->done();

https://discord.com/developers/docs/resources/channel#delete-all-reactions

Delete reaction by current user

(e.g. the bot reacted 😀 so [😀4] becomes [😀3]):

$message->deleteReaction(Message::REACT_DELETE_ME, $emoji)->then(function () {
    // ...
})->done();

https://discord.com/developers/docs/resources/channel#delete-own-reaction

Delete reaction by another user

(e.g. an user reacted 😀 so [😀2] becomes [😀1]), change 123123123123123123 with User ID:

$message->deleteReaction(Message::REACT_DELETE_ID, $emoji, '123123123123123123')->then(function () {
    // ...
})->done();

https://discord.com/developers/docs/resources/channel#delete-user-reaction

Delete all reactions of one emoji

(e.g. deleting 😂 from [😀1][😂4][❤️2] becomes [😀1][❤️2])

$message->deleteReaction(Message::REACT_DELETE_EMOJI, $emoji)->then(function () {
    // ...
})->done();

https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji

Get a Specific Reaction

You must first get the Message object to use the code below. Change 😀 below with the emoji you want to retrieve

Cached, synchronous:

$reaction = $message->reactions->get('id', '😀');

If the code above returns null, you may need to fetch it first (Promise, asynchronous):

$message->reactions->fetch('😀')->then(function (Reaction $reactions) {
    // ...
})->done();

https://discord.com/developers/docs/resources/channel#get-reactions

Clone this wiki locally