From b56102416338aac97a5dde7fdf79d84f7f66ad77 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 4 Apr 2022 00:49:36 -0400 Subject: [PATCH] Fix WebhookState not handling reaction emoji Fix #7842 --- discord/webhook/async_.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index ae8abf071..1f00368df 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -43,6 +43,7 @@ from ..enums import try_enum, WebhookType from ..user import BaseUser, User from ..flags import MessageFlags from ..asset import Asset +from ..partial_emoji import PartialEmoji from ..http import Route, handle_message_parameters, MultipartParameters, HTTPClient from ..mixins import Hashable from ..channel import PartialMessageable @@ -67,6 +68,7 @@ if TYPE_CHECKING: from ..state import ConnectionState from ..http import Response from ..guild import Guild + from ..emoji import Emoji from ..channel import TextChannel from ..abc import Snowflake from ..ui.view import View @@ -85,6 +87,7 @@ if TYPE_CHECKING: from ..types.channel import ( PartialChannel as PartialChannelPayload, ) + from ..types.emoji import PartialEmoji as PartialEmojiPayload BE = TypeVar('BE', bound=BaseException) _State = Union[ConnectionState, '_WebhookState'] @@ -648,6 +651,18 @@ class _WebhookState: # state parameter is artificial return BaseUser(state=self, data=data) # type: ignore + def get_reaction_emoji(self, data: PartialEmojiPayload) -> Union[PartialEmoji, Emoji, str]: + if self._parent is not None: + return self._parent.get_reaction_emoji(data) + + emoji_id = utils._get_as_snowflake(data, 'id') + + if not emoji_id: + # the name key will be a str + return data['name'] # type: ignore + + return PartialEmoji(animated=data.get('animated', False), id=emoji_id, name=data['name']) # type: ignore + @property def http(self) -> Union[HTTPClient, _FriendlyHttpAttributeErrorHelper]: if self._parent is not None: