Search code examples
javadiscorddiscord-jda

Trying to iterate through all messages in a discord channel with JDA


I want to iterate through all messages in a channel in JDA, but im not sure how to do it. I have tried to get iterableHistory but it doesnt give me anything useful I think. Ive tried going through the docs but I cant find anything useful. Im trying to get a list or an array list if possible so that each message could be added to a file.


Solution

  • List<Message> messageListRaw = (currentChannel.getHistoryFromBeginning(100).complete().getRetrievedHistory());
                ArrayList<Message> messageList = new ArrayList<Message>(messageListRaw);
                Collections.reverse(messageList);
                for (Message message :  messageList){
                    //Use for 'message'
                }