discord commando 出错 名称/别名为“$command.name”的命令已注册

Posted

技术标签:

【中文标题】discord commando 出错 名称/别名为“$command.name”的命令已注册【英文标题】:Error on discord commando A command with the name/alias "$command.name" is already registereddiscord commando 出错 名称/别名为“$command.name”的命令已注册 【发布时间】:2021-08-03 16:20:21 【问题描述】:

我正在使用 Node.js Discord.js-commando,我尝试运行我的代码,但是出现了这个问题,请告诉我您是否遇到相同的错误或有修复。下面的代码来自 index.js,供您参考。请回复此消息并告诉我您是否知道

C:\Users\james\OneDrive\Desktop\Discover Now\node_modules\discord.js-commando\src\registry.js:129
                        throw new Error(`A command with the name/alias "$command.name" is already registered.`);
                        ^

Error: A command with the name/alias "help" is already registered.
    at CommandoRegistry.registerCommand (C:\Users\james\OneDrive\Desktop\Discover Now\node_modules\discord.js-commando\src\registry.js:129:10)
    at CommandoRegistry.registerCommands (C:\Users\james\OneDrive\Desktop\Discover Now\node_modules\discord.js-commando\src\registry.js:176:9)
    at CommandoRegistry.registerCommandsIn (C:\Users\james\OneDrive\Desktop\Discover Now\node_modules\discord.js-commando\src\registry.js:200:15)
    at Object.<anonymous> (C:\Users\james\OneDrive\Desktop\Discover Now\index.js:67:4)
    at Module._compile (node:internal/modules/cjs/loader:1102:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
    at Module.load (node:internal/modules/cjs/loader:967:32)
    at Function.Module._load (node:internal/modules/cjs/loader:807:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

这是我在 index.js 中的代码/命令处理程序,我有 5 个类别,每个类别都有自己的名称。如果你有答案请回复


client.registry
  .registerDefaultTypes()
  .registerGroups([
    ["fun", "Fun Commands"],
    ["moderation", "Moderation Commands"],
    ["special", "Special Commands"],
    ["misc", "Misc Commands"],
    ["music", "Music Commands"]
  ])
  .registerDefaultGroups()
  .registerDefaultCommands()
  .registerCommandsIn(path.join(__dirname, "commands"));


【问题讨论】:

看起来path.join(__dirname, "commands") 包含已注册的命令help 我该如何解决这个问题,这是我第一次与突击队合作。 不要注册help 两次。它曾经在registerDefaultCommands()registerCommandsIn(path.join(__dirname, "commands")) 中注册过一次。您可以禁用默认命令或删除您的自定义命令。 【参考方案1】:

您可以在这里做两件事,将您的自定义命令从 help 更改为其他类似 commands 或禁用由突击队提供的默认命令 help

要禁用突击队的默认help 命令,您可以这样做

client.registry
  .registerDefaultTypes()
  .registerGroups([
    ["fun", "Fun Commands"],
    ["moderation", "Moderation Commands"],
    ["special", "Special Commands"],
    ["misc", "Misc Commands"],
    ["music", "Music Commands"]
  ])
    .registerDefaultGroups()
    .registerDefaultCommands(
      help: false,
      prefix: true,
      ping: true,
      eval: true,
      unknownCommand: true,
      commandState: true,
    )
  .registerCommandsIn(path.join(__dirname, "commands"));

【讨论】:

以上是关于discord commando 出错 名称/别名为“$command.name”的命令已注册的主要内容,如果未能解决你的问题,请参考以下文章

Discord.js-commando 缺少参数回复

Discord.js Commando 广播所有命令错误

嵌入命令(颜色)(discord.js-commando)

尝试为 Discord bot 编写音乐播放器时出错

Discord.js 和 discord.js-commando 防止命令在特定通道中运行

广播所有命令不自动删除广播 - Discord.js-Commando