From 79b709290cfbe7ee9bc7ca861c3db4c65299d9e5 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 24 Feb 2026 09:47:10 -0500 Subject: [PATCH] Add client parameter to PartialEmoji.from_str Fix #10407 --- discord/partial_emoji.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/discord/partial_emoji.py b/discord/partial_emoji.py index d028244c0..3301864a6 100644 --- a/discord/partial_emoji.py +++ b/discord/partial_emoji.py @@ -39,6 +39,7 @@ __all__ = ( if TYPE_CHECKING: from typing_extensions import Self + from .client import Client from .state import ConnectionState from datetime import datetime from .types.emoji import Emoji as EmojiPayload, PartialEmoji as PartialEmojiPayload @@ -114,7 +115,7 @@ class PartialEmoji(_EmojiTag, AssetMixin): ) @classmethod - def from_str(cls, value: str) -> Self: + def from_str(cls, value: str, *, client: Client = utils.MISSING) -> Self: """Converts a Discord string representation of an emoji to a :class:`PartialEmoji`. The formats accepted are: @@ -132,6 +133,11 @@ class PartialEmoji(_EmojiTag, AssetMixin): ------------ value: :class:`str` The string representation of an emoji. + client: :class:`Client` + The client to initialise this emoji with. This allows it to + attach the client's internal state. + + .. versionadded:: 2.7 Returns -------- @@ -144,8 +150,12 @@ class PartialEmoji(_EmojiTag, AssetMixin): animated = bool(groups['animated']) emoji_id = int(groups['id']) name = groups['name'] + if client is not utils.MISSING: + return cls.with_state(name=name, animated=animated, id=emoji_id, state=client._connection) return cls(name=name, animated=animated, id=emoji_id) + if client is not utils.MISSING: + return cls.with_state(name=value, animated=False, id=None, state=client._connection) return cls(name=value, id=None, animated=False) def to_dict(self) -> EmojiPayload: