From 2bcbd49bc6d618736e2aa2c5c4d6beb76e33238c Mon Sep 17 00:00:00 2001 From: owocado <24418520+owocado@users.noreply.github.com> Date: Sat, 21 Jun 2025 00:27:10 +0530 Subject: [PATCH] Add __repr__ method to various classes --- discord/app_commands/installs.py | 6 ++++++ discord/app_commands/models.py | 6 ++++++ discord/ext/commands/parameters.py | 3 +++ discord/interactions.py | 3 +++ 4 files changed, 18 insertions(+) diff --git a/discord/app_commands/installs.py b/discord/app_commands/installs.py index 5ac033245..e00d13724 100644 --- a/discord/app_commands/installs.py +++ b/discord/app_commands/installs.py @@ -57,6 +57,9 @@ class AppInstallationType: self._guild: Optional[bool] = guild self._user: Optional[bool] = user + def __repr__(self): + return f'' + @property def guild(self) -> bool: """:class:`bool`: Whether the integration is a guild install.""" @@ -142,6 +145,9 @@ class AppCommandContext: self._dm_channel: Optional[bool] = dm_channel self._private_channel: Optional[bool] = private_channel + def __repr__(self) -> str: + return f'' + @property def guild(self) -> bool: """:class:`bool`: Whether the context allows usage in a guild.""" diff --git a/discord/app_commands/models.py b/discord/app_commands/models.py index e8a96784b..dcf70d41e 100644 --- a/discord/app_commands/models.py +++ b/discord/app_commands/models.py @@ -1063,6 +1063,9 @@ class AppCommandPermissions: self.target: Union[Object, User, Member, Role, AllChannels, GuildChannel] = _object + def __repr__(self) -> str: + return f'' + def to_dict(self) -> ApplicationCommandPermissions: return { 'id': self.target.id, @@ -1106,6 +1109,9 @@ class GuildAppCommandPermissions: AppCommandPermissions(data=value, guild=guild, state=self._state) for value in data['permissions'] ] + def __repr__(self) -> str: + return f'' + def to_dict(self) -> Dict[str, Any]: return {'permissions': [p.to_dict() for p in self.permissions]} diff --git a/discord/ext/commands/parameters.py b/discord/ext/commands/parameters.py index 196530d94..2640902a3 100644 --- a/discord/ext/commands/parameters.py +++ b/discord/ext/commands/parameters.py @@ -109,6 +109,9 @@ class Parameter(inspect.Parameter): self._fallback = False self._displayed_name = displayed_name + def __repr__(self) -> str: + return f'<{self.__class__.__name__} name={self._name!r} required={self.required}>' + def replace( self, *, diff --git a/discord/interactions.py b/discord/interactions.py index cb9a21e88..abe47efa2 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -712,6 +712,9 @@ class InteractionCallbackResponse(Generic[ClientT]): self.type: InteractionResponseType = type self._update(data) + def __repr__(self) -> str: + return f'' + def _update(self, data: InteractionCallbackPayload) -> None: interaction = data['interaction']