此代码每次运行时都会发送一秒钟的垃圾邮件。有谁知道防止这种情况发生?变量计数是过去一小时发送的消息量,我的目标是如果过去一小时发送的消息超过 15 条,则发送消息。这是我尝试过的代码:
var count = await keyv.get('messagecount')
const sendtochan = await rotate.guild.channels.cache.get('760626595332358205');
cron.schedule('0 0 * * * *', async () => {
if (count > 14 && !rotate.author.bot) {
keyv.set('messagecount', 0)
const sendtochan = await rotate.guild.channels.cache.get('760626595332358205');
sendtochan.send(`This channel's current topic is: **${await keyv.get('topic')}**`);
return
}
if (count < 14 && !rotate.author.bot) {
keyv.set('messagecount', 0)
return
}
});