您好,我正尝试对{strong>自动命令进行编程,以使用setInterval
功能在 5分钟后自动清除邮件,但是提取消息的号码错误,这会导致漫游器无限循环进行自动清除。
Discord.js v12.2.0
命令 purge.js
let destination = client.channels.cache.get(config.request);
try {
await destination.messages.fetch({ limit: 20 }).then(async messages => {
if (messages.size < 20) return console.log(messages.size, `No messages to delete.`); // this was to check the number received.
await destination.bulkDelete(messages)
await destination.send({
embed: {
color: 0x35363B,
title: `Chat Automatically Deleted.`,
footer: {
text: `Next Delete after ${config.deleteTime / 1000 / 60} minute.`,
}
}
}).then(msg => msg.delete({ timeout: 2000 }))
})
}
catch (err) {
console.log('Error while doing Bulk Delete');
console.log(err);
}
finally {
await destination.send({
files: [
`./Wallpapers/Colors.png`,
`./Wallpapers/Commands.png`
],
});
await destination.send(`- **Enjoy , <#7>**`);
}
事件 message.js
let autoClear = require(`../commands/clear`);
const interval = setInterval(function () {
autoClear.run()
}, config.deleteTime);