如何创建名称中带有空格的斜杠命令?

How to create a slash command with spacing in the name?

我见过一些机器人在他们的斜杠命令的名称中有 space,例如:/admin ban

但是当我尝试实现它时,我收到一条错误消息,指出斜杠命令的名称与验证正则表达式不匹配。

我的代码:

guild.commands.create({
    name: 'foo bar',
    description: 'random description here'
});

错误:

DiscordAPIError: Invalid Form Body
name: String value did not match validation regex.

这些被称为subcommands。它们是对命令进行排序的好方法。例如,不使用 setsomethingdeletesomething 命令,您可以使用 something deletesomething set.

您可以使用 options 属性 并将类型设置为 SUB_COMMAND

guild.commands.create({
  name: "foo",
  description: "random description here",
  options: [
    {
      type: "SUB_COMMAND",
      name: "bar",
      description: "some description"
    }
  ]
})

你可以在interactionCreate活动中通过.getSubcommand()

获得
const subcommand = interaction.options.getSubcommand() // "bar"