From f8dd5607937aad7f6b658f1235cf9859fbb0e877 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 13 Jul 2023 22:08:41 -0400 Subject: [PATCH] Add RawReactionActionEvent.message_author_id field --- discord/ext/tasks/__init__.py | 2 +- discord/raw_models.py | 14 ++++++++++---- discord/types/gateway.py | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index f3cfb8f4f..3a1454559 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -811,7 +811,7 @@ def loop( it is assigned a name based off of the callable name such as ``discord-ext-tasks: function_name``. - .. versionadded:: 2.4 + .. versionadded:: 2.1 Raises -------- diff --git a/discord/raw_models.py b/discord/raw_models.py index 79841309d..506ac8ce5 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -24,9 +24,10 @@ DEALINGS IN THE SOFTWARE. from __future__ import annotations -from typing import TYPE_CHECKING, List, Optional, Set, Tuple, Union +from typing import TYPE_CHECKING, Literal, Optional, Set, List, Tuple, Union from .enums import ChannelType, ReadStateType, try_enum +from .utils import _get_as_snowflake if TYPE_CHECKING: from .guild import Guild @@ -51,6 +52,7 @@ if TYPE_CHECKING: ) ReactionActionEvent = Union[MessageReactionAddEvent, MessageReactionRemoveEvent] + ReactionActionType = Literal['REACTION_ADD', 'REACTION_REMOVE'] __all__ = ( @@ -189,7 +191,10 @@ class RawReactionActionEvent(_RawReprMixin): The member who added the reaction. Only available if ``event_type`` is ``REACTION_ADD`` and the reaction is inside a guild. .. versionadded:: 1.3 + message_author_id: Optional[:class:`int`] + The author ID of the message being reacted to. Only available if ``event_type`` is ``REACTION_ADD``. + .. versionadded:: 2.1 event_type: :class:`str` The event type that triggered this action. Can be ``REACTION_ADD`` for reaction addition or @@ -198,15 +203,16 @@ class RawReactionActionEvent(_RawReprMixin): .. versionadded:: 1.3 """ - __slots__ = ('message_id', 'user_id', 'channel_id', 'guild_id', 'emoji', 'event_type', 'member') + __slots__ = ('message_id', 'user_id', 'channel_id', 'guild_id', 'emoji', 'event_type', 'member', 'message_author_id') - def __init__(self, data: ReactionActionEvent, emoji: PartialEmoji, event_type: str) -> None: + def __init__(self, data: ReactionActionEvent, emoji: PartialEmoji, event_type: ReactionActionType) -> None: self.message_id: int = int(data['message_id']) self.channel_id: int = int(data['channel_id']) self.user_id: int = int(data['user_id']) self.emoji: PartialEmoji = emoji - self.event_type: str = event_type + self.event_type: ReactionActionType = event_type self.member: Optional[Member] = None + self.message_author_id: Optional[int] = _get_as_snowflake(data, 'message_author_id') try: self.guild_id: Optional[int] = int(data['guild_id']) diff --git a/discord/types/gateway.py b/discord/types/gateway.py index 1f1a44ff0..84aebcef1 100644 --- a/discord/types/gateway.py +++ b/discord/types/gateway.py @@ -180,6 +180,7 @@ class MessageReactionAddEvent(TypedDict): emoji: PartialEmoji member: NotRequired[MemberWithUser] guild_id: NotRequired[Snowflake] + message_author_id: NotRequired[Snowflake] class MessageReactionRemoveEvent(TypedDict):