diff options
| author | Rapptz <[email protected]> | 2020-01-17 19:48:46 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-01-17 19:53:28 -0500 |
| commit | 87f9dcff9c5af9c4fa6e6b148663320522a3c82f (patch) | |
| tree | 2a46dc76aafa9e10ad134c681705684bdb4cf29c /discord/message.py | |
| parent | Add support for on_invite_create and on_invite_delete (diff) | |
| download | discord.py-87f9dcff9c5af9c4fa6e6b148663320522a3c82f.tar.xz discord.py-87f9dcff9c5af9c4fa6e6b148663320522a3c82f.zip | |
Add support for clearing a specific reaction.
Closes #2440
Diffstat (limited to 'discord/message.py')
| -rw-r--r-- | discord/message.py | 43 |
1 files changed, 43 insertions, 0 deletions
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): |