Skip to content

Commit

Permalink
chore: add parents properties
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Jul 28, 2022
1 parent 2df688b commit e33c827
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions disnake/ext/commands/slash_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ def parent(self) -> Optional[InvokableSlashCommand]:
"""
return self._parent

@property
def parents(
self,
) -> Tuple[InvokableSlashCommand]:
"""Tuple[:class:`InvokableSlashCommand`]: Retrieves the parents of this command.
If the command has no parents then it returns an empty :class:`tuple`.
For example in commands ``/a b test``, the parents are ``(b, a)``.
.. versionadded:: 2.6
"""
return (self.parent,) # type: ignore

def sub_command(
self,
name: LocalizedOptional = None,
Expand Down Expand Up @@ -338,6 +352,26 @@ def parent(self) -> Optional[Union[InvokableSlashCommand, SubCommandGroup]]:
# todo: figure out when this can be optional or not, and try to make it non-optional for user-experience
return self._parent

@property
def parents(
self,
) -> Union[Tuple[InvokableSlashCommand], Tuple[SubCommandGroup, InvokableSlashCommand]]:
"""Union[Tuple[:class:`InvokableSlashCommand`], Tuple[:class:`SubCommandGroup`, :class:`InvokableSlashCommand`]]: Retrieves the parents of this command.
If the command has no parents then it returns an empty :class:`tuple`.
For example in commands ``/a b test``, the parents are ``(b, a)``.
.. versionadded:: 2.6
"""
entries = []
command = self
while command.parent is not None: # type: ignore
command = command.parent # type: ignore
entries.append(command)

return tuple(entries)

async def _call_autocompleter(
self, param: str, inter: ApplicationCommandInteraction, user_input: str
) -> Optional[Choices]:
Expand Down

0 comments on commit e33c827

Please sign in to comment.