更新项目的节点模块后发生了新的执行错误。
我正在测试(使用DiscordJS)以下代码:
if (msg.content === "!next") {
msg.channel.send(tellDate()) ;
}
tellDate()是:
function tellDate() {
var myDate = ...// Initialize myDate as a correct Date
if(isPast(myDate){
// ...
}
else if(isFuture(myDate)){
console.log("after call isFuture function");
return `tellDate : test test`;
}
}
myDate
将进入isFuture()
测试。这是isFuture()
:
function isFuture(d)
{
console.log("entering isFuture function");
const today = new Date();
console.log("after declaring today");
if(d.getFullYear() > today.getFullYear())
return true;
else if(d.getFullYear() === today.getFullYear() && d.getMonth() > today.getMonth())
return true;
else if(d.getFullYear() === today.getFullYear() && d.getMonth() === today.getMonth() && d.getDate() > today.getDate())
return true;
else
return false;
}
但执行从未到达isFuture()
:
(node:8380) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 2): DiscordAPIError: Cannot send an empty message
(node:8380) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.
但是,如果我在tellDate()
中用“if”更改“else if”,则会显示:
entering isFuture function
after declaring today
但它不会执行日期比较(相同的错误)。
所以:
tellDate()
有所作为?您发送的msg.channel.send
消息不能为空
if (msg.content === "!next") {
const message = tellDate();
if(message) msg.channel.send(message) ;
}
您可以简单地使用>
来比较日期
function isFuture(d)
{
console.log("entering isFuture function");
const today = new Date();
console.log("after declaring today");
return d > today;
}