Tabnine Logo
MessageHistory.retrievePast
Code IndexAdd Tabnine to your IDE (free)

How to use
retrievePast
method
in
net.dv8tion.jda.core.entities.MessageHistory

Best Java code snippets using net.dv8tion.jda.core.entities.MessageHistory.retrievePast (Showing top 7 results out of 315)

origin: avaire/avaire

private void loadMessages(MessageHistory history, int toDelete, Set<Long> userIds, Consumer<List<Message>> consumer) {
  long maxMessageAge = (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(14) - MiscUtil.DISCORD_EPOCH) << MiscUtil.TIMESTAMP_OFFSET;
  List<Message> messages = new ArrayList<>();
  history.retrievePast(toDelete).queue(historyMessages -> {
    if (historyMessages.isEmpty()) {
      consumer.accept(messages);
      return;
    }
    for (Message historyMessage : historyMessages) {
      if (historyMessage.isPinned() || historyMessage.getIdLong() < maxMessageAge) {
        continue;
      }
      if (userIds != null && !userIds.contains(historyMessage.getAuthor().getIdLong())) {
        continue;
      }
      if (messages.size() >= toDelete) {
        consumer.accept(messages);
        return;
      }
      messages.add(historyMessage);
    }
    consumer.accept(messages);
  });
}
origin: FlareBot/FlareBot

.retrievePast(100)
.complete()
.stream()
origin: Kaaz/DiscordBot

do {
  int part = Math.min(MAX_BULK_SIZE, totalMessages);
  List<Message> messages = history.retrievePast(part).complete();
  if (messages.isEmpty()) {
    break;
origin: FlareBot/FlareBot

outer:
while (toRetrieve > 0) {
  if (history.retrievePast((targetUser == null ? Math.min(toRetrieve, 100) : 100)).complete().isEmpty()) {
    break;
origin: FlareBot/FlareBot

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
  if (args.length == 1 && args[0].matches("[0-9]{18,22}")) {
    if (!guild.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_MANAGE)) {
      MessageUtils.sendErrorMessage("I need the `Manage Messages` permission in order to pin!", channel);
      return;
    }
    Message msg = channel.getMessageById(args[0].trim()).complete();
    if (msg == null) {
      MessageUtils.sendErrorMessage("That message could not be found!", channel);
      return;
    }
    msg.pin().complete();
    channel.getHistory().retrievePast(1).complete().get(0).delete().queue();
  } else if (args.length != 0) {
    if (!guild.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_MANAGE)) {
      MessageUtils.sendErrorMessage("I need the `Manage Messages` permission in order to pin!", channel);
      return;
    }
    Message msg = channel.sendMessage(new EmbedBuilder().setTitle(sender.getName(), null)
        .setThumbnail(MessageUtils.getAvatar(sender)).setDescription(MessageUtils.getMessage(args, 0))
        .build()).complete();
    msg.pin().complete();
    channel.getHistory().retrievePast(1).complete().get(0).delete().queue();
  } else {
    MessageUtils.sendUsage(this, channel, sender, args);
  }
}
origin: avaire/avaire

context.getChannel().getHistory().retrievePast(2).queue(messages -> {
  if (messages.size() != 2) {
    return;
origin: FlareBot/FlareBot

if (reaction != null) {
  if (reaction.getCount() == 5) {
    message.pin().queue((aVoid) -> event.getChannel().getHistory().retrievePast(1).complete().get(0)
        .delete().queue());
net.dv8tion.jda.core.entitiesMessageHistoryretrievePast

Javadoc

Retrieves messages from Discord that were sent before the oldest sent message in MessageHistory's history cache ( #getRetrievedHistory()).
Can only retrieve a maximum of 100 messages at a time.
This method has 2 modes of operation: initial retrieval and additional retrieval.
  • Initial Retrieval
    This mode is what is used when no net.dv8tion.jda.core.entities.Message have been retrieved yet ( #getRetrievedHistory()'s size is 0). Initial retrieval starts from the most recent message sent to the channel and retrieves backwards from there. So, if 50 messages are retrieved during this mode, the most recent 50 messages will be retrieved.
  • Additional Retrieval
    This mode is used once some net.dv8tion.jda.core.entities.Message have already been retrieved from Discord and are stored in MessageHistory's history ( #getRetrievedHistory()). When retrieving messages in this mode, MessageHistory will retrieve previous messages starting from the oldest message stored in MessageHistory.
    E.g: If you initially retrieved 10 messages, the next call to this method to retrieve 10 messages would retrieve the next 10 messages, starting from the oldest message of the 10 previously retrieved messages.

Possible net.dv8tion.jda.core.requests.ErrorResponse include:

  • net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_MESSAGE
    Can occur if retrieving in Additional Mode and the Message being used as the marker for the last retrieved Message was deleted. Currently, to fix this, you need to create a new net.dv8tion.jda.core.entities.MessageHistory instance.
  • net.dv8tion.jda.core.requests.ErrorResponse#MISSING_ACCESS
    Can occur if the request for history retrieval was executed after JDA lost access to the Channel, typically due to the account being removed from the net.dv8tion.jda.core.entities.Guild or net.dv8tion.jda.client.entities.Group.
  • net.dv8tion.jda.core.requests.ErrorResponse#MISSING_PERMISSIONS
    Can occur if the request for history retrieval was executed after JDA lost the net.dv8tion.jda.core.Permission#MESSAGE_HISTORY permission.
  • net.dv8tion.jda.core.requests.ErrorResponse#UNKNOWN_CHANNEL
    The send request was attempted after the channel was deleted.

Popular methods of MessageHistory

  • <init>
    Creates a new MessageHistory object.
  • checkArguments
  • getHistoryAfter
    Constructs a net.dv8tion.jda.core.entities.MessageHistory with the initially retrieved history of me
  • getHistoryAround
    Constructs a net.dv8tion.jda.core.entities.MessageHistory with the initially retrieved history of me
  • getHistoryBefore
    Constructs a net.dv8tion.jda.core.entities.MessageHistory with the initially retrieved history of me
  • getJDA
    The corresponding JDA instance for this MessageHistory
  • getMessageById
    Used to get a Message from the set of already retrieved message via it's message Id. If a Message wi
  • getRetrievedHistory
    Returns a List of Messages, sorted starting from newest to oldest, of all message that have already
  • size
    The amount of retrieved net.dv8tion.jda.core.entities.Messageby this MessageHistory. This returns 0

Popular in Java

  • Reactive rest calls using spring rest template
  • getExternalFilesDir (Context)
  • getSharedPreferences (Context)
  • runOnUiThread (Activity)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Permission (java.security)
    Legacy security code; do not use.
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now