node.js - 慢模式命令总是发送相同的东西
问题描述
我正在尝试让我的慢模式命令正常工作。基本上,当我输入 >sm 2s 时,它会回复“请按照此示例进行操作:;sm 5”<- 如果 args 为空,则该回复应该只发送。
if(args[1] == null) {
return message.channel.send("Please follow this example: ;sm 5")
}if (args[1] !== null) {
message.channel.setRateLimitPerUser(args[0])
message.channel.send(`Slowmode is now ${args[0]}s`)
}}
module.exports.config = {
name: "sm",
aliases: []
}```
解决方案
在 JavaScript 和大多数其他语言中,您可以!
在函数中将not
.
例如,让我们采取message.member.hasPermission()
. 如果我们!
在开头添加,给我们:
if (!message.member.hasPermission('ADMINISTRATOR') return
我们基本上是在告诉客户,if the message member does **not** have the administrator permission, return the command
.
现在,让我们看看你的 if 语句,说if (!args[1] == null) {
,你基本上是在告诉客户if not args[1] equals to null do this:
,让我们面对它完全没有意义。
当我们想将变量与某个值进行比较时,我们想告诉客户端if args[1] is **not** equal to null, do this.
因此为什么你应该将你的 if 语句修改为:
if (args[1] !== null) {
很抱歉回答的很长,感觉就像给某人上了一课:p
推荐阅读
- c# - 如何模拟实体框架核心变更跟踪
- azure-blob-storage - 如何在 azure 中读取和写入不可变 Blob 存储
- mongodb - Mongoose 5.6.1 上的大量连接
- javascript - 使用 JavaScript 将 svg 和 img 元素导出到同一个文件
- instagram - 如何检索应用程序的 Instagram 主页新闻提要?
- r - R Shiny Server 将不接受 UI 输入。声称“无效参数”
- java - tempCodeRunnerFile.jar 中没有主要清单属性
- git - 如何在 GIT 中更新 repo 中的分支
- java - 目录的单元测试存在 - Junit
- java - 从日期列表中获取下一个生日