From 9cc82f2ca3b69266b06d0522f34412d0fb02b5b2 Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:14:58 +0200 Subject: [PATCH 1/4] Add with_localizations to CommandTree.fetch_commands --- discord/app_commands/tree.py | 14 +++++++++++--- discord/http.py | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/discord/app_commands/tree.py b/discord/app_commands/tree.py index 5bdfbec58..b0a3c9dbe 100644 --- a/discord/app_commands/tree.py +++ b/discord/app_commands/tree.py @@ -180,7 +180,9 @@ class CommandTree(Generic[ClientT]): return AppCommand(data=command, state=self._state) - async def fetch_commands(self, *, guild: Optional[Snowflake] = None) -> List[AppCommand]: + async def fetch_commands( + self, *, guild: Optional[Snowflake] = None, with_localizations: bool = False + ) -> List[AppCommand]: """|coro| Fetches the application's current commands. @@ -197,6 +199,8 @@ class CommandTree(Generic[ClientT]): guild: Optional[:class:`~discord.abc.Snowflake`] The guild to fetch the commands from. If not passed then global commands are fetched instead. + with_localizations: :class:`bool` + Whether to fetch the localizations for the commands. Defaults to ``False``. Raises ------- @@ -214,9 +218,13 @@ class CommandTree(Generic[ClientT]): raise MissingApplicationID if guild is None: - commands = await self._http.get_global_commands(self.client.application_id) + commands = await self._http.get_global_commands( + self.client.application_id, with_localizations=with_localizations + ) else: - commands = await self._http.get_guild_commands(self.client.application_id, guild.id) + commands = await self._http.get_guild_commands( + self.client.application_id, guild.id, with_localizations=with_localizations + ) return [AppCommand(data=data, state=self._state) for data in commands] diff --git a/discord/http.py b/discord/http.py index 6e803830e..6b972e9c5 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2128,8 +2128,13 @@ class HTTPClient: # Application commands (global) - def get_global_commands(self, application_id: Snowflake) -> Response[List[command.ApplicationCommand]]: - return self.request(Route('GET', '/applications/{application_id}/commands', application_id=application_id)) + def get_global_commands( + self, application_id: Snowflake, with_localizations: bool = False + ) -> Response[List[command.ApplicationCommand]]: + params = {'with_localizations': with_localizations} + return self.request( + Route('GET', '/applications/{application_id}/commands', application_id=application_id, params=params) + ) def get_global_command(self, application_id: Snowflake, command_id: Snowflake) -> Response[command.ApplicationCommand]: r = Route( @@ -2184,13 +2189,18 @@ class HTTPClient: # Application commands (guild) def get_guild_commands( - self, application_id: Snowflake, guild_id: Snowflake + self, + application_id: Snowflake, + guild_id: Snowflake, + with_localizations: bool = False, ) -> Response[List[command.ApplicationCommand]]: + params = {'with_localizations': with_localizations} r = Route( 'GET', '/applications/{application_id}/guilds/{guild_id}/commands', application_id=application_id, guild_id=guild_id, + params=params, ) return self.request(r) From a2f29909e191916df357d2c268f373291f34cc72 Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Tue, 13 Jun 2023 14:17:34 +0200 Subject: [PATCH 2/4] Add forgotten versionadded --- discord/app_commands/tree.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discord/app_commands/tree.py b/discord/app_commands/tree.py index b0a3c9dbe..7d229837c 100644 --- a/discord/app_commands/tree.py +++ b/discord/app_commands/tree.py @@ -202,6 +202,8 @@ class CommandTree(Generic[ClientT]): with_localizations: :class:`bool` Whether to fetch the localizations for the commands. Defaults to ``False``. + .. versionadded:: 2.4 + Raises ------- HTTPException From d236fdb730dadb2299681383f5c6cadf355d5a3c Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Wed, 14 Jun 2023 13:52:06 +0200 Subject: [PATCH 3/4] Fix passing params to request --- discord/http.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/discord/http.py b/discord/http.py index 6b972e9c5..d17ae14ee 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2133,7 +2133,7 @@ class HTTPClient: ) -> Response[List[command.ApplicationCommand]]: params = {'with_localizations': with_localizations} return self.request( - Route('GET', '/applications/{application_id}/commands', application_id=application_id, params=params) + Route('GET', '/applications/{application_id}/commands', application_id=application_id), params=params ) def get_global_command(self, application_id: Snowflake, command_id: Snowflake) -> Response[command.ApplicationCommand]: @@ -2200,9 +2200,8 @@ class HTTPClient: '/applications/{application_id}/guilds/{guild_id}/commands', application_id=application_id, guild_id=guild_id, - params=params, ) - return self.request(r) + return self.request(r, params=params) def get_guild_command( self, From faf867b55f15b68648580c9ba04bdf21b26252ea Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:01:13 +0200 Subject: [PATCH 4/4] Cast bool to int --- discord/http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/http.py b/discord/http.py index d17ae14ee..f41a14142 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2131,7 +2131,7 @@ class HTTPClient: def get_global_commands( self, application_id: Snowflake, with_localizations: bool = False ) -> Response[List[command.ApplicationCommand]]: - params = {'with_localizations': with_localizations} + params = {'with_localizations': int(with_localizations)} return self.request( Route('GET', '/applications/{application_id}/commands', application_id=application_id), params=params ) @@ -2194,7 +2194,7 @@ class HTTPClient: guild_id: Snowflake, with_localizations: bool = False, ) -> Response[List[command.ApplicationCommand]]: - params = {'with_localizations': with_localizations} + params = {'with_localizations': int(with_localizations)} r = Route( 'GET', '/applications/{application_id}/guilds/{guild_id}/commands',