数字检查失败/被忽略。 discord.js

发布于 2025-02-09 20:55:45 字数 703 浏览 3 评论 0原文

我正在尝试制造一个允许最多3次打击的罢工系统,因此,当我尝试检查StrikeNumber是否在1到3之间时,它会忽略,如果声明,我不确定为什么,但是我已经尝试了多种修复方法,但似乎仍然失败。

这是被忽略的语句,这是

           let strikeNumber = args[2] //(Args 0 is the command it self, Args 1 is the user, Args 2 is the `Strikenumber`, and Args 3 is the reason.)

            if (!strikeNumber) {
                return message.reply("Please state the number of the strike. (Example: 1, 2, 3)")
            } if (!strikeNumber > 0 && !strikeNumber < 4) {
                return message.reply("Strike number must be from 1 to 3.")
            }

并非所有代码都在这里,并且没有错误,它只是忽略语句。

I'm trying to make a strike system that allows up to 3 strikes, so, when I try to check if the strikeNumber is between 1 and 3, it ignores the if statement, I'm not sure why, but I've tried multiple ways to fix it, and it still seems to fail.

Here is the if statement that is getting ignored:

           let strikeNumber = args[2] //(Args 0 is the command it self, Args 1 is the user, Args 2 is the `Strikenumber`, and Args 3 is the reason.)

            if (!strikeNumber) {
                return message.reply("Please state the number of the strike. (Example: 1, 2, 3)")
            } if (!strikeNumber > 0 && !strikeNumber < 4) {
                return message.reply("Strike number must be from 1 to 3.")
            }

Not all the code is here, and there is no error, it just ignores the if statement.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒废 2025-02-16 20:55:45

尝试用此替换第二个条件,它检查数字是否低于零 4

if ( num < 0 || num > 4 )

Try replacing the second condition with this, it checks if the number is below zero or above 4

if ( num < 0 || num > 4 )
勿挽旧人 2025-02-16 20:55:45

您是否使用2个语句而不是其他情况?这会实现您的目标吗?

if (!strikeNumber) {
    return message.reply("Please state the number of the strike. (Example: 1, 2, 3)")
} else {

    if (x === 1 || x === 2 || x === 3) {
        return message.reply("Strike number is 1, 2 or 3")
    } else {
        return message.reply("Strike number must be from 1 to 3.")
    }
}

Is there a reason you are using 2 if statements instead of an if else? Does this accomplish your goal?

if (!strikeNumber) {
    return message.reply("Please state the number of the strike. (Example: 1, 2, 3)")
} else {

    if (x === 1 || x === 2 || x === 3) {
        return message.reply("Strike number is 1, 2 or 3")
    } else {
        return message.reply("Strike number must be from 1 to 3.")
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文