Reputation: 1
Is there a way to make this better? I'm trying to make unlimited purge command... But it seems like message.channel.messages.cache only gets message the time you used it and I don't really know how to make it better. The bot will just lag for a long time... and cycle wont break because of that.
for (let i = 1; i <= amount/100; i++) {
let messagecount = message.channel.messages.cache.size
if(messagecount<=5){
console.log("break")
break}
message.channel.bulkDelete(100)
}
}
Upvotes: 0
Views: 932
Reputation: 7441
According to the Discord API docs, you can't delete messages older than 2 weeks through the Discord API, and neither can you with more than 100 messages. This is not a limitation you should/would want to break, and you may encounter the risk of being ratelimited. Of course, you could loop this, as you tried, but the ratelimit is still here. If I were you and wanted to delete the messages this bad, I would either call the command multiple times, or loop the bulkDelete
with a cooldown (2000ms would be enough, I guess?).
Upvotes: 1