Skip to content

Commit

Permalink
Add handler to edit & to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Soheab committed Dec 2, 2024
1 parent 312f4fd commit 2615300
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions discord/app_commands/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ def _from_data(self, data: ApplicationCommandPayload) -> None:
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)
if handler is None:
self.handler = None
else:
self.handler = try_enum(EntryPointCommandHandlerType, handler)


def to_dict(self) -> ApplicationCommandPayload:
return {
Expand All @@ -268,6 +270,7 @@ def to_dict(self) -> ApplicationCommandPayload:
'contexts': self.allowed_contexts.to_array() if self.allowed_contexts is not None else None,
'integration_types': self.allowed_installs.to_array() if self.allowed_installs is not None else None,
'options': [opt.to_dict() for opt in self.options],
'handler': self.handler.value if self.handler is not None else None,
} # type: ignore # Type checker does not understand this literal.

def __str__(self) -> str:
Expand Down Expand Up @@ -328,6 +331,7 @@ async def edit(
default_member_permissions: Optional[Permissions] = MISSING,
dm_permission: bool = MISSING,
options: List[Union[Argument, AppCommandGroup]] = MISSING,
handler: Optional[EntryPointCommandHandlerType] = MISSING,
) -> AppCommand:
"""|coro|
Expand All @@ -346,6 +350,10 @@ async def edit(
Indicates if the application command can be used in DMs.
options: List[Union[:class:`Argument`, :class:`AppCommandGroup`]]
List of new options for this application command.
handler: Optional[:class:`~discord.EntryPointCommandHandlerType`]
Determines whether the interaction is handled by the app's interactions handler or by Discord.
Only available for commands with type :attr:`~discord.AppCommandType.primary_entry_point`.
Raises
-------
Expand Down Expand Up @@ -387,6 +395,9 @@ async def edit(
if options is not MISSING:
payload['options'] = [option.to_dict() for option in options]

if handler is not MISSING:
payload['handler'] = handler

if not payload:
return self

Expand Down

0 comments on commit 2615300

Please sign in to comment.