如何修复 discord.js-commando bot 响应未知命令

How to fix discord.js-commando bot responding to unknown commands

我正在创建客户端 unknownCommandResponse 属性 设置为 false:

const client = new CommandoClient({
  commandPrefix: '$',
  unknownCommandResponse: false,
  owner: '291048060845424640',
  disableEveryone: true
});

然而,当我尝试 $kasopdkoakwdokapowkdo 时,它的响应是:

Unknown command. Use $help or @Mysticonomy#2670 help to view the command list.

在 1 月 18 日之前,这是正确的做法:他们决定通过允许将 运行相反。
此更改可能尚未得到充分记录,但已被推送到 master branch with this commit by Gawdl3y. This topic comes from this issue, and is also listed in the "Done" column of the "Important stuff" project [link]。

如果你想让它像过去一样工作,你需要使用以前的版本;如果不更新这部分代码,您将无法更新库以添加新功能。

通过此更新,您可以通过扩展 Command class(通常)然后添加两个设置为 true 的属性来创建新命令:unknownhidden.
想要例子的可以直接看作者改的默认的unknown-command

module.exports = class UnknownCommandCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'unknown-command',
      group: 'util',
      memberName: 'unknown-command',
      description: 'Displays help information for when an unknown command is used.',
      examples: ['unknown-command kickeverybodyever'],
      unknown: true,
      hidden: true
    });
  }

  run(msg) {
    return msg.reply(
      `Unknown command. Use ${msg.anyUsage(
                'help',
                msg.guild ? undefined : null,
                msg.guild ? undefined : null
            )} to view the command list.`
    );
  }
};

记住要避免加载默认值 unknown-command:它将由 CommandoRegistry.registerDefaultCommands() 默认加载,除非您明确告诉它不要这样做。
为避免这种情况,请在加载这些命令时将 unknownCommand: false 添加到选项中。

client.registry.registerDefaultCommands({
  unknownCommand: false
});