Class MessagePaginationAction
- java.lang.Object
-
- net.dv8tion.jda.core.requests.RestAction<java.util.List<T>>
-
- net.dv8tion.jda.core.requests.restaction.pagination.PaginationAction<Message,MessagePaginationAction>
-
- net.dv8tion.jda.core.requests.restaction.pagination.MessagePaginationAction
-
- All Implemented Interfaces:
java.lang.Iterable<Message>
public class MessagePaginationAction extends PaginationAction<Message,MessagePaginationAction>
PaginationAction
that paginates the endpointsRoute.Messages.GET_MESSAGE_HISTORY
.Must provide not-null
MessageChannel
to compile a valid pagination route.Limits:
Minimum - 1
Maximum - 100Example
/** * Iterates messages in an async stream and stops once the limit has been reached. */ public static void onEachMessageAsync(MessageChannel channel, Consumer<Message> consumer, int limit) { if (limit< 1) return; MessagePaginationAction action = channel.getIterableHistory(); AtomicInteger counter = new AtomicInteger(limit); action.forEachAsync( (message)-> { consumer.accept(message); // if false the iteration is terminated; else it continues return counter.decrementAndGet() == 0; }); }
- Since:
- 3.1
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.dv8tion.jda.core.requests.restaction.pagination.PaginationAction
PaginationAction.PaginationIterator
-
Nested classes/interfaces inherited from class net.dv8tion.jda.core.requests.RestAction
RestAction.EmptyRestAction<T>
-
-
Field Summary
-
Fields inherited from class net.dv8tion.jda.core.requests.RestAction
DEFAULT_FAILURE, DEFAULT_SUCCESS, LOG
-
-
Constructor Summary
Constructors Constructor Description MessagePaginationAction(MessageChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageChannel
getChannel()
The targetedMessageChannel
ChannelType
getType()
TheChannelType
of the targetedMessageChannel
.-
Methods inherited from class net.dv8tion.jda.core.requests.restaction.pagination.PaginationAction
cache, cacheSize, forEachAsync, forEachAsync, forEachRemaining, forEachRemainingAsync, forEachRemainingAsync, getCached, getFirst, getLast, getLimit, getMaxLimit, getMinLimit, isCacheEnabled, isEmpty, iterator, limit, parallelStream, setCheck, spliterator, stream, takeAsync, takeRemainingAsync
-
Methods inherited from class net.dv8tion.jda.core.requests.RestAction
complete, complete, completeAfter, getJDA, isPassContext, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, setPassContext, submit, submit, submitAfter, submitAfter
-
-
-
-
Constructor Detail
-
MessagePaginationAction
public MessagePaginationAction(MessageChannel channel)
-
-
Method Detail
-
getType
public ChannelType getType()
TheChannelType
of the targetedMessageChannel
.- Returns:
ChannelType
-
getChannel
public MessageChannel getChannel()
The targetedMessageChannel
- Returns:
- The MessageChannel instance
-
-