From 64e5d0534503ce348714e1a329cbb362d193a2de Mon Sep 17 00:00:00 2001 From: Minz Date: Tue, 16 Jan 2024 14:20:51 +0100 Subject: [PATCH] Cleanup messages in #memes-videomemes after 48 hours --- timers/cleanupMessages-MVM.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 timers/cleanupMessages-MVM.js diff --git a/timers/cleanupMessages-MVM.js b/timers/cleanupMessages-MVM.js new file mode 100644 index 0000000..08d7169 --- /dev/null +++ b/timers/cleanupMessages-MVM.js @@ -0,0 +1,29 @@ +module.exports = { + timeout: 60000, + immediate: true, + name: 'Cleanup tasks', + async tick(client, timer) { + const channelId = '1101703550070947920'; + const channel = await client.channels.fetch(channelId); + + console.log(`[TIMER] Running cleanup task for ${channel.guild.name}/${channel.name}`); + channel.messages.fetch({ limit: 100 }).then(messages => { + //Iterate through the messages here with the variable "messages". + messages.forEach(message => { + if(message.attachments.size > 0) { + //Skip messages with attachment + return; + } + + let ageInMinutes = Math.ceil((Date.now() - message.createdTimestamp) / 1000 / 60); + if(ageInMinutes < 2880) { + //Skip messages posted within last 48 Hours + return; + } + + console.log(`[CLEANUP] [${message.guild.name}/${message.channel.name}] | ${message.author.globalName}: ${message.content}`); + message.delete(); + }); + }); + }, +}; \ No newline at end of file