[英]Auto delete messages in the specified channel by time? Discord.js
I did an automatic-channel cleaning at the time I needed (Monday 15:00)
我在需要的时候进行了自动频道清理
(Monday 15:00)
But my program does not work as it should.但是我的程序不能正常工作。 The countdown starts when a message appears in the channel.
当频道中出现消息时,倒计时开始。
I need the channel to be cleared without new messages in channel.id我需要在channel.id中没有新消息的情况下清除频道
CODE代码
const schedule = require("node-schedule");
client.on("message", async (message) => {
if (client.channels.cache.get("829042005236645900")) {
const job = schedule.scheduleJob('30 * * * * *', function () {
console.log('Delete');
message.channel.bulkDelete(20)
});
}
});
It looks like you're creating the schedule inside the event handler, and that may be what's causing the issue.看起来您正在事件处理程序中创建计划,这可能是导致问题的原因。 Here's an alternative to that:
这是一个替代方案:
const schedule = require("node-schedule");
const channel = client.channels.cache.get("829042005236645900");
const job = schedule.scheduleJob('30 * * * * *', function () {
console.log('Delete');
channel.bulkDelete(20);
});
However, it also looks like you want to make the event fire every 30 seconds?但是,您似乎也想让事件每 30 秒触发一次?
node-schedule
has a system for that called Recurrence Rule Scheduling : node-schedule
有一个称为Recurrence Rule Scheduling的系统:
const schedule = require("node-schedule");
const channel = client.channels.cache.get("829042005236645900");
const job = new schedule.scheduleJob({ second: new schedule.Range(0, 59, 30) },
function () {
console.log('Delete');
channel.bulkDelete(20);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.