[英]Check when a value is equal to 0
I have a process that runs when the command is issued in the discord bot, sometimes this process will fail and I need to know when it does.我有一个在 discord 机器人中发出命令时运行的进程,有时这个进程会失败,我需要知道它什么时候会失败。 Every time after the command is issued and the process finishes it logs in console
console.log ('Process done: All succeded: %s || All failed, %s'), allsucces, allfailed
每次发出命令并且进程完成后,它都会登录控制台
console.log ('Process done: All succeded: %s || All failed, %s'), allsucces, allfailed
So every time all succeded = 0 I want the bot to dm me in a discord message所以每次都成功 = 0我希望机器人在 discord 消息中通知我
You can simply compare allsucces
value to 0
您可以简单地将
allsucces
值与0
进行比较
if (allsucces === 0) {
/* DM Logic */
}
These links might also provide you with some useful information regarding Javascript and how Comparison and logical Operators work:这些链接还可能为您提供有关 Javascript 以及比较和逻辑运算符如何工作的一些有用信息:
Javascript Basics Javascript 基础知识
JavaScript Comparison and Logical Operators JavaScript 比较和逻辑运算符
To compare 2 values, use comparison operators .要比较 2 个值,请使用比较运算符。
Here's how they work:以下是它们的工作方式:
val == 0 // val has the value 0 but does not *need* to be the same type ("0" == 0 is true)
val === 0 // val is 0, both in value and type
val != 0 // opposite of "==" - val does not have the value 0
val !== 0 // opposite of "===" - val does not have the value 0, or is not the same type
val > 0 // val is more than 0
val < 0 // val is less than 0
val >= 0 // val is more than or equal to 0
val <= 0 // val is less than or equal to 0
See the difference between ===
and ==
in this question在这个问题中查看
===
和==
之间的区别
To implement this in your code, use the ===
operator要在您的代码中实现这一点,请使用
===
运算符
if (allsucces === 0) {
// allsucces is equal to 0
}
And be sure allsucces
is a number, not a string, otherwise the strict equals operator will make it return false
!并确保
allsucces
是一个数字,而不是一个字符串,否则严格的等于运算符会使其返回false
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.