public class MessageHistory
extends java.lang.Object
Message
history of a
MessageChannel
.
Modifier and Type | Class | Description |
---|---|---|
static class |
MessageHistory.MessageRetrieveAction |
Constructs a MessageHistory object with initially retrieved Messages before or after a certain pivot message id.
|
Constructor | Description |
---|---|
MessageHistory(MessageChannel channel) |
Creates a new MessageHistory object.
|
Modifier and Type | Method | Description |
---|---|---|
MessageChannel |
getChannel() |
Returns the
MessageChannel that this MessageHistory
is related to. |
static MessageHistory.MessageRetrieveAction |
getHistoryAfter(MessageChannel channel,
java.lang.String messageId) |
Constructs a
MessageHistory with the initially retrieved history
of messages sent after the mentioned message ID (exclusive). |
static MessageHistory.MessageRetrieveAction |
getHistoryAround(MessageChannel channel,
java.lang.String messageId) |
Constructs a
MessageHistory with the initially retrieved history
of messages sent around the mentioned message ID (inclusive). |
static MessageHistory.MessageRetrieveAction |
getHistoryBefore(MessageChannel channel,
java.lang.String messageId) |
Constructs a
MessageHistory with the initially retrieved history
of messages sent before the mentioned message ID (exclusive). |
JDA |
getJDA() |
The corresponding JDA instance for this MessageHistory
|
Message |
getMessageById(long id) |
Used to get a Message from the set of already retrieved message via it's message Id.
|
Message |
getMessageById(java.lang.String id) |
Used to get a Message from the set of already retrieved message via it's message Id.
|
java.util.List<Message> |
getRetrievedHistory() |
Returns a List of Messages, sorted starting from newest to oldest, of all message that have already been retrieved
from Discord with this MessageHistory object using the
retrievePast(int) , retrieveFuture(int) , and
MessageChannel.getHistoryAround(String, int) methods. |
boolean |
isEmpty() |
Whether this MessageHistory instance has retrieved any messages.
|
RestAction<java.util.List<Message>> |
retrieveFuture(int amount) |
Retrieves messages from Discord that were sent more recently than the most recently sent message in
MessageHistory's history cache (
getRetrievedHistory() ). |
RestAction<java.util.List<Message>> |
retrievePast(int amount) |
Retrieves messages from Discord that were sent before the oldest sent message in MessageHistory's history cache
(
getRetrievedHistory() ). |
int |
size() |
The amount of retrieved
Messages
by this MessageHistory. |
public MessageHistory(MessageChannel channel)
channel
- The MessageChannel
to retrieval history from.public JDA getJDA()
public int size()
Messages
by this MessageHistory.
0
until any call to retrieve messages has completed.
See retrievePast(int)
and retrieveFuture(int)
!public boolean isEmpty()
public MessageChannel getChannel()
MessageChannel
that this MessageHistory
is related to.@CheckReturnValue public RestAction<java.util.List<Message>> retrievePast(int amount)
getRetrievedHistory()
).
100
messages at a time.
Messages
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.Messages
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.
Possible ErrorResponses
include:
UNKNOWN_MESSAGE
MessageHistory
instance.MISSING_ACCESS
Guild
or
Group
.MISSING_PERMISSIONS
Permission.MESSAGE_HISTORY
permission.UNKNOWN_CHANNEL
amount
- The amount of Messages
to retrieve.RestAction
-
Type: List
<Message
>
java.lang.IllegalArgumentException
- The the amount
is less than 1
or greater than 100
.@CheckReturnValue public RestAction<java.util.List<Message>> retrieveFuture(int amount)
getRetrievedHistory()
).
Use case for this method is for getting more recent messages after jumping to a specific point in history
using something like MessageChannel.getHistoryAround(String, int)
.
retrievePast(int)
's Additional Retrieval mode.
Note: This method can only be used after Messages
have already
been retrieved from Discord.
Possible ErrorResponses
include:
UNKNOWN_MESSAGE
MessageHistory
instance.MISSING_ACCESS
Guild
or
Group
.MISSING_PERMISSIONS
Permission.MESSAGE_HISTORY
permission.UNKNOWN_CHANNEL
amount
- The amount of Messages
to retrieve.RestAction
-
Type: List
<Message
>
java.lang.IllegalArgumentException
- The the amount
is less than 1
or greater than 100
.java.lang.IllegalStateException
- If no messages have been retrieved by this MessageHistory.public java.util.List<Message> getRetrievedHistory()
retrievePast(int)
, retrieveFuture(int)
, and
MessageChannel.getHistoryAround(String, int)
methods.public Message getMessageById(java.lang.String id)
Note: This methods is not the same as MessageChannel.getMessageById(String)
, which itself queries
Discord. This method is for getting a message that has already been retrieved by this MessageHistory object.
id
- The id of the requested Message.id
as the one provided.java.lang.IllegalArgumentException
- If the provided id
is null or empty.java.lang.NumberFormatException
- If the provided id
cannot be parsed by Long.parseLong(String)
public Message getMessageById(long id)
Note: This methods is not the same as MessageChannel.getMessageById(long)
, which itself queries
Discord. This method is for getting a message that has already been retrieved by this MessageHistory object.
id
- The id of the requested Message.id
as the one provided.public static MessageHistory.MessageRetrieveAction getHistoryAfter(MessageChannel channel, java.lang.String messageId)
MessageHistory
with the initially retrieved history
of messages sent after the mentioned message ID (exclusive).
Alternatively you can use MessageChannel.getHistoryAfter(...)
Example
MessageHistory history = MessageHistory.getHistoryAfter(channel, messageId).limit(60).complete()
Will return a MessageHistory instance with the first 60 messages sent after the provided message ID.
Alternatively you can provide an epoch millisecond timestamp using MiscUtil.getDiscordTimestamp(long)
:
long timestamp = System.currentTimeMillis(); // or any other epoch millis timestamp
String discordTimestamp = Long.toUnsignedString(MiscUtil.getDiscordTimestamp(timestamp));
MessageHistory history = MessageHistory.getHistoryAfter(channel, discordTimestamp).complete();
channel
- The MessageChannel
messageId
- The pivot ID to useMessageRetrieveAction
java.lang.IllegalArgumentException
- If any of the provided arguments is null
;
Or if the provided messageId contains whitespaceInsufficientPermissionException
- If this is a TextChannel and the currently logged in account does not
have the permission Permission.MESSAGE_HISTORY
MessageChannel.getHistoryAfter(String, int)
,
MessageChannel.getHistoryAfter(long, int)
,
MessageChannel.getHistoryAfter(Message, int)
public static MessageHistory.MessageRetrieveAction getHistoryBefore(MessageChannel channel, java.lang.String messageId)
MessageHistory
with the initially retrieved history
of messages sent before the mentioned message ID (exclusive).
Alternatively you can use MessageChannel.getHistoryBefore(...)
Example
MessageHistory history = MessageHistory.getHistoryBefore(channel, messageId).limit(60).complete()
Will return a MessageHistory instance with the first 60 messages sent before the provided message ID.
Alternatively you can provide an epoch millisecond timestamp using MiscUtil.getDiscordTimestamp(long)
:
long timestamp = System.currentTimeMillis(); // or any other epoch millis timestamp
String discordTimestamp = Long.toUnsignedString(MiscUtil.getDiscordTimestamp(timestamp));
MessageHistory history = MessageHistory.getHistoryBefore(channel, discordTimestamp).complete();
channel
- The MessageChannel
messageId
- The pivot ID to useMessageRetrieveAction
java.lang.IllegalArgumentException
- If any of the provided arguments is null
;
Or if the provided messageId contains whitespaceInsufficientPermissionException
- If this is a TextChannel and the currently logged in account does not
have the permission Permission.MESSAGE_HISTORY
MessageChannel.getHistoryBefore(String, int)
,
MessageChannel.getHistoryBefore(long, int)
,
MessageChannel.getHistoryBefore(Message, int)
public static MessageHistory.MessageRetrieveAction getHistoryAround(MessageChannel channel, java.lang.String messageId)
MessageHistory
with the initially retrieved history
of messages sent around the mentioned message ID (inclusive).
Alternatively you can use MessageChannel.getHistoryAround(...)
Example
MessageHistory history = MessageHistory.getHistoryAround(channel, messageId).limit(60).complete()
Will return a MessageHistory instance with the first 60 messages sent around the provided message ID.
Alternatively you can provide an epoch millisecond timestamp using MiscUtil.getDiscordTimestamp(long)
:
long timestamp = System.currentTimeMillis(); // or any other epoch millis timestamp
String discordTimestamp = Long.toUnsignedString(MiscUtil.getDiscordTimestamp(timestamp));
MessageHistory history = MessageHistory.getHistoryAround(channel, discordTimestamp).complete();
channel
- The MessageChannel
messageId
- The pivot ID to useMessageRetrieveAction
java.lang.IllegalArgumentException
- If any of the provided arguments is null
;
Or if the provided messageId contains whitespaceInsufficientPermissionException
- If this is a TextChannel and the currently logged in account does not
have the permission Permission.MESSAGE_HISTORY
MessageChannel.getHistoryAround(String, int)
,
MessageChannel.getHistoryAround(long, int)
,
MessageChannel.getHistoryAround(Message, int)