Skip to content

Commit 5864839

Browse files
feat: add new reaction event (#1640)
1 parent 670a47b commit 5864839

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

interactions/api/events/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
MessageReactionAdd,
4545
MessageReactionRemove,
4646
MessageReactionRemoveAll,
47+
MessageReactionRemoveEmoji,
4748
MessageUpdate,
4849
NewThreadCreate,
4950
PresenceUpdate,
@@ -161,6 +162,7 @@
161162
"MessageReactionAdd",
162163
"MessageReactionRemove",
163164
"MessageReactionRemoveAll",
165+
"MessageReactionRemoveEmoji",
164166
"MessageUpdate",
165167
"ModalCompletion",
166168
"ModalError",

interactions/api/events/discord.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ async def an_event_handler(event: ChannelCreate):
7575
"MessageReactionAdd",
7676
"MessageReactionRemove",
7777
"MessageReactionRemoveAll",
78+
"MessageReactionRemoveEmoji",
7879
"MessageUpdate",
7980
"NewThreadCreate",
8081
"PresenceUpdate",
@@ -577,6 +578,16 @@ class MessageReactionRemoveAll(GuildEvent):
577578
"""The message that was reacted to"""
578579

579580

581+
@attrs.define(eq=False, order=False, hash=False, kw_only=False)
582+
class MessageReactionRemoveEmoji(MessageReactionRemoveAll):
583+
"""Dispatched when all reactions of a specifc emoji are removed from a message."""
584+
585+
emoji: "PartialEmoji" = attrs.field(
586+
repr=False,
587+
)
588+
"""The emoji that was removed"""
589+
590+
580591
@attrs.define(eq=False, order=False, hash=False, kw_only=False)
581592
class PresenceUpdate(BaseEvent):
582593
"""A user's presence has changed."""

interactions/api/events/processors/reaction_events.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,24 @@ async def _on_raw_message_reaction_remove_all(self, event: "RawGatewayEvent") ->
8181
await self.cache.fetch_message(event.data["channel_id"], event.data["message_id"]),
8282
)
8383
)
84+
85+
@Processor.define()
86+
async def _on_raw_message_reaction_remove_emoji(self, event: "RawGatewayEvent") -> None:
87+
emoji = PartialEmoji.from_dict(event.data.get("emoji"))
88+
message = self.cache.get_message(event.data.get("channel_id"), event.data.get("message_id"))
89+
90+
if message:
91+
for i, reaction in enumerate(message.reactions):
92+
if reaction.emoji == emoji:
93+
message.reactions.pop(i)
94+
break
95+
else:
96+
message = await self.cache.fetch_message(event.data.get("channel_id"), event.data.get("message_id"))
97+
98+
self.dispatch(
99+
events.MessageReactionRemoveEmoji(
100+
event.data.get("guild_id"),
101+
message,
102+
emoji,
103+
)
104+
)

interactions/client/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@
208208
Intents.DIRECT_MESSAGE_REACTIONS,
209209
Intents.REACTIONS,
210210
],
211+
events.MessageReactionRemoveEmoji: [
212+
Intents.GUILD_MESSAGE_REACTIONS,
213+
Intents.DIRECT_MESSAGE_REACTIONS,
214+
Intents.REACTIONS,
215+
],
211216
}
212217

213218

0 commit comments

Comments
 (0)