From 87f9dcff9c5af9c4fa6e6b148663320522a3c82f Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 17 Jan 2020 19:48:46 -0500 Subject: Add support for clearing a specific reaction. Closes #2440 --- discord/message.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'discord/message.py') diff --git a/discord/message.py b/discord/message.py index e2ae7193..4010a2c3 100644 --- a/discord/message.py +++ b/discord/message.py @@ -371,6 +371,18 @@ class Message: return reaction + def _clear_emoji(self, emoji): + to_check = str(emoji) + for index, reaction in enumerate(self.reactions): + if str(reaction.emoji) == to_check: + break + else: + # didn't find anything so just return + return + + del self.reactions[index] + return reaction + def _update(self, data): handlers = self._HANDLERS for key, value in data.items(): @@ -945,6 +957,37 @@ class Message: else: await self._state.http.remove_reaction(self.channel.id, self.id, emoji, member.id) + async def clear_reaction(self, emoji): + """|coro| + + Clears a specific reaction from the message. + + The emoji may be a unicode emoji or a custom guild :class:`Emoji`. + + You need the :attr:`~Permissions.manage_messages` permission to use this. + + .. versionadded:: 1.3 + + Parameters + ----------- + emoji: Union[:class:`Emoji`, :class:`Reaction`, :class:`PartialEmoji`, :class:`str`] + The emoji to clear. + + Raises + -------- + HTTPException + Clearing the reaction failed. + Forbidden + You do not have the proper permissions to clear the reaction. + NotFound + The emoji you specified was not found. + InvalidArgument + The emoji parameter is invalid. + """ + + emoji = self._emoji_reaction(emoji) + await self._state.http.clear_single_reaction(self.channel.id, self.id, emoji) + @staticmethod def _emoji_reaction(emoji): if isinstance(emoji, Reaction): -- cgit v1.2.3