Deleting all messages in discord.js text channel

Xydez picture Xydez · Jan 12, 2018 · Viewed 60.9k times · Source

Ok, so I searched for a while, but I couldn't find any information on how to delete all messages in a discord channel. And by all messages I mean every single message ever written in that channel. Any clues?

Answer

user8690818 picture user8690818 · Aug 3, 2018

Try this

async () => {
  let fetched;
  do {
    fetched = await channel.fetchMessages({limit: 100});
    message.channel.bulkDelete(fetched);
  }
  while(fetched.size >= 2);
}