如何修复discord.js-commando bot响应未知命令 [英] How to fix discord.js-commando bot responding to unknown commands

查看:119
本文介绍了如何修复discord.js-commando bot响应未知命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating the client with the unknownCommandResponse property set to false:

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

然而,当我尝试 $ kasopdkoakwdokapowkdo 时,它回复:

Yet when I try $kasopdkoakwdokapowkdo, it responds with:

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


推荐答案

这是正确的方式,直到18日1月:他们决定通过允许运行的自定义命令使机器人未知命令和错误回复覆盖。

此更改可能尚未得到充分记录,但已被推送到 master 分支通过此提交。 com / Gawdl3yrel =nofollow noreferrer> Gawdl3y 。本主题来自此问题,并且也列在完成一栏中。 重要的东西项目[链接]。

That was the right way to do it until the 18th of January: they decided to make the bot "unknown command" and "error" replies overridable, by allowing custom commands that will run instead.
This change may not be well-documented yet, but has been pushed to the 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].

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

If you want to make it work like in the past, you'll need to use a previous version; you won't be able to update the library to add new functionalities without updating this part of the code too.

通过此更新,您可以通过扩展来创建新命令命令类(通常如此),然后添加两个属性设置为 true unknown 隐藏

如果你想要一个例子,你可以直接看默认 unknown-command 作者的更改:

With this update, you can create a new command by extending the Command class (as usually) and then adding two properties set to true: unknown and hidden.
If you want an example, you can look directly at the default unknown-command by the author of the change:

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

Remember to avoid loading the default unknown-command: it'll be loaded by default by CommandoRegistry.registerDefaultCommands() unless you explicitly tell it not to do it.
To avoid that, add unknownCommand: false to the options when you load those commands.

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

这篇关于如何修复discord.js-commando bot响应未知命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆