Interface MessageChannelMixin<T extends MessageChannelMixin<T>>
- All Superinterfaces:
Channel
,ChannelMixin<T>
,ChannelUnion
,Formattable
,IDetachableEntity
,IDetachableEntityMixin
,IMentionable
,ISnowflake
,MessageChannel
,MessageChannelUnion
- All Known Subinterfaces:
GroupChannelMixin<T>
,GuildMessageChannelMixin<T>
,NewsChannelMixin<T>
,PrivateChannelMixin<T>
,StageChannelMixin<T>
,StandardGuildMessageChannelMixin<T>
,TextChannelMixin<T>
,ThreadChannelMixin<T>
,VoiceChannelMixin<T>
- All Known Implementing Classes:
AbstractStandardGuildMessageChannelImpl
,DetachedGroupChannelImpl
,DetachedNewsChannelImpl
,DetachedPrivateChannelImpl
,DetachedStageChannelImpl
,DetachedTextChannelImpl
,DetachedThreadChannelImpl
,DetachedVoiceChannelImpl
,NewsChannelImpl
,PrivateChannelImpl
,StageChannelImpl
,TextChannelImpl
,ThreadChannelImpl
,VoiceChannelImpl
-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.entities.channel.Channel
MAX_NAME_LENGTH
-
Method Summary
Modifier and TypeMethodDescriptiondefault RestAction
<Void> addReactionById
(String messageId, Emoji emoji) Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.default RestActionImpl
<Void> bulkDeleteMessages
(Collection<String> messageIds) boolean
void
void
void
void
void
void
void
default AuditableRestAction
<Void> deleteMessageById
(String messageId) Attempts to delete aMessage
from the Discord servers that has the same id as the id provided.default MessageEditAction
editMessageAttachmentsById
(String messageId, Collection<? extends AttachedFile> attachments) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageById
(String messageId, CharSequence newContent) Attempts to edit a message by its id in this channel.default MessageEditAction
editMessageById
(String messageId, MessageEditData data) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageComponentsById
(String messageId, Collection<? extends MessageTopLevelComponent> components) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageEmbedsById
(String messageId, Collection<? extends MessageEmbed> newEmbeds) Attempts to edit a message by its id in this MessageChannel.default MessageHistory
Creates a newMessageHistory
object for each call of this method.getHistoryAfter
(String messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent after the marker ID.getHistoryAround
(String messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent around the marker.getHistoryBefore
(String messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent before the marker ID.getHistoryFromBeginning
(int limit) Retrieves messages from the beginning of thisMessageChannel
.default MessagePaginationAction
APaginationAction
implementation that allows toiterate
over recentMessages
of this MessageChannel.default RestAction
<Void> pinMessageById
(String messageId) Used to pin a message.default List
<CompletableFuture<Void>> purgeMessages
(List<? extends Message> messages) Convenience method to delete messages in the most efficient way available.default List
<CompletableFuture<Void>> purgeMessagesById
(long... messageIds) Convenience method to delete messages in the most efficient way available.default RestAction
<Void> removeReactionById
(String messageId, Emoji emoji) Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.default RestAction
<Message> retrieveMessageById
(String messageId) Attempts to get aMessage
from the Discord's servers that has the same id as the id provided.default RestAction
<List<Message>> Retrieves a List ofMessages
that have been pinned in this channel.default ReactionPaginationAction
retrieveReactionUsersById
(String messageId, Emoji emoji) default MessageCreateAction
sendFiles
(Collection<? extends FileUpload> files) Send a message to this channel.default MessageCreateAction
sendMessage
(CharSequence text) Send a message to this channel.default MessageCreateAction
Send a message to this channel.default MessageCreateAction
sendMessageComponents
(Collection<? extends MessageTopLevelComponent> components) Send a message to this channel.default MessageCreateAction
sendMessageEmbeds
(Collection<? extends MessageEmbed> embeds) Send a message to this channel.default MessageCreateAction
sendMessageEmbeds
(MessageEmbed embed, MessageEmbed... other) Send a message to this channel.default MessageCreateAction
Send a message to this channel.default RestAction
<Void> Sends the typing status to discord.setLatestMessageIdLong
(long latestMessageId) default RestAction
<Void> unpinMessageById
(String messageId) Used to unpin a message.Methods inherited from interface net.dv8tion.jda.api.entities.channel.Channel
formatTo, getAsMention, getFlags, getJDA, getName, getType
Methods inherited from interface net.dv8tion.jda.internal.entities.channel.mixin.ChannelMixin
checkCanAccess, delete, setName
Methods inherited from interface net.dv8tion.jda.api.entities.channel.unions.ChannelUnion
asAudioChannel, asCategory, asForumChannel, asGroupChannel, asGuildChannel, asGuildMessageChannel, asMediaChannel, asMessageChannel, asNewsChannel, asPrivateChannel, asStageChannel, asStandardGuildChannel, asStandardGuildMessageChannel, asTextChannel, asThreadChannel, asThreadContainer, asVoiceChannel
Methods inherited from interface net.dv8tion.jda.api.entities.detached.IDetachableEntity
isDetached
Methods inherited from interface net.dv8tion.jda.internal.entities.detached.mixin.IDetachableEntityMixin
checkAttached, detachedException, detachedRequiresChannelException
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
Methods inherited from interface net.dv8tion.jda.api.entities.channel.middleman.MessageChannel
addReactionById, canTalk, deleteMessageById, editMessageAttachmentsById, editMessageAttachmentsById, editMessageAttachmentsById, editMessageById, editMessageById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageEmbedsById, editMessageEmbedsById, editMessageEmbedsById, editMessageFormatById, editMessageFormatById, endPollById, endPollById, getHistoryAfter, getHistoryAfter, getHistoryAround, getHistoryAround, getHistoryBefore, getHistoryBefore, getLatestMessageId, getLatestMessageIdLong, pinMessageById, purgeMessages, purgeMessagesById, purgeMessagesById, removeReactionById, retrieveMessageById, retrievePollVotersById, retrievePollVotersById, retrieveReactionUsersById, retrieveReactionUsersById, retrieveReactionUsersById, sendFiles, sendMessageComponents, sendMessageComponents, sendMessageFormat, unpinMessageById
Methods inherited from interface net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion
asAudioChannel, asGroupChannel, asGuildMessageChannel, asNewsChannel, asPrivateChannel, asStageChannel, asTextChannel, asThreadChannel, asThreadContainer, asVoiceChannel
-
Method Details
-
purgeMessages
@Nonnull default List<CompletableFuture<Void>> purgeMessages(@Nonnull List<? extends Message> messages) Description copied from interface:MessageChannel
Convenience method to delete messages in the most efficient way available.
This combines bothGuildMessageChannel.deleteMessagesByIds(Collection)
as well asMessage.delete()
to delete all messages provided. No checks will be done to prevent failures, useCompletionStage.exceptionally(Function)
to handle failures.Any messages that cannot be deleted, as suggested by
MessageType.canDelete()
, will be filtered out before making any requests.For possible ErrorResponses see
MessageChannel.purgeMessagesById(long...)
.- Specified by:
purgeMessages
in interfaceMessageChannel
- Parameters:
messages
- The messages to delete- Returns:
- List of futures representing all deletion tasks
- See Also:
-
purgeMessagesById
Description copied from interface:MessageChannel
Convenience method to delete messages in the most efficient way available.
This combines bothGuildMessageChannel.deleteMessagesByIds(Collection)
as well asMessageChannel.deleteMessageById(long)
to delete all messages provided. No checks will be done to prevent failures, useCompletionStage.exceptionally(Function)
to handle failures.Possible ErrorResponses include:
UNKNOWN_CHANNEL
if this channel was deletedUNKNOWN_MESSAGE
if any of the provided messages does not existMISSING_ACCESS
if we were removed from the channelMISSING_PERMISSIONS
The send request was attempted after the account lostPermission.MESSAGE_MANAGE
in the channel.
- Specified by:
purgeMessagesById
in interfaceMessageChannel
- Parameters:
messageIds
- The message ids to delete- Returns:
- List of futures representing all deletion tasks
- See Also:
-
sendMessage
Description copied from interface:MessageChannel
Send a message to this channel.Possible
ErrorResponses
include:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Specified by:
sendMessage
in interfaceMessageChannel
- Parameters:
text
- The message content- Returns:
MessageCreateAction
-
sendMessageEmbeds
@Nonnull @CheckReturnValue default MessageCreateAction sendMessageEmbeds(@Nonnull MessageEmbed embed, @Nonnull MessageEmbed... other) Description copied from interface:MessageChannel
Send a message to this channel.Possible
ErrorResponses
include:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
Example: Attachment Images
// Make a file upload instance which refers to a local file called "myFile.png" // The second parameter "image.png" is the filename we tell discord to use for the attachment FileUpload file = FileUpload.fromData(new File("myFile.png"), "image.png"); // Build a message embed which refers to this attachment by the given name. // Note that this must be the same name as configured for the attachment, not your local filename. MessageEmbed embed = new EmbedBuilder() .setDescription("This is my cute cat :)") .setImage("attachment://image.png") // refer to the file by using the "attachment://" schema with the filename we gave it above .build(); channel.sendMessageEmbeds(embed) // send the embed .addFiles(file) // add the file as attachment .queue();
- Specified by:
sendMessageEmbeds
in interfaceMessageChannel
- Parameters:
embed
-MessageEmbed
to sendother
- AdditionalMessageEmbeds
to use (up to 10)- Returns:
MessageCreateAction
-
sendMessageEmbeds
@Nonnull @CheckReturnValue default MessageCreateAction sendMessageEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Description copied from interface:MessageChannel
Send a message to this channel.Possible
ErrorResponses
include:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
Example: Attachment Images
// Make a file upload instance which refers to a local file called "myFile.png" // The second parameter "image.png" is the filename we tell discord to use for the attachment FileUpload file = FileUpload.fromData(new File("myFile.png"), "image.png"); // Build a message embed which refers to this attachment by the given name. // Note that this must be the same name as configured for the attachment, not your local filename. MessageEmbed embed = new EmbedBuilder() .setDescription("This is my cute cat :)") .setImage("attachment://image.png") // refer to the file by using the "attachment://" schema with the filename we gave it above .build(); channel.sendMessageEmbeds(Collections.singleton(embed)) // send the embeds .addFiles(file) // add the file as attachment .queue();
- Specified by:
sendMessageEmbeds
in interfaceMessageChannel
- Parameters:
embeds
-MessageEmbeds
to use (up to 10)- Returns:
MessageCreateAction
-
sendMessageComponents
@Nonnull default MessageCreateAction sendMessageComponents(@Nonnull Collection<? extends MessageTopLevelComponent> components) Description copied from interface:MessageChannel
Send a message to this channel.Possible
ErrorResponses
include:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Specified by:
sendMessageComponents
in interfaceMessageChannel
- Parameters:
components
- TheMessageTopLevelComponents
to send, can contain up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).- Returns:
MessageCreateAction
-
sendMessagePoll
Description copied from interface:MessageChannel
Send a message to this channel.Possible
ErrorResponses
include:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filterPOLL_INVALID_CHANNEL_TYPE
This channel does not allow pollsPOLL_WITH_UNUSABLE_EMOJI
This poll uses an external emoji that the bot is not allowed to use
- Specified by:
sendMessagePoll
in interfaceMessageChannel
- Parameters:
poll
- The poll to send- Returns:
MessageCreateAction
-
sendMessage
Description copied from interface:MessageChannel
Send a message to this channel.Possible
ErrorResponses
include:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Specified by:
sendMessage
in interfaceMessageChannel
- Parameters:
msg
- TheMessageCreateData
to send- Returns:
MessageCreateAction
- See Also:
-
sendFiles
@Nonnull @CheckReturnValue default MessageCreateAction sendFiles(@Nonnull Collection<? extends FileUpload> files) Description copied from interface:MessageChannel
Send a message to this channel.Resource Handling Note: Once the request is handed off to the requester, for example when you call
RestAction.queue()
, the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after usingFileUpload.fromData(File)
, before callingRestAction.queue()
. You can safely use a try-with-resources to handle this, sinceFileUpload.close()
becomes ineffective once the request is handed off.Possible
ErrorResponses
include:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filterREQUEST_ENTITY_TOO_LARGE
If the total sum of uploaded bytes exceeds the guild'supload limit
Example: Attachment Images
// Make a file upload instance which refers to a local file called "myFile.png" // The second parameter "image.png" is the filename we tell discord to use for the attachment FileUpload file = FileUpload.fromData(new File("myFile.png"), "image.png"); // Build a message embed which refers to this attachment by the given name. // Note that this must be the same name as configured for the attachment, not your local filename. MessageEmbed embed = new EmbedBuilder() .setDescription("This is my cute cat :)") .setImage("attachment://image.png") // refer to the file by using the "attachment://" schema with the filename we gave it above .build(); channel.sendFiles(Collections.singleton(file)) // send the file upload .addEmbeds(embed) // add the embed you want to reference the file with .queue();
- Specified by:
sendFiles
in interfaceMessageChannel
- Parameters:
files
- TheFileUploads
to attach to the message- Returns:
MessageCreateAction
- See Also:
-
retrieveMessageById
@Nonnull @CheckReturnValue default RestAction<Message> retrieveMessageById(@Nonnull String messageId) Description copied from interface:MessageChannel
Attempts to get aMessage
from the Discord's servers that has the same id as the id provided.
Note: when retrieving a Message, you must retrieve it from the channel it was sent in!The
Message.getMember()
method will always return null for the resulting message. To retrieve the member you can usegetGuild().retrieveMember(message.getAuthor())
.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theGuildMessageChannel
.UNKNOWN_MESSAGE
The providedid
does not refer to a message sent in this channel or the message has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
retrieveMessageById
in interfaceMessageChannel
- Parameters:
messageId
- The id of the sought after Message- Returns:
RestAction
- Type: Message
The Message defined by the provided id.
-
deleteMessageById
@Nonnull @CheckReturnValue default AuditableRestAction<Void> deleteMessageById(@Nonnull String messageId) Description copied from interface:MessageChannel
Attempts to delete aMessage
from the Discord servers that has the same id as the id provided.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request attempted to delete a Message in aGuildMessageChannel
that was not sent by the currently logged in account.INVALID_DM_ACTION
Attempted to delete a Message in aPrivateChannel
that was not sent by the currently logged in account.UNKNOWN_MESSAGE
The providedid
does not refer to a message sent in this channel or the message has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
deleteMessageById
in interfaceMessageChannel
- Parameters:
messageId
- The id of the Message that should be deleted- Returns:
RestAction
- Type: Void
-
getHistory
Description copied from interface:MessageChannel
Creates a newMessageHistory
object for each call of this method.
MessageHistory is NOT an internal message cache, but rather it queries the Discord servers for previously sent messages.- Specified by:
getHistory
in interfaceMessageChannel
- Returns:
- A
MessageHistory
related to this channel.
-
getIterableHistory
Description copied from interface:MessageChannel
APaginationAction
implementation that allows toiterate
over recentMessages
of this MessageChannel.
This is not a cache for received messages and it can only view messages that were sent before. This iterates chronologically backwards (from present to past).It is recommended not to use this in an enhanced for-loop without end conditions as it might cause memory overflows in channels with a long message history.
Examples
public CompletableFuture<List<Message>> getMessagesByUser(MessageChannel channel, User user) { return channel.getIterableHistory() .takeAsync(1000) // Collect 1000 messages .thenApply(list -> list.stream() .filter(m -> m.getAuthor().equals(user)) // Filter messages by author .collect(Collectors.toList()) ); }
- Specified by:
getIterableHistory
in interfaceMessageChannel
- Returns:
MessagePaginationAction
-
getHistoryAround
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAround(@Nonnull String messageId, int limit) Description copied from interface:MessageChannel
Uses the providedid
of a message as a marker and retrieves messages sent around the marker. Thelimit
determines the amount of messages retrieved near the marker. Discord will attempt to evenly split the limit between before and after the marker, however in the case that the marker is set near the beginning or near the end of the channel's history the amount of messages on each side of the marker may be different, and their total count may not equal the providedlimit
.Examples:
Retrieve 100 messages from the middle of history. >100 message exist in history and the marker is >50 messages from the edge of history.getHistoryAround(messageId, 100)
- This will retrieve 100 messages from history, 50 before the marker and 50 after the marker.Retrieve 10 messages near the end of history. Provided id is for a message that is the 3rd most recent message.
getHistoryAround(messageId, 10)
- This will retrieve 10 messages from history, 8 before the marker and 2 after the marker.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theGuildMessageChannel
.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted, thus could not be used as a marker.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
getHistoryAround
in interfaceMessageChannel
- Parameters:
messageId
- The id of the message that will act as a marker.limit
- The amount of messages to be retrieved around the marker. Minimum: 1, Max: 100.- Returns:
MessageHistory.MessageRetrieveAction
Provides aMessageHistory
object with messages around the provided message loaded into it.- See Also:
-
getHistoryAfter
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAfter(@Nonnull String messageId, int limit) Description copied from interface:MessageChannel
Uses the providedid
of a message as a marker and retrieves messages sent after the marker ID. Thelimit
determines the amount of messages retrieved near the marker.Examples:
Retrieve 100 messages from the middle of history. >100 message exist in history and the marker is >50 messages from the edge of history.getHistoryAfter(messageId, 100)
- This will retrieve 100 messages from history sent after the marker.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theGuildMessageChannel
.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted, thus could not be used as a marker.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
getHistoryAfter
in interfaceMessageChannel
- Parameters:
messageId
- The id of the message that will act as a marker.limit
- The amount of messages to be retrieved after the marker. Minimum: 1, Max: 100.- Returns:
MessageHistory.MessageRetrieveAction
Provides aMessageHistory
object with messages after the provided message loaded into it.- See Also:
-
getHistoryBefore
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryBefore(@Nonnull String messageId, int limit) Description copied from interface:MessageChannel
Uses the providedid
of a message as a marker and retrieves messages sent before the marker ID. Thelimit
determines the amount of messages retrieved near the marker.Examples:
Retrieve 100 messages from the middle of history. >100 message exist in history and the marker is >50 messages from the edge of history.getHistoryBefore(messageId, 100)
- This will retrieve 100 messages from history sent before the marker.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theGuildMessageChannel
.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted, thus could not be used as a marker.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
getHistoryBefore
in interfaceMessageChannel
- Parameters:
messageId
- The id of the message that will act as a marker.limit
- The amount of messages to be retrieved after the marker. Minimum: 1, Max: 100.- Returns:
MessageHistory.MessageRetrieveAction
Provides aMessageHistory
object with messages before the provided message loaded into it.- See Also:
-
getHistoryFromBeginning
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryFromBeginning(int limit) Description copied from interface:MessageChannel
Retrieves messages from the beginning of thisMessageChannel
. Thelimit
determines the amount of messages being retrieved.Example
public void resendFirstMessage(MessageChannel channel) { channel.getHistoryFromBeginning(1).queue(history -> { if (!history.isEmpty()) { Message firstMsg = history.getRetrievedHistory().get(0); channel.sendMessage(firstMsg).queue(); } else channel.sendMessage("No history for this channel!").queue(); }); }
The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theGuildMessageChannel
.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
getHistoryFromBeginning
in interfaceMessageChannel
- Parameters:
limit
- The amount of messages to be retrieved. Minimum: 1, Max: 100.- Returns:
MessageHistory.MessageRetrieveAction
Provides aMessageHistory
object with with the first messages of this channel loaded into it.
Note: The messages are ordered from the most recent to oldest!- See Also:
-
sendTyping
Description copied from interface:MessageChannel
Sends the typing status to discord. This is what is used to make the message "X is typing..." appear.
The typing status only lasts for 10 seconds or until a message is sent.
So if you wish to show continuous typing you will need to call this method once every 10 seconds.The official discord client sends this every 5 seconds even though the typing status lasts 10.
The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
was revoked in theGuildMessageChannel
UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
sendTyping
in interfaceMessageChannel
- Returns:
RestAction
- Type: Void
-
addReactionById
@Nonnull @CheckReturnValue default RestAction<Void> addReactionById(@Nonnull String messageId, @Nonnull Emoji emoji) Description copied from interface:MessageChannel
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theGuildMessageChannel
.UNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
addReactionById
in interfaceMessageChannel
- Parameters:
messageId
- The messageId to attach the reaction toemoji
- The not-nullEmoji
to react with- Returns:
RestAction
-
removeReactionById
@Nonnull @CheckReturnValue default RestAction<Void> removeReactionById(@Nonnull String messageId, @Nonnull Emoji emoji) Description copied from interface:MessageChannel
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theGuildMessageChannel
.UNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
removeReactionById
in interfaceMessageChannel
- Parameters:
messageId
- The messageId to remove the reaction fromemoji
- The emoji to remove- Returns:
RestAction
-
retrieveReactionUsersById
@Nonnull @CheckReturnValue default ReactionPaginationAction retrieveReactionUsersById(@Nonnull String messageId, @Nonnull Emoji emoji) Description copied from interface:MessageChannel
This obtains theusers
who reacted to a message using the givenEmoji
.
By default, this only includes users that reacted withMessageReaction.ReactionType.NORMAL
. UseretrieveReactionUsersById(messageId, emoji, ReactionType.SUPER)
to retrieve the users that used a super reaction instead.Messages maintain a list of reactions, alongside a list of users who added them.
Using this data, we can obtain a
ReactionPaginationAction
of the users who've reacted to the given message.The following
ErrorResponses
are possible:MISSING_ACCESS
The retrieve request was attempted after the account lost access to theGuildMessageChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.
- Specified by:
retrieveReactionUsersById
in interfaceMessageChannel
- Parameters:
messageId
- The messageId to retrieve the users from.emoji
- TheEmoji
to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emoji's users.
-
pinMessageById
Description copied from interface:MessageChannel
Used to pin a message. Pinned messages are retrievable viaMessageChannel.retrievePinnedMessages()
.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildMessageChannel
.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
pinMessageById
in interfaceMessageChannel
- Parameters:
messageId
- The message to pin.- Returns:
RestAction
-
unpinMessageById
Description copied from interface:MessageChannel
Used to unpin a message. Pinned messages are retrievable viaMessageChannel.retrievePinnedMessages()
.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildMessageChannel
.UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
unpinMessageById
in interfaceMessageChannel
- Parameters:
messageId
- The message to unpin.- Returns:
RestAction
-
retrievePinnedMessages
Description copied from interface:MessageChannel
Retrieves a List ofMessages
that have been pinned in this channel.
If no messages have been pinned, this retrieves an empty List.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
retrievePinnedMessages
in interfaceMessageChannel
- Returns:
RestAction
- Type: List<Message
>
Retrieves an immutable list of pinned messages
-
editMessageById
@Nonnull @CheckReturnValue default MessageEditAction editMessageById(@Nonnull String messageId, @Nonnull CharSequence newContent) Description copied from interface:MessageChannel
Attempts to edit a message by its id in this channel.The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
Attempted to edit a message that was not sent by the currently logged in account. Discord does not allow editing of other users' Messages!MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageById
in interfaceMessageChannel
- Parameters:
messageId
- The id referencing the Message that should be editednewContent
- The new content for the edited message- Returns:
MessageEditAction
-
editMessageById
@Nonnull @CheckReturnValue default MessageEditAction editMessageById(@Nonnull String messageId, @Nonnull MessageEditData data) Description copied from interface:MessageChannel
Attempts to edit a message by its id in this MessageChannel.The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
Attempted to edit a message that was not sent by the currently logged in account. Discord does not allow editing of other users' Messages!MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageById
in interfaceMessageChannel
- Parameters:
messageId
- The id referencing the Message that should be editeddata
- The new content for the edited message- Returns:
MessageEditAction
-
editMessageEmbedsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageEmbedsById(@Nonnull String messageId, @Nonnull Collection<? extends MessageEmbed> newEmbeds) Description copied from interface:MessageChannel
Attempts to edit a message by its id in this MessageChannel.The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
Attempted to edit a message that was not sent by the currently logged in account. Discord does not allow editing of other users' Messages!MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageEmbedsById
in interfaceMessageChannel
- Parameters:
messageId
- The id referencing the Message that should be editednewEmbeds
- Up to 10 newMessageEmbeds
for the edited message- Returns:
MessageEditAction
-
editMessageComponentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageComponentsById(@Nonnull String messageId, @Nonnull Collection<? extends MessageTopLevelComponent> components) Description copied from interface:MessageChannel
Attempts to edit a message by its id in this MessageChannel.
This will replace all the currentComponents
, such asButtons
orSelectMenus
on this message. The provided parameters areMessageTopLevelComponents
such asActionRow
which contain a list of components to arrange in the respective layout.Example
List<ActionRow> rows = Arrays.asList( ActionRow.of(Button.success("prompt:accept", "Accept"), Button.danger("prompt:reject", "Reject")), // 1st row below message ActionRow.of(Button.link(url, "Help")) // 2nd row below message ); channel.editMessageComponentsById(messageId, rows).queue();
The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
Attempted to edit a message that was not sent by the currently logged in account. Discord does not allow editing of other users' Messages!MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted. This might also be triggered for ephemeral messages.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageComponentsById
in interfaceMessageChannel
- Parameters:
messageId
- The id referencing the Message that should be editedcomponents
- TheMessageTopLevelComponents
to set, can be empty to remove components, can contain up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).- Returns:
MessageEditAction
-
editMessageAttachmentsById
@Nonnull default MessageEditAction editMessageAttachmentsById(@Nonnull String messageId, @Nonnull Collection<? extends AttachedFile> attachments) Description copied from interface:MessageChannel
Attempts to edit a message by its id in this MessageChannel.The following
ErrorResponses
are possible:REQUEST_ENTITY_TOO_LARGE
If any of the provided files is bigger thanGuild.getMaxFileSize()
INVALID_AUTHOR_EDIT
Attempted to edit a message that was not sent by the currently logged in account. Discord does not allow editing of other users' Messages!MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted. This might also be triggered for ephemeral messages.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
Resource Handling Note: Once the request is handed off to the requester, for example when you call
RestAction.queue()
, the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after usingFileUpload.fromData(File)
, before callingRestAction.queue()
. You can safely use a try-with-resources to handle this, sinceFileUpload.close()
becomes ineffective once the request is handed off.- Specified by:
editMessageAttachmentsById
in interfaceMessageChannel
- Parameters:
messageId
- The message id. For interactions this supports"@original"
to edit the source message of the interaction.attachments
- The new attachments of the message (Can beFileUploads
orAttachmentUpdates
)- Returns:
MessageEditAction
that can be used to further update the message- See Also:
-
setLatestMessageIdLong
-
checkCanSendMessage
void checkCanSendMessage() -
checkCanSendMessageEmbeds
void checkCanSendMessageEmbeds() -
checkCanSendFiles
void checkCanSendFiles() -
checkCanViewHistory
void checkCanViewHistory() -
checkCanAddReactions
void checkCanAddReactions() -
checkCanRemoveReactions
void checkCanRemoveReactions() -
checkCanControlMessagePins
void checkCanControlMessagePins() -
canDeleteOtherUsersMessages
boolean canDeleteOtherUsersMessages() -
bulkDeleteMessages
-