Add group command support
This commit is contained in:
parent
614c6bca67
commit
1a22df6228
@ -1081,13 +1081,12 @@ class BotBase(GroupMixin):
|
||||
# Fetch out subcommands from the options
|
||||
command_name = interaction.data['name']
|
||||
command_options = interaction.data.get('options') or []
|
||||
while any(o["type"] in {1, 2} for o in command_options):
|
||||
for option in command_options:
|
||||
if option['type'] in {1, 2}:
|
||||
command_name = option['name']
|
||||
command_name += f' {option["name"]}'
|
||||
command_options = option.get('options') or []
|
||||
|
||||
command_name += f'{command_name} '
|
||||
|
||||
command = self.get_command(command_name)
|
||||
if command is None:
|
||||
raise errors.CommandNotFound(f'Command "{command_name}" is not found')
|
||||
|
@ -1146,15 +1146,19 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
finally:
|
||||
ctx.command = original
|
||||
|
||||
def to_application_command(self) -> Optional[EditApplicationCommand]:
|
||||
def to_application_command(self, nested: int = 0) -> Optional[EditApplicationCommand]:
|
||||
if self.slash_command is False:
|
||||
return
|
||||
elif nested == 3:
|
||||
raise ValueError(f"{self.qualified_name} is too deeply nested!")
|
||||
|
||||
payload = {
|
||||
"name": self.name,
|
||||
"description": self.short_doc or "no description",
|
||||
"options": []
|
||||
}
|
||||
if nested != 0:
|
||||
payload["type"] = 1
|
||||
|
||||
option_descriptions = self.extras.get("option_descriptions", {})
|
||||
for name, param in self.clean_params.items():
|
||||
@ -1561,6 +1565,22 @@ class Group(GroupMixin[CogT], Command[CogT, P, T]):
|
||||
view.previous = previous
|
||||
await super().reinvoke(ctx, call_hooks=call_hooks)
|
||||
|
||||
def to_application_command(self, nested: int = 0) -> Optional[EditApplicationCommand]:
|
||||
if self.slash_command is False:
|
||||
return
|
||||
elif nested == 2:
|
||||
raise ValueError(f"{self.qualified_name} is too deeply nested for slash commands!")
|
||||
|
||||
return { # type: ignore
|
||||
"name": self.name,
|
||||
"type": int(not (nested - 1)) + 1,
|
||||
"description": self.short_doc or 'no description',
|
||||
"options": [
|
||||
cmd.to_application_command(nested=nested+1)
|
||||
for cmd in self.commands
|
||||
]
|
||||
}
|
||||
|
||||
# Decorators
|
||||
|
||||
@overload
|
||||
|
Loading…
x
Reference in New Issue
Block a user