Reputation: 157
I've seen some bots that have space in the name of their slash commands, ex: /admin ban
But when I try to implement it, I get an error saying that the name of the slash command does not match a validation regex.
My code:
guild.commands.create({
name: 'foo bar',
description: 'random description here'
});
Error:
DiscordAPIError: Invalid Form Body
name: String value did not match validation regex.
Upvotes: 5
Views: 3681
Reputation: 9041
These are called subcommands. They are a good way to sort commands. For example, instead of using setsomething
and deletesomething
commands, you could use something delete
and something set
.
You can do this with the options
property, and setting the type to SUB_COMMAND
guild.commands.create({
name: "foo",
description: "random description here",
options: [
{
type: "SUB_COMMAND",
name: "bar",
description: "some description"
}
]
})
You can get this in the interactionCreate
event through .getSubcommand()
const subcommand = interaction.options.getSubcommand() // "bar"
Upvotes: 5