Skip to content

Commit c210d39

Browse files
Strixenshiftinv
andauthored
Apply suggestions from code review
These are good suggestions Co-authored-by: shiftinv <[email protected]> Signed-off-by: Strix <[email protected]>
1 parent 6a39a2e commit c210d39

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

guide/docs/popular-topics/reactions.mdx

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ In this guide we will be providing an example using the <DocsLink reference="dis
1818
- Removing reactions that are not owned by the bot requires <DocsLink reference="disnake.Intents.reactions">Intents.reactions</DocsLink> to be set
1919
- Therefore <DocsLink reference="disnake.Intents.messages">Intents.messages</DocsLink> is indirectly required if you want to manipulate reactions
2020
- A message can have a maximum of 20 unique reactions on it at one time.
21-
- Reactions are inherently linked to emojis, and your bot will not have access to resend all emojis used by discord users
22-
- Dealing with reactions result in a fair amount of extra api-calls, meaning it can have rate-limit implications on deployment scale.
23-
- Using Reactions as a UX interface was never a inteded behavior, and is ultimatly inferior to the newer component style interface
21+
- Reactions are inherently linked to emojis, and your bot will not have access to resend all emojis used by Discord users.
22+
- Dealing with reactions results in a fair amount of extra API calls, meaning it can have rate-limit implications on deployment scale.
23+
- Using Reactions as a UX interface was never a intended behavior, and is ultimately inferior to the newer component style interface.
2424
:::
2525

2626
<DiscordMessages>
@@ -61,27 +61,25 @@ PartialEmoji: are most often custom emojis too, but will usually represent custo
6161
Strings: are normally returned when Unicode CodePoints are used. These are the standard emojis most are familiar with (✅🎮💛💫)
6262
but these can also come as a PartialEmoji
6363

64-
There is also a small write up about this [`here`](//faq/general.mdx#how-can-i-add-a-reaction-to-a-message)
64+
There is also a small write up about this [here](../faq/general.mdx#how-can-i-add-a-reaction-to-a-message).
6565

6666
:::note
67-
The examples are only meant to demonstrate how disnake interacts with Reactions, and should probably not be copied verbatim.
68-
These examples are not intended for cogs, but can easily be adapted to run inside one. See: [**Creating cogs/extensions**](//getting-started/using-cogs.mdx)
69-
Some examples are also available in the [`DisnakeDev`](https://github.com/DisnakeDev/disnake/tree/master/examples) github repository
67+
The examples are only meant to demonstrate how disnake interacts with reactions, and should probably not be copied verbatim.
68+
These examples are not intended for [cogs](../getting-started/using-cogs.mdx), but can easily be adapted to run inside them.
69+
Some examples are also available in the [GitHub repository](https://github.com/DisnakeDev/disnake/tree/master/examples).
7070
:::
7171

7272
### Example using on_reaction events
7373

7474
There are a few reaction related events we can listen/subscribe to:
7575

76-
- <DocsLink reference="disnake.on_raw_reaction_add">on_raw_reaction_add</DocsLink>
77-
- <DocsLink reference="disnake.on_raw_reaction_remove">on_raw_reaction_remove</DocsLink>
78-
- <DocsLink reference="disnake.on_raw_reaction_clear">on_raw_reaction_clear</DocsLink> Called when a message has all reactions
79-
removed
80-
- <DocsLink reference="disnake.on_raw_reaction_clear_emoji">on_raw_reaction_clear_emoji</DocsLink> Called when a specific
81-
reaction is removed from a message{' '}
76+
- <DocsLink reference="disnake.on_raw_reaction_add">on_raw_reaction_add</DocsLink>, called when a user adds a reaction
77+
- <DocsLink reference="disnake.on_raw_reaction_remove">on_raw_reaction_remove</DocsLink>, called when a user's reaction is removed
78+
- <DocsLink reference="disnake.on_raw_reaction_clear">on_raw_reaction_clear</DocsLink>, called when a message has all reactions removed
79+
- <DocsLink reference="disnake.on_raw_reaction_clear_emoji">on_raw_reaction_clear_emoji</DocsLink>, called when all reactions with a specific emoji are removed from a message
8280

83-
There are non-raw equivilants, but they rely on the cache. If the message is not found in the internal cache, then the event is not called.
84-
For this reason raw events are preffered, and you are only giving up on an included User/Member object that you can easily fetch if you need it.
81+
There are non-raw equivalents, but they rely on the cache. If the message is not found in the internal cache, then the event is not called.
82+
For this reason raw events are preferred, and you are only giving up on an included User/Member object that you can easily fetch if you need it.
8583

8684
- More information about events can be found in the docs, [`here`](https://docs.disnake.dev/en/stable/api.html#event-reference)
8785

@@ -90,9 +88,6 @@ This is generally not an issue since it contains everything we need, but its som
9088
Raw reaction events come a <DocsLink reference="disnake.RawReactionActionEvent">RawReactionActionEvent</DocsLink> which is called `payload` in the examples.
9189

9290
```python title="on_raw_reaction_add.py"
93-
import disnake
94-
95-
9691
@bot.listen()
9792
async def on_raw_reaction_add(self, payload: disnake.RawReactionActionEvent):
9893
# For this example we will have the bot post a message describing the event, and adding the emoji to that message as an exercise
@@ -103,25 +98,25 @@ async def on_raw_reaction_add(self, payload: disnake.RawReactionActionEvent):
10398
if not payload.guild_id:
10499
return # guild_id is None if its a DM
105100

106-
# Raw event's contain few objects, so we need to grab the channel from the cache
101+
# Raw events contain the channel ID, so we need to grab the channel from the cache
107102
event_channel = bot.get_channel(payload.channel_id)
108103

109104
# With the channel in hand we can use it to post a new message like normal, Messageable.send() returns the message, and we need to store it
110105
event_response_message = await event_channel.send(
111106
content=f"Reaction {payload.emoji} added by: {payload.member.display_name}!"
112107
)
113108

114-
# Now using that stored message, we can add our own reaction to it, and the add_reaction() coroutine supports PartialEmojis so we're good to go
115-
# One thing we need to consider is that the bot cannot access custom emojis outside servers they occupy (see caution below)
116-
# Because of this we need to check if we have access to the custom_emoji.
117-
# disnake.Emoji have a is_usable() function we can reference, but Partials do not so we need to check manually.
118-
if payload.emoji.is_custom_emoji and not bot.get_emoji(payload.emoji.id):
119-
return # The emoji is custom, but could not be found in the cache.
109+
# Now, we could add our own reaction to the message we just sent.
110+
# One thing we need to consider is that the bot cannot access custom emojis from servers they're not members of (see caution below),
111+
# because of this we need to check if we have access to the custom_emoji.
112+
# disnake.Emoji has a `is_usable()` function we could reference, but partials do not, so we need to check manually.
113+
if payload.emoji.is_custom_emoji() and not bot.get_emoji(payload.emoji.id):
114+
return # The emoji is custom, but from a guild the bot cannot access.
120115
await event_response_message.add_reaction(payload.emoji)
121116
```
122117

123-
Below is how the the listener above would react both for a Unicode CodePoint emoji and a custom_emoji the bot can't access
124-
Notice how the **payload.emoji** resolved into **:disnake:** because the emoji is on a server not accessable to the bot
118+
Below is how the the listener above would react both for a unicode emoji and a custom emoji the bot can't access.
119+
Notice how second emoji resolved into **:disnake:** because the emoji is on a server not accessible to the bot:
125120

126121
<DiscordMessages>
127122
<DiscordMessage profile="user">
@@ -154,11 +149,13 @@ Notice how the **payload.emoji** resolved into **:disnake:** because the emoji i
154149
</div>
155150
</DiscordMessage>
156151
<DiscordMessage profile="bot">Reaction :disnake: added by: AbhigyanTrips!</DiscordMessage>
157-
</DiscordMessages>{' '}
152+
</DiscordMessages>
153+
154+
<br/>
158155

159156
:::caution
160157
We can only use custom emojis from servers the bot has joined, but we can use them interchangably on those servers.
161-
Bots can make <DocsLink reference="disnake.ui.Button">buttons</DocsLink> using emojis from outside servers they occupy, this may or may not be intended behaviour from Discord and should not be relied on.
158+
Bots can make <DocsLink reference="disnake.ui.Button">buttons</DocsLink> using emojis from servers they're not members of, this may or may not be intended behaviour by Discord and should not be relied on.
162159
:::
163160

164161
Here's a few ways you could filter on reactions to do various things
@@ -277,12 +274,9 @@ async def list_reactions(self, inter: disnake.MessageCommandInteraction):
277274
reaction_list
278275
): # We then loop through the reactions and use enumerate for indexing
279276
response_string += f"{index+1}. {reaction.emoji} - {reaction.count}\n" # Using f-strings we format the list how we like
280-
if (
281-
not response_string
282-
): # If the message has no reactions, response_string will be "" which evaluates as False
283-
response_string = "No Reactions found"
284277

285-
await inter.response.send_message(response_string)
278+
# If the message has no reactions, response_string will be "" which evaluates to False
279+
await inter.response.send_message(response_string or "No Reactions found")
286280

287281
# As with the previous examples, we can add reactions too
288282

0 commit comments

Comments
 (0)