Add group command support

This commit is contained in:
Gnome
2021-08-31 15:17:49 +01:00
parent 614c6bca67
commit 1a22df6228
2 changed files with 26 additions and 7 deletions

View File

@@ -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