Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDA Discord bot to delete all messages from a text channel

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.

like image 739
Aritra Bag Avatar asked Nov 29 '25 18:11

Aritra Bag


1 Answers

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();
like image 75
Redi Avatar answered Dec 02 '25 07:12

Redi