I am trying for my JDA discord bot to delete all the messages from a text channel and I am using a highly inefficient code as of right now which occasionally works and occassionally doesn't. The code:
{
List<Message> msgs;
msgs = textChannel.getHistory().retrievePast(50).complete();
textChannel.deleteMessages(msgs).queue();
}
I know for a fact that I am calling the function and I know for a fact that the textChannel being passed is the correct one. Please do help me with the same.
The fastest and most efficient way I could think of, would be to clone the Channel and delete the old one.
Try something like this:
textChannel.createCopy().queue();
textChannel.delete().queue();