node.js - 如果机器人无法识别命令(命令处理程序)discord.js,如何让机器人响应未知命令
问题描述
我正在努力做到这一点,所以如果有人执行 &hep 或 &asdsw 之类的操作,它会说未知命令,因为没有与用户输入的命令匹配的命令。基本上相同的未知命令。我看到了另一篇文章,但那不是针对命令处理程序的。我没有写出任何代码。谢谢!
解决方案
由于命令存储在集合中,您可以使用Collection.get()并检查命令是否存在。
const Collection = new Discord.Collection();
// This part should be already done by your command handler.
Collection.set("commandName", "commandFile");
// Getting the command (assuming the key is the name of the command)
const Command = Collection.get("commandName");
if (!Command) return message.channel.send("The command does not exist.");
// The command exists.
推荐阅读
- database - 两张表对一张表作为关系
- php - 循环价格在 Woocommerce 存档中显示为不带小数
- javascript - 如何根据来自服务器端的信息添加 HTML div 元素?
- python - Python 3.7 builtins.NameError
- python - 如何在python中找到字符串中子字符串的出现次数?
- python - pytorch 可以优化顺序操作(如张量流图或 JAX 的 jit)吗?
- javascript - 将初始数据从服务器传递到 React 应用程序
- spring - Spring JPA 多线程
- c# - 如何在 .NET Core 中修复(不抑制)CA1303(不将文字字符串作为本地化参数传递)
- ruby - 什么参数应该传递给其他方法