Skip to content

Commit 2bcbd49

Browse files
authored
Add __repr__ method to various classes
1 parent 667e7c9 commit 2bcbd49

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

discord/app_commands/installs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def __init__(self, *, guild: Optional[bool] = None, user: Optional[bool] = None)
5757
self._guild: Optional[bool] = guild
5858
self._user: Optional[bool] = user
5959

60+
def __repr__(self):
61+
return f'<AppInstallationType guild={self.guild!r} user={self.user!r}>'
62+
6063
@property
6164
def guild(self) -> bool:
6265
""":class:`bool`: Whether the integration is a guild install."""
@@ -142,6 +145,9 @@ def __init__(
142145
self._dm_channel: Optional[bool] = dm_channel
143146
self._private_channel: Optional[bool] = private_channel
144147

148+
def __repr__(self) -> str:
149+
return f'<AppCommandContext guild={self.guild!r} dm_channel={self.dm_channel!r} private_channel={self.private_channel!r}>'
150+
145151
@property
146152
def guild(self) -> bool:
147153
""":class:`bool`: Whether the context allows usage in a guild."""

discord/app_commands/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,9 @@ def __init__(self, *, data: ApplicationCommandPermissions, guild: Guild, state:
10631063

10641064
self.target: Union[Object, User, Member, Role, AllChannels, GuildChannel] = _object
10651065

1066+
def __repr__(self) -> str:
1067+
return f'<AppCommandPermissions id={self.id} type={self.type!r} guild={self.guild!r} permission={self.permission}>'
1068+
10661069
def to_dict(self) -> ApplicationCommandPermissions:
10671070
return {
10681071
'id': self.target.id,
@@ -1106,6 +1109,9 @@ def __init__(self, *, data: GuildApplicationCommandPermissions, state: Connectio
11061109
AppCommandPermissions(data=value, guild=guild, state=self._state) for value in data['permissions']
11071110
]
11081111

1112+
def __repr__(self) -> str:
1113+
return f'<GuildAppCommandPermissions id={self.id!r} guild_id={self.guild_id!r} permissions={self.permissions!r}>'
1114+
11091115
def to_dict(self) -> Dict[str, Any]:
11101116
return {'permissions': [p.to_dict() for p in self.permissions]}
11111117

discord/ext/commands/parameters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def __init__(
109109
self._fallback = False
110110
self._displayed_name = displayed_name
111111

112+
def __repr__(self) -> str:
113+
return f'<{self.__class__.__name__} name={self._name!r} required={self.required}>'
114+
112115
def replace(
113116
self,
114117
*,

discord/interactions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@ def __init__(
712712
self.type: InteractionResponseType = type
713713
self._update(data)
714714

715+
def __repr__(self) -> str:
716+
return f'<InteractionCallbackResponse id={self.id} type={self.type!r}>'
717+
715718
def _update(self, data: InteractionCallbackPayload) -> None:
716719
interaction = data['interaction']
717720

0 commit comments

Comments
 (0)