Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add with_localizations to CommandTree.fetch_commands #9452

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions discord/app_commands/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ async def fetch_command(self, command_id: int, /, *, guild: Optional[Snowflake]

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.
Expand All @@ -197,6 +199,10 @@ async def fetch_commands(self, *, guild: Optional[Snowflake] = None) -> List[App
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``.

.. versionadded:: 2.4

Raises
-------
Expand All @@ -214,9 +220,13 @@ async def fetch_commands(self, *, guild: Optional[Snowflake] = None) -> List[App
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]

Expand Down
17 changes: 13 additions & 4 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,8 +2127,13 @@ def get_scheduled_event_users(

# 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': int(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(
Expand Down Expand Up @@ -2183,15 +2188,19 @@ def bulk_upsert_global_commands(
# 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': int(with_localizations)}
r = Route(
'GET',
'/applications/{application_id}/guilds/{guild_id}/commands',
application_id=application_id,
guild_id=guild_id,
)
return self.request(r)
return self.request(r, params=params)

def get_guild_command(
self,
Expand Down
Loading