ClearMessagesBot-Discord
ClearMessagesBot-Discord copied to clipboard
Messages older than 14 days are not being deleted.
When using bulkdelete messages older than 14 days can not be deleted. https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=bulkDelete
When I wrote my bot I used this solution.
messages = await message.channel.fetchMessages({
limit: 100
});
await message.channel
.bulkDelete(messages, true)
.then(deletedMessages => {
//Filtering out messages that did not get deleted.
messages = messages.filter(val => {
!deletedMessages.array().includes(val);
});
if (messages.size > 0) {
//Deleting messages older than 14 days
messages.deleteAll();
}
})
.catch(function(error) {
});
}
@rhld13 let me know if you want to work on this issue.
When I wrote my bot I used this solution.
messages = await message.channel.fetchMessages({ limit: 100 }); await message.channel .bulkDelete(messages, true) .then(deletedMessages => { //Filtering out messages that did not get deleted. messages = messages.filter(val => { !deletedMessages.array().includes(val); }); if (messages.size > 0) { //Deleting messages older than 14 days messages.deleteAll(); } }) .catch(function(error) { }); }
Thnx user this helped me alot although i wasn't able to get messages more then 100 it truly helped me just replace message.channel.fetchMessages with message.channel.messages.fetch and remove that last bracket!
but if your code is correct lmao It is not a question it is actually an answer