So, i have a discord bot with over 120 slash commands. the way my slash commands are formatted are like this:
@client.slash_command(name="fun")
async def fun(interaction: Interaction):
pass
@fun.subcommand(name="command")
async def funcommand(interaction: Interaction):
#command code
I Have several of these sub command starters. I am using NEXTCORD, PYTHON. My question is: how can i get all of these subcommands, as actual command objects that includes name and description(anything else is not required but will be good if provided.)
I tried using the get_all_commands(). i was expecting it to work, but it only showed the nextcord built in help command, since by bot does not have any prefix commands.
Every SlashApplicationCommand have children
attribute.
You can get full list of commands like in this example:
commands = []
def add_command(command: nextcord.SlashApplicationCommand | nextcord.SlashApplicationSubcommand, parent_name=''):
commands.append(
{"name": parent_name + command.name, "help": command.description, "brief": command.description})
def explore_command(command: nextcord.SlashApplicationCommand | nextcord.SlashApplicationSubcommand, parent_name=""):
if not command.children:
add_command(command, parent_name)
else:
for child in command.children.values():
explore_command(child, parent_name + command.name + " ")
for slash_command in self.client.get_all_application_commands():
explore_command(slash_command)