Skip to content
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
36 changes: 36 additions & 0 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,42 @@ def search(
most_relevant=most_relevant,
)

async def user_application_commands(self) -> List[Union[SlashCommand, UserCommand, MessageCommand]]:
"""|coro|

Returns a list of user-installed commands available.

.. versionadded:: 2.1

.. note::

Method returns only user-installed commands.

Raises
------
~discord.HTTPException
Getting the commands failed.

Returns
-------
List[Union[:class:`~discord.SlashCommand`, :class:`~discord.UserCommand`, :class:`~discord.MessageCommand`]]
A list of user-installed commands.
"""
state = self._state
data = await state.http.user_application_command_index()

cmds = data['application_commands']
apps = {int(app['id']): state.create_integration_application(app) for app in data.get('applications') or []}

result = []

for cmd in cmds:
_, cls = _command_factory(cmd['type'])
application = apps.get(int(cmd['application_id']))
result.append(cls(state=state, data=cmd, application=application))

return result

async def application_commands(self) -> List[Union[SlashCommand, UserCommand, MessageCommand]]:
"""|coro|

Expand Down
37 changes: 37 additions & 0 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
from .affinity import *
from .oauth2 import OAuth2Authorization, OAuth2Token
from .experiment import UserExperiment, GuildExperiment
from .commands import SlashCommand, UserCommand, MessageCommand, _command_factory

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -859,6 +860,42 @@ async def _async_setup_hook(self) -> None:

self._ready = asyncio.Event()

async def user_application_commands(self) -> List[Union[SlashCommand, UserCommand, MessageCommand]]:
"""|coro|

Returns a list of user-installed commands available.

.. versionadded:: 2.1

.. note::

Method returns only user-installed commands.

Raises
------
~discord.HTTPException
Getting the commands failed.

Returns
-------
List[Union[:class:`~discord.SlashCommand`, :class:`~discord.UserCommand`, :class:`~discord.MessageCommand`]]
A list of user-installed commands.
"""
state = self._connection
data = await state.http.user_application_command_index()

cmds = data['application_commands']
apps = {int(app['id']): state.create_integration_application(app) for app in data.get('applications') or []}

result = []

for cmd in cmds:
_, cls = _command_factory(cmd['type'])
application = apps.get(int(cmd['application_id']))
result.append(cls(state=state, data=cmd, application=application))

return result

async def setup_hook(self) -> None:
"""|coro|

Expand Down
2 changes: 2 additions & 0 deletions discord/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def __init__(
self.application_id: int = int(data['application_id'])
self.id: int = int(data['id'])
self.version = int(data['version'])
self.integration_types = data.get('integration_types', [])
self.global_popularity_rank = data.get('global_popularity_rank', 0)

self._default_member_permissions = _get_as_snowflake(data, 'default_member_permissions')
dm_permission = data.get('dm_permission') # Null means true?
Expand Down
36 changes: 36 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,42 @@ def convert(d):

return [convert(d) for d in data]

async def user_application_commands(self) -> List[Union[SlashCommand, UserCommand, MessageCommand]]:
"""|coro|

Returns a list of user-installed commands available.

.. versionadded:: 2.1

.. note::

Method returns only user-installed commands.

Raises
------
~discord.HTTPException
Getting the commands failed.

Returns
-------
List[Union[:class:`~discord.SlashCommand`, :class:`~discord.UserCommand`, :class:`~discord.MessageCommand`]]
A list of user-installed commands.
"""
state = self._state
data = await state.http.user_application_command_index()

cmds = data['application_commands']
apps = {int(app['id']): state.create_integration_application(app) for app in data.get('applications') or []}

result = []

for cmd in cmds:
_, cls = _command_factory(cmd['type'])
application = apps.get(int(cmd['application_id']))
result.append(cls(state=state, data=cmd, application=application))

return result

async def application_commands(self) -> List[Union[SlashCommand, UserCommand, MessageCommand]]:
"""|coro|

Expand Down