Codota Logo
MessageHistory
Code IndexAdd Codota to your IDE (free)

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

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Connection c =
  • Codota IconDataSource dataSource;dataSource.getConnection()
  • Codota IconString url;DriverManager.getConnection(url)
  • Codota IconIdentityDatabaseUtil.getDBConnection()
  • Smart code suggestions by Codota
}
origin: DV8FromTheWorld/JDA

/**
 * Creates a new {@link MessageHistory MessageHistory} object for each call of this method.
 * <br>MessageHistory is <b>NOT</b> an internal message cache, but rather it queries the Discord servers for previously sent messages.
 *
 * @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException
 *         If this is a {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}
 *         and the currently logged in account does not have the permission {@link net.dv8tion.jda.core.Permission#MESSAGE_HISTORY MESSAGE_HISTORY}
 *
 * @return A {@link net.dv8tion.jda.core.entities.MessageHistory MessageHistory} related to this channel.
 */
default MessageHistory getHistory()
{
  return new MessageHistory(this);
}
origin: DV8FromTheWorld/JDA

default MessageHistory.MessageRetrieveAction getHistoryAfter(String messageId, int limit)
  return MessageHistory.getHistoryAfter(this, messageId).limit(limit);
origin: DV8FromTheWorld/JDA

default MessageHistory.MessageRetrieveAction getHistoryAround(String messageId, int limit)
  return MessageHistory.getHistoryAround(this, messageId).limit(limit);
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

  return;
MessageHistory history = new MessageHistory(channel);
int toRetrieve = amount;
int i = 0;
outer:
while (toRetrieve > 0) {
  if (history.retrievePast((targetUser == null ? Math.min(toRetrieve, 100) : 100)).complete().isEmpty()) {
    break;
  for (Message msg : history.getRetrievedHistory()) {
    if (msg.getCreationTime().plusWeeks(2).isBefore(OffsetDateTime.now())) break outer;
    if (msg.getId().equals(message.getId())) continue;
origin: DV8FromTheWorld/JDA

checkArguments(channel, messageId);
Route.CompiledRoute route = Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId()).withQueryParams("around", messageId);
return new MessageRetrieveAction(route, channel);
origin: DV8FromTheWorld/JDA

return new RestAction<List<Message>>(getJDA(), route)
origin: DV8FromTheWorld/JDA

/**
 * Used to get a Message from the set of already retrieved message via it's message Id.
 * <br>If a Message with the provided id has not already been retrieved (thus, doesn't not exist in this MessageHistory
 * object), then this method returns null.
 * <p>
 * <b>Note:</b> This methods is not the same as {@link MessageChannel#getMessageById(String)}, which itself queries
 * Discord. This method is for getting a message that has already been retrieved by this MessageHistory object.
 *
 * @param  id
 *         The id of the requested Message.
 *
 * @throws java.lang.IllegalArgumentException
 *         If the provided {@code id} is null or empty.
 * @throws java.lang.NumberFormatException
 *         If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)}
 *
 * @return Possibly-null Message with the same {@code id} as the one provided.
 */
public Message getMessageById(String id)
{
  return getMessageById(MiscUtil.parseSnowflake(id));
}
origin: DV8FromTheWorld/JDA

default MessageHistory.MessageRetrieveAction getHistoryBefore(String messageId, int limit)
  return MessageHistory.getHistoryBefore(this, messageId).limit(limit);
origin: FlareBot/FlareBot

.retrievePast(100)
.complete()
.stream()
origin: DV8FromTheWorld/JDA

checkArguments(channel, messageId);
Route.CompiledRoute route = Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId()).withQueryParams("after", messageId);
return new MessageRetrieveAction(route, channel);
origin: DV8FromTheWorld/JDA

  route = route.withQueryParams("before", String.valueOf(history.lastKey()));
return new RestAction<List<Message>>(getJDA(), route)
origin: Kaaz/DiscordBot

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

  @Override
  protected void handleResponse(Response response, Request<MessageHistory> request)
  {
    if (!response.isOk())
    {
      request.onFailure(response);
      return;
    }
    final MessageHistory result = new MessageHistory(channel);
    final JSONArray array = response.getArray();
    final EntityBuilder builder = api.get().getEntityBuilder();
    for (int i = 0; i < array.length(); i++)
    {
      try
      {
        JSONObject obj = array.getJSONObject(i);
        result.history.put(obj.getLong("id"), builder.createMessage(obj, channel, false));
      }
      catch (JSONException | NullPointerException e)
      {
        LOG.warn("Encountered exception in MessagePagination", e);
      }
    }
    request.onSuccess(result);
  }
}
origin: DV8FromTheWorld/JDA

checkArguments(channel, messageId);
Route.CompiledRoute route = Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId()).withQueryParams("before", messageId);
return new MessageRetrieveAction(route, channel);
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.entitiesMessageHistory

Javadoc

Represents an access point to the net.dv8tion.jda.core.entities.Message history of a net.dv8tion.jda.core.entities.MessageChannel.
Note: Message order is always in recent to past order. I.e: A message at index 0 of a list is more recent than a message at index 1.

Most used methods

  • retrievePast
    Retrieves messages from Discord that were sent before the oldest sent message in MessageHistory's hi
  • <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

  • Making http post requests using okhttp
  • compareTo (BigDecimal)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • putExtra (Intent)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Permission (java.security)
    Abstract class for representing access to a system resource. All permissions have a name (whose inte
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • JCheckBox (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now