diff --git a/discord/activity.py b/discord/activity.py index f9d43ccf9..78362a84a 100644 --- a/discord/activity.py +++ b/discord/activity.py @@ -99,6 +99,8 @@ if TYPE_CHECKING: ActivityButton, ) + from .state import ConnectionState + class BaseActivity: """The base activity that all user-settable activities inherit from. @@ -809,16 +811,16 @@ ActivityTypes = Union[Activity, Game, CustomActivity, Streaming, Spotify] @overload -def create_activity(data: ActivityPayload) -> ActivityTypes: +def create_activity(data: ActivityPayload, state: ConnectionState) -> ActivityTypes: ... @overload -def create_activity(data: None) -> None: +def create_activity(data: None, state: ConnectionState) -> None: ... -def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]: +def create_activity(data: Optional[ActivityPayload], state: ConnectionState) -> Optional[ActivityTypes]: if not data: return None @@ -831,10 +833,10 @@ def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]: try: name = data.pop('name') except KeyError: - return Activity(**data) + ret = Activity(**data) else: # we removed the name key from data already - return CustomActivity(name=name, **data) # type: ignore + ret = CustomActivity(name=name, **data) # type: ignore elif game_type is ActivityType.streaming: if 'url' in data: # the url won't be None here @@ -842,4 +844,9 @@ def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]: return Activity(**data) elif game_type is ActivityType.listening and 'sync_id' in data and 'session_id' in data: return Spotify(**data) - return Activity(**data) + else: + ret = Activity(**data) + + if isinstance(ret.emoji, PartialEmoji): + ret.emoji._state = state + return ret diff --git a/discord/client.py b/discord/client.py index bf928b1d7..0ae417f16 100644 --- a/discord/client.py +++ b/discord/client.py @@ -717,7 +717,7 @@ class Client: """Optional[:class:`.BaseActivity`]: The activity being used upon logging in. """ - return create_activity(self._connection._activity) + return create_activity(self._connection._activity, self._connection) @activity.setter def activity(self, value: Optional[ActivityTypes]) -> None: diff --git a/discord/member.py b/discord/member.py index 4ebb6263e..b1c9e3a44 100644 --- a/discord/member.py +++ b/discord/member.py @@ -448,7 +448,7 @@ class Member(discord.abc.Messageable, _UserTag): self._avatar = data.get('avatar') def _presence_update(self, data: PartialPresenceUpdate, user: UserPayload) -> Optional[Tuple[User, User]]: - self.activities = tuple(map(create_activity, data['activities'])) + self.activities = tuple(create_activity(d, self._state) for d in data['activities']) self._client_status._update(data['status'], data['client_status']) if len(user) > 1: diff --git a/discord/widget.py b/discord/widget.py index 0a828b08b..b10b63c31 100644 --- a/discord/widget.py +++ b/discord/widget.py @@ -188,7 +188,7 @@ class WidgetMember(BaseUser): except KeyError: activity = None else: - activity = create_activity(game) + activity = create_activity(game, state) self.activity: Optional[Union[BaseActivity, Spotify]] = activity