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:
JavaScript
x
5
1
guild.commands.create({
2
name: 'foo bar',
3
description: 'random description here'
4
});
5
Error:
JavaScript
1
3
1
DiscordAPIError: Invalid Form Body
2
name: String value did not match validation regex.
3
Advertisement
Answer
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
JavaScript
1
12
12
1
guild.commands.create({
2
name: "foo",
3
description: "random description here",
4
options: [
5
{
6
type: "SUB_COMMAND",
7
name: "bar",
8
description: "some description"
9
}
10
]
11
})
12
You can get this in the interactionCreate
event through .getSubcommand()
JavaScript
1
2
1
const subcommand = interaction.options.getSubcommand() // "bar"
2