我的代码有问题,然后尝试查找错误
我已经尝试使用let
代替var
,但是它仍然无法正常工作。控制台中也没有输出。
我认为该错误位于我的代码的if (tylerdel == true)
之内:
if (command === prefixfile.prefix + `active`) {
var tylerdel = true
message.channel.send (`test`)
if (tylerdel == true) {
if (message.author.id === ("")) {
message.delete (1)
}
}
}
如果某条消息来自某个人,则应该删除该消息,但我也需要该消息可切换。
答案 0 :(得分:1)
根据您的代码,布尔变量tylerdel
将始终为true
,因此无需在if condition
中使用此变量。
if(command === prefixfile.prefix + 'active') {
message.channel.send('test');
if (message.author.id === '') {
message.delete(1);
}
}
答案 1 :(得分:1)
请注意==
(相等)和===
(身份)。
More info about the operators
您应该知道什么是“ Debugging”。您可以尝试在每个if
中打印一些东西,看看问题出在哪里。
希望这可以帮助您解决问题。
答案 2 :(得分:-1)
尝试一下:
if (command === prefixfile.prefix + 'active') {
var tylerdel = true;
message.channel.send ('test');
if (tylerdel) {
if (message.author.id === '') {
message.delete(1);
}
}
}