我的节点cron有问题。实际上,当我启动此cron时,它会运行约24小时,然后在cron运行两次和3次之后,依此类推。
您能帮我吗?这是我的npm cron软件包:https://www.npmjs.com/package/cron
这是我的代码:
var Update = new cron('*/1 * * * *', async () => {
function CheckReboot(){
const date = new Date()
if(date.getHours() === "16" || date.getHours() === "10"){
if(date.getMinutes() <= 3){
return true
}else{
return false
}
}
}
if(CheckReboot()){return}
const GET_API_Webservices = await API_Webservices()
if(!GET_API_Webservices){
return new Error("can't access to API Webservices (Refresh Staff en Ligne)")
}
const GET_API_Webservices_serveurs = GET_API_Webservices.serveurs
if(GET_API_Webservices_serveurs[1].staffs_en_service === "[]"){
if(!s1_cache.includes("Aucun")){Alert_ServerWithoutMods(1)}
var s1_mod = ["Aucun"]
}else{
var s1_mod = JSON.parse(GET_API_Webservices_serveurs[1].staffs_en_service)
}
if(GET_API_Webservices_serveurs[2].staffs_en_service === "[]"){
if(!s2_cache.includes("Aucun")){Alert_ServerWithoutMods(2)}
var s2_mod = ["Aucun"]
}else{
var s2_mod = JSON.parse(GET_API_Webservices_serveurs[2].staffs_en_service)
}
if(GET_API_Webservices_serveurs[3].staffs_en_service === "[]"){
if(!s3_cache.includes("Aucun")){Alert_ServerWithoutMods(3)}
var s3_mod = ["Aucun"]
}else{
var s3_mod = JSON.parse(GET_API_Webservices_serveurs[3].staffs_en_service)
}
s1_cache = s1_mod
s2_cache = s2_mod
s3_cache = s3_mod
const parsed_message = `@everyone\n**[STAFFS EN SERVICE]**\n\n- \`🌐\` Serveur 1 - [${GET_API_Webservices_serveurs[1].total_joueurs}/${GET_API_Webservices_serveurs[1].slots}] (Admin : ${GET_API_Webservices_serveurs[1].total_admins}) -\n-> ${s1_mod.join("\n-> ")}\n\n- \`🌐\` Serveur 2 - [${GET_API_Webservices_serveurs[2].total_joueurs}/${GET_API_Webservices_serveurs[2].slots}] (Admin : ${GET_API_Webservices_serveurs[2].total_admins}) -\n-> ${s2_mod.join("\n-> ")}\n\n- \`🌐\` Serveur 3 - [${GET_API_Webservices_serveurs[3].total_joueurs}/${GET_API_Webservices_serveurs[3].slots}] (Admin : ${GET_API_Webservices_serveurs[3].total_admins}) -\n-> ${s3_mod.join("\n-> ")}`
chan.fetchMessage("690357691364933646").then(m => {
m.edit(parsed_message)
})
}, null, true)
此Cron用于更新Discord上的消息,该消息显示游戏服务器上可用的管理员,并且在没有Staff的情况下将DM发送给主持人,但某些时候我们会两次或多次收到此消息...
提前谢谢您
我仍在阅读您的代码,但是与此同时,您可以更正此错误,因为getHours返回了数字,所以此条件始终返回false!
if(date.getHours() === "16" || date.getHours() === "10")
//更新
我不认为Cron有任何问题,就像我在上面解释的那样,您的if语句总是返回false,导致此行从不返回:
if (CheckReboot()) {
return
}