【问题标题】:Slowmode command always sends the same thing慢模式命令总是发送相同的东西
【发布时间】:2021-04-11 12:31:12
【问题描述】:

我正在尝试让我的慢速模式命令正常工作。基本上,当我输入 >sm 2s 时,它会回复“请按照此示例进行操作:;sm 5”


  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: []
}```

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    在 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

    【讨论】:

    • 遗憾的是,我仍然只回复我之前提到的内容.. [imgur.com/a/Cj72xza]
    • 这是我的建议:与其检查 args[1] 是否为空,我建议您简单地执行以下操作:if (!args[1]) return // would return if no input of args[1] was given.message.channel.setRateLimitPerUser(args[0]) 此代码似乎运行良好!跨度>
    • Ehhh,我的意思是我需要它,所以当 args 为空时,我的机器人只会返回,而不是当有 args 时。
    猜你喜欢
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 2019-12-04
    • 2013-09-20
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多