Browse Source

Add fields for Entry Point Command

pull/9996/head
Soheab_ 7 months ago
parent
commit
6b026f238d
  1. 24
      discord/app_commands/models.py
  2. 6
      discord/enums.py
  3. 12
      discord/types/command.py
  4. 20
      docs/interactions/api.rst

24
discord/app_commands/models.py

@ -35,6 +35,7 @@ from ..enums import (
AppCommandPermissionType,
ChannelType,
Locale,
EntryPointCommandHandlerType,
try_enum,
)
from ..mixins import Hashable
@ -181,6 +182,10 @@ class AppCommand(Hashable):
denotes that it is a global command.
nsfw: :class:`bool`
Whether the command is NSFW and should only work in NSFW channels.
handler: Optional[:class:`~discord.EntryPointCommandHandlerType`]
Determines whether the interaction is handled by the app's interactions handler or by Discord.
This is only available for commands with type :attr:`~discord.AppCommandType.primary_entry_point`.
"""
__slots__ = (
@ -198,6 +203,7 @@ class AppCommand(Hashable):
'allowed_contexts',
'allowed_installs',
'nsfw',
'handler',
'_state',
)
@ -245,6 +251,11 @@ class AppCommand(Hashable):
self.name_localizations: Dict[Locale, str] = _to_locale_dict(data.get('name_localizations') or {})
self.description_localizations: Dict[Locale, str] = _to_locale_dict(data.get('description_localizations') or {})
handler = data.get('handler')
self.handler: Optional[EntryPointCommandHandlerType] = None # type: ignore
if handler is not None:
self.handler: EntryPointCommandHandlerType = try_enum(EntryPointCommandHandlerType, handler)
def to_dict(self) -> ApplicationCommandPayload:
return {
'id': self.id,
@ -433,6 +444,19 @@ class AppCommand(Hashable):
)
return GuildAppCommandPermissions(data=data, state=state, command=self)
def is_default_entry_point_command(self) -> bool:
""":class:`bool`: Returns ``True`` if the command is the default entry point command.
This is determined by the command's name and handler type.
More information can be found in the :ddocs:`official Discord
documentation <interactions/application-commands#default-entry-point-command>`.
"""
return (
self.type is AppCommandType.primary_entry_point
and self.name.casefold() == 'launch'
and self.handler is EntryPointCommandHandlerType.discord_launch_activity
)
class Choice(Generic[ChoiceT]):
"""Represents an application command argument choice.

6
discord/enums.py

@ -767,6 +767,7 @@ class AppCommandType(Enum):
chat_input = 1
user = 2
message = 3
primary_entry_point = 4
class AppCommandPermissionType(Enum):
@ -862,6 +863,11 @@ class SubscriptionStatus(Enum):
inactive = 2
class EntryPointCommandHandlerType(Enum):
app_handler = 1
discord_launch_activity = 2
def create_unknown_value(cls: Type[E], val: Any) -> E:
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
name = f'unknown_{val}'

12
discord/types/command.py

@ -31,7 +31,7 @@ from .channel import ChannelType
from .snowflake import Snowflake
from .interactions import InteractionContextType
ApplicationCommandType = Literal[1, 2, 3]
ApplicationCommandType = Literal[1, 2, 3, 4]
ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
ApplicationIntegrationType = Literal[0, 1]
@ -162,6 +162,15 @@ class _ChatInputApplicationCommand(_BaseApplicationCommand, total=False):
]
EntryPointCommandHandlerType = Literal[1, 2]
class _PrimaryEntryPointApplicationCommand(_BaseApplicationCommand):
description: Required[str]
type: Literal[4]
handler: EntryPointCommandHandlerType
class _BaseContextMenuApplicationCommand(_BaseApplicationCommand):
description: Literal[""]
@ -178,6 +187,7 @@ GlobalApplicationCommand = Union[
_ChatInputApplicationCommand,
_UserApplicationCommand,
_MessageApplicationCommand,
_PrimaryEntryPointApplicationCommand,
]

20
docs/interactions/api.rst

@ -430,6 +430,11 @@ Enumerations
.. attribute:: message
A message context menu command.
.. attribute:: primary_entry_point
.. versionadded:: 2.5
A command that represents the primary way to invoke an app's Activity
.. class:: AppCommandPermissionType
@ -447,6 +452,21 @@ Enumerations
The permission is for a user.
.. class:: EntryPointCommandHandlerType
Represents the type of an entry point command handler.
.. versionadded:: 2.5
.. attribute:: app_handler
The app handles the interaction using an interaction token.
.. attribute:: discord_launch_activity
Discord handles the interaction by launching an Activity and
sending a follow-up message without coordinating with the app.
.. _discord_ui_kit:
Bot UI Kit

Loading…
Cancel
Save