feat: delete old messages on start

This commit is contained in:
ethanf 2023-12-15 22:56:29 -06:00
parent 4964bf50e1
commit 974d01a08f

View File

@ -20,6 +20,16 @@ const client = new Client({
client.on("ready", () => { client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`); 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 // send message on error