Reactions
A command can react to reactions. Send a message with some reactions on it, and when someone reacts with one of them, the same command runs again, with the person who reacted. The reaction works like a button: it can change the message, give or take a role, answer in the channel and more.
The idea
Section titled “The idea”{{ if eq .Trigger "command" }} {{ sendMessage nil (complexMessage "embed" (cembed "description" "React with 🦋 to claim this") "reactions" (cslice "🦋" "🎀")) }}{{ return }}{{ end }}
{{/* From here on, someone reacted */}}{{ if eq .Reaction.Emoji "🦋" }} {{ updateMessage (cembed "description" (print "Claimed by " .User.Username)) }} {{ removeReaction }}{{ end }}"reactions"incomplexMessageis a list of up to 5 emojis. Petto puts them on the message and remembers it for one week..Triggeris"reaction"when someone reacted..Reaction.Emojiis the emoji the way you wrote it in the list, and.Reaction.Addedistrue..Userand.Memberare the person who reacted..Messageis the message they reacted to, with its embeds.- Only reactions from people count, never from bots, and only the emojis in the list.
- For a custom emoji write it as Discord does,
<:name:123456789012345678>, in the list and in the check.
What the code can do
Section titled “What the code can do”| Function | In a reaction |
|---|---|
updateMessage message |
Changes the message that was reacted to. What you do not give stays. It only works on a message Petto sent |
respond message |
Sends a message in the channel of the reaction. It cannot be private, a reaction has no private answer |
removeReaction |
Takes the reaction of that person away, so it can be used again |
addRole, removeRole |
Give or take a role of the person who reacted, with the same checks |
sendMessage, sendDM, addReaction, dbSet… |
As always |
Printing text sends it in the channel, like respond.
Good to know
Section titled “Good to know”- Only the messages of the command that sent them with
"reactions"answer. A reaction to any other message does not run anything. - The reactions only work in a message sent with
sendMessage, not in a direct message or an answer to a click. - Using the same reaction twice in a very short time is ignored.
- The keys of stored data that start with
rx:are reserved: Petto uses them to remember these messages. They do not count towards the 500 values of a server. - Each run has the same limits as a command.
A complete example
Section titled “A complete example”The claim template is a request card: !claim a cake sends it with 🦋 and 🎀. 🦋 marks it as claimed by the person who reacted, and 🎀 only counts if it is the person who asked. Install it with !customcommand template claim and read its code with !customcommand codeshow claim.
