From bb71f14ce3fee8b895f3d19d352db0740c5a1440 Mon Sep 17 00:00:00 2001 From: NCPlayz Date: Sat, 23 Nov 2019 16:00:46 +0000 Subject: [PATCH] Add `RawReactionActionEvent.member` --- discord/raw_models.py | 9 ++++++++- discord/state.py | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index 103d148a0..1f3185642 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -127,13 +127,19 @@ class RawReactionActionEvent(_RawReprMixin): The guild ID where the reaction got added or removed, if applicable. emoji: :class:`PartialEmoji` The custom or unicode emoji being used. + member: Optional[:class:`Member`] + The member who added the reaction. Only available if `event_type` is `REACTION_ADD`. + + .. versionadded:: 1.3 + event_type: :class:`str` The event type that triggered this action. Can be ``REACTION_ADD`` for reaction addition or ``REACTION_REMOVE`` for reaction removal. """ - __slots__ = ('message_id', 'user_id', 'channel_id', 'guild_id', 'emoji') + __slots__ = ('message_id', 'user_id', 'channel_id', 'guild_id', 'emoji', + 'event_type', 'member') def __init__(self, data, emoji, event_type): self.message_id = int(data['message_id']) @@ -141,6 +147,7 @@ class RawReactionActionEvent(_RawReprMixin): self.user_id = int(data['user_id']) self.emoji = emoji self.event_type = event_type + self.member = None try: self.guild_id = int(data['guild_id']) diff --git a/discord/state.py b/discord/state.py index 210408b24..10208d3bf 100644 --- a/discord/state.py +++ b/discord/state.py @@ -456,6 +456,13 @@ class ConnectionState: emoji_id = utils._get_as_snowflake(emoji, 'id') emoji = PartialEmoji.with_state(self, animated=emoji.get('animated', False), id=emoji_id, name=emoji['name']) raw = RawReactionActionEvent(data, emoji, 'REACTION_ADD') + + member_data = data.get('member') + if member_data: + guild = self._get_guild(raw.guild_id) + raw.member = Member(data=member_data, guild=guild, state=self) + else: + raw.member = None self.dispatch('raw_reaction_add', raw) # rich interface here @@ -463,7 +470,8 @@ class ConnectionState: if message is not None: emoji = self._upgrade_partial_emoji(emoji) reaction = message._add_reaction(data, emoji, raw.user_id) - user = self._get_reaction_user(message.channel, raw.user_id) + user = raw.member or self._get_reaction_user(message.channel, raw.user_id) + if user: self.dispatch('reaction_add', reaction, user)