ClearMessagesBot-Discord icon indicating copy to clipboard operation
ClearMessagesBot-Discord copied to clipboard

Messages older than 14 days are not being deleted.

Open Qwiko opened this issue 5 years ago • 4 comments

When using bulkdelete messages older than 14 days can not be deleted. https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=bulkDelete

Qwiko avatar Mar 26 '19 15:03 Qwiko

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) {
  });
}

Qwiko avatar Mar 26 '19 15:03 Qwiko

@rhld13 let me know if you want to work on this issue.

praneetsharma avatar Jun 25 '19 04:06 praneetsharma

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!

gamer-black avatar Feb 03 '21 06:02 gamer-black

but if your code is correct lmao It is not a question it is actually an answer

gamer-black avatar Feb 03 '21 06:02 gamer-black