From 974d01a08f39895b723fd08e30786b95ce3e23ec Mon Sep 17 00:00:00 2001 From: ethanf Date: Fri, 15 Dec 2023 22:56:29 -0600 Subject: [PATCH] feat: delete old messages on start --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index ee8968b..91c695f 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,16 @@ const client = new Client({ client.on("ready", () => { console.log(`Logged in as ${client.user.tag}!`); + console.log(`Deleting old messages from this bot in command channel: ${COMMAND_CHANNEL_ID}...`); + let channel = client.channels.cache.get(COMMAND_CHANNEL_ID); + if (!channel) return console.error("(ready) Can't find command channel"); + channel.messages.fetch({ limit: 100 }).then(messages => { + messages.forEach(message => { + if (message.author.id === client.user.id) { + message.delete(); + } + }); + }).catch(console.error); }); // send message on error