Interface MessageChannel
- All Superinterfaces:
Channel
,Formattable
,IMentionable
,ISnowflake
- All Known Subinterfaces:
GroupChannel
,GuildMessageChannel
,GuildMessageChannelUnion
,MessageChannelUnion
,NewsChannel
,PrivateChannel
,StageChannel
,StandardGuildMessageChannel
,TextChannel
,ThreadChannel
,VoiceChannel
Messages
and files sent to it.
Formattable
This interface extends Formattable
and can be used with a Formatter
such as used by String.format(String, Object...)
or PrintStream.printf(String, Object...)
.
This will use Channel.getName()
rather than Object.toString()
!
Supported Features:
- Alternative
- Prepends the name with#
(Example:%#s
- results in#
)Channel.getName()
- Width/Left-Justification
- Ensures the size of a format (Example:%20s
- uses at minimum 20 chars;%-10s
- uses left-justified padding) - Precision
- Cuts the content to the specified size (Example:%.20s
)
More information on formatting syntax can be found in the format syntax documentation
!
GuildMessageChannel
is a special case which uses IMentionable.getAsMention()
by default and uses the #
format as alternativeChannel.getName()
- See Also:
-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.entities.channel.Channel
MAX_NAME_LENGTH
-
Method Summary
Modifier and TypeMethodDescriptiondefault RestAction
<Void> addReactionById
(long messageId, Emoji emoji) Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.default RestAction
<Void> addReactionById
(String messageId, Emoji emoji) Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.boolean
canTalk()
Whether the currently logged in user can send messages in this channel or not.default AuditableRestAction
<Void> deleteMessageById
(long messageId) Attempts to delete aMessage
from the Discord servers that has the same id as the id provided.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
(long messageId, Collection<? extends AttachedFile> attachments) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageAttachmentsById
(long messageId, AttachedFile... attachments) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageAttachmentsById
(String messageId, Collection<? extends AttachedFile> attachments) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageAttachmentsById
(String messageId, AttachedFile... attachments) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageById
(long messageId, CharSequence newContent) Attempts to edit a message by its id in this channel.default MessageEditAction
editMessageById
(long messageId, MessageEditData data) 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
(long messageId, Collection<? extends LayoutComponent> components) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageComponentsById
(long messageId, LayoutComponent... components) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageComponentsById
(String messageId, Collection<? extends LayoutComponent> components) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageComponentsById
(String messageId, LayoutComponent... components) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageEmbedsById
(long messageId, Collection<? extends MessageEmbed> newEmbeds) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageEmbedsById
(long messageId, MessageEmbed... newEmbeds) 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 MessageEditAction
editMessageEmbedsById
(String messageId, MessageEmbed... newEmbeds) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageFormatById
(long messageId, String format, Object... args) Attempts to edit a message by its id in this MessageChannel.default MessageEditAction
editMessageFormatById
(String messageId, String format, Object... args) Attempts to edit a message by its id in this MessageChannel.default AuditableRestAction
<Message> endPollById
(long messageId) End the poll attached to this message.default AuditableRestAction
<Message> endPollById
(String messageId) End the poll attached to this message.default MessageHistory
Creates a newMessageHistory
object for each call of this method.getHistoryAfter
(long messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent after the marker ID.getHistoryAfter
(String messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent after the marker ID.getHistoryAfter
(Message message, int limit) Uses the provided message as a marker and retrieves messages sent after the marker.getHistoryAround
(long messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages around the marker.getHistoryAround
(String messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent around the marker.getHistoryAround
(Message message, int limit) Uses the providedMessage
as a marker and retrieves messages around the marker.getHistoryBefore
(long messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent before the marker ID.getHistoryBefore
(String messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages sent before the marker ID.getHistoryBefore
(Message message, int limit) Uses the provided message as a marker and retrieves messages sent before the marker.getHistoryFromBeginning
(int limit) Retrieves messages from the beginning of thisMessageChannel
.default MessagePaginationAction
APaginationAction
implementation that allows toiterate
over recentMessages
of this MessageChannel.default String
The id for the most recent message sent in this current MessageChannel.long
The id for the most recent message sent in this current MessageChannel.default RestAction
<Void> pinMessageById
(long messageId) Used to pin a message.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>> purgeMessages
(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 List
<CompletableFuture<Void>> purgeMessagesById
(String... messageIds) Convenience method to delete messages in the most efficient way available.default List
<CompletableFuture<Void>> purgeMessagesById
(List<String> messageIds) Convenience method to delete messages in the most efficient way available.default RestAction
<Void> removeReactionById
(long messageId, Emoji emoji) Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.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
(long messageId) Attempts to get aMessage
from the Discord's servers that has the same id as the id provided.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
<@Unmodifiable List<Message>> Retrieves a List ofMessages
that have been pinned in this channel.default PollVotersPaginationAction
retrievePollVotersById
(long messageId, long answerId) Paginate the users who voted for a poll answer.default PollVotersPaginationAction
retrievePollVotersById
(String messageId, long answerId) Paginate the users who voted for a poll answer.default ReactionPaginationAction
retrieveReactionUsersById
(long messageId, Emoji emoji) default ReactionPaginationAction
retrieveReactionUsersById
(String messageId, Emoji emoji) default MessageCreateAction
sendFiles
(Collection<? extends FileUpload> files) Send a message to this channel.default MessageCreateAction
sendFiles
(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 LayoutComponent> components) Send a message to this channel.default MessageCreateAction
sendMessageComponents
(LayoutComponent component, LayoutComponent... other) 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
sendMessageFormat
(String format, Object... args) Send a message to this channel.default MessageCreateAction
Send a message to this channel.default RestAction
<Void> Sends the typing status to discord.default RestAction
<Void> unpinMessageById
(long messageId) Used to unpin a message.default RestAction
<Void> unpinMessageById
(String messageId) Used to unpin a message.Methods inherited from interface net.dv8tion.jda.api.entities.channel.Channel
delete, formatTo, getAsMention, getFlags, getJDA, getName, getType
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
Method Details
-
getLatestMessageId
The id for the most recent message sent in this current MessageChannel.This value is updated on each
MessageReceivedEvent
and the value might point to an already deleted message since the ID is not cleared when the message is deleted, so callingretrieveMessageById(long)
with this id can result in anUNKNOWN_MESSAGE
error- Returns:
- The most recent message's id or "0" if no messages are present
-
getLatestMessageIdLong
long getLatestMessageIdLong()The id for the most recent message sent in this current MessageChannel.This value is updated on each
MessageReceivedEvent
and the value might point to an already deleted message since the value is not cleared when the message is deleted, so callingretrieveMessageById(long)
with this id can result in anUNKNOWN_MESSAGE
error- Returns:
- The most recent message's id or 0 if no messages are present
-
canTalk
boolean canTalk()Whether the currently logged in user can send messages in this channel or not.
ForGuildMessageChannel
this method checks for bothPermission.VIEW_CHANNEL
andPermission.MESSAGE_SEND
.
ForThreadChannel
this method checks forPermission.MESSAGE_SEND_IN_THREADS
instead ofPermission.MESSAGE_SEND
.
ForPrivateChannel
this method checks if the user that this PrivateChannel communicates with is not a bot, but it does not check if the said user blocked the currently logged in user or have their DMs disabled.- Returns:
- True, if we are able to read and send messages in this channel
-
purgeMessagesById
Convenience method to delete messages in the most efficient way available.
This combines bothGuildMessageChannel.deleteMessagesByIds(Collection)
as well asdeleteMessageById(long)
to delete all messages provided. No checks will be done to prevent failures, useCompletionStage.exceptionally(Function)
to handle failures.For possible ErrorResponses see
purgeMessagesById(long...)
.- Parameters:
messageIds
- The message ids to delete- Returns:
- List of futures representing all deletion tasks
- See Also:
-
purgeMessagesById
Convenience method to delete messages in the most efficient way available.
This combines bothGuildMessageChannel.deleteMessagesByIds(Collection)
as well asdeleteMessageById(long)
to delete all messages provided. No checks will be done to prevent failures, useCompletionStage.exceptionally(Function)
to handle failures.For possible ErrorResponses see
purgeMessagesById(long...)
.- Parameters:
messageIds
- The message ids to delete- Returns:
- List of futures representing all deletion tasks
- See Also:
-
purgeMessages
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.For possible ErrorResponses see
purgeMessagesById(long...)
.- Parameters:
messages
- The messages to delete- Returns:
- List of futures representing all deletion tasks
- Throws:
InsufficientPermissionException
- If one of the provided messages is from another user and cannot be deleted due to permissionsIllegalArgumentException
- If one of the provided messages is from another user and cannot be deleted because this is not in a guild- See Also:
-
purgeMessages
@Nonnull default List<CompletableFuture<Void>> purgeMessages(@Nonnull List<? extends Message> messages) 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
purgeMessagesById(long...)
.- Parameters:
messages
- The messages to delete- Returns:
- List of futures representing all deletion tasks
- Throws:
InsufficientPermissionException
- If one of the provided messages is from another user and cannot be deleted due to permissionsIllegalArgumentException
- If one of the provided messages is from another user and cannot be deleted because this is not in a guild- See Also:
-
purgeMessagesById
Convenience method to delete messages in the most efficient way available.
This combines bothGuildMessageChannel.deleteMessagesByIds(Collection)
as well asdeleteMessageById(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.
- Parameters:
messageIds
- The message ids to delete- Returns:
- List of futures representing all deletion tasks
- See Also:
-
sendMessage
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
- Parameters:
text
- The message content- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If the content is null or longer than 2000 charactersInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
sendMessage
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
- Parameters:
msg
- TheMessageCreateData
to send- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If null is providedInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
- See Also:
-
sendMessageFormat
@Nonnull @CheckReturnValue default MessageCreateAction sendMessageFormat(@Nonnull String format, @Nonnull Object... args) 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
- Parameters:
format
- Format string for the message contentargs
- Format arguments for the content- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If the format string is null or the resulting content is longer than 2000 charactersInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
IllegalFormatException
- If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
-
sendMessageEmbeds
@Nonnull @CheckReturnValue default MessageCreateAction sendMessageEmbeds(@Nonnull MessageEmbed embed, @Nonnull MessageEmbed... other) 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();
- Parameters:
embed
-MessageEmbed
to sendother
- AdditionalMessageEmbeds
to use (up to 10)- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If any of the embeds are null, more than 10, or longer thanMessageEmbed.EMBED_MAX_LENGTH_BOT
.InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
sendMessageEmbeds
@Nonnull @CheckReturnValue default MessageCreateAction sendMessageEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) 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();
- Parameters:
embeds
-MessageEmbeds
to use (up to 10)- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If any of the embeds are null, more than 10, or longer thanMessageEmbed.EMBED_MAX_LENGTH_BOT
.InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
sendMessageComponents
@Nonnull @CheckReturnValue default MessageCreateAction sendMessageComponents(@Nonnull LayoutComponent component, @Nonnull LayoutComponent... other) 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
- Parameters:
component
-LayoutComponent
to sendother
- AdditionalLayoutComponents
to use (up to 5)- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If any of the components is null or more than 5 component layouts are providedInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
sendMessageComponents
@Nonnull @CheckReturnValue default MessageCreateAction sendMessageComponents(@Nonnull Collection<? extends LayoutComponent> components) 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();
- Parameters:
components
-LayoutComponents
to use (up to 5)- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If any of the components is null or more than 5 component layouts are providedInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
sendMessagePoll
@Nonnull @CheckReturnValue default MessageCreateAction sendMessagePoll(@Nonnull MessagePollData poll) 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
- Parameters:
poll
- The poll to send- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If the poll is nullInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
sendFiles
@Nonnull @CheckReturnValue default MessageCreateAction sendFiles(@Nonnull Collection<? extends FileUpload> files) 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();
- Parameters:
files
- TheFileUploads
to attach to the message- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If null is providedInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
- See Also:
-
sendFiles
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(file) // send the file upload .addEmbeds(embed) // add the embed you want to reference the file with .queue();
- Parameters:
files
- TheFileUploads
to attach to the message- Returns:
MessageCreateAction
- Throws:
UnsupportedOperationException
- If this is aPrivateChannel
and the recipient is a botIllegalArgumentException
- If null is providedInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
- See Also:
-
retrieveMessageById
@Nonnull @CheckReturnValue default RestAction<Message> retrieveMessageById(@Nonnull String messageId) 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.
- Parameters:
messageId
- The id of the sought after Message- Returns:
RestAction
- Type: Message
The Message defined by the provided id.- Throws:
IllegalArgumentException
- if the providedmessageId
is null or empty.InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have
-
retrieveMessageById
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.
- Parameters:
messageId
- The id of the sought after Message- Returns:
RestAction
- Type: Message
The Message defined by the provided id.- Throws:
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have
-
deleteMessageById
@Nonnull @CheckReturnValue default AuditableRestAction<Void> deleteMessageById(@Nonnull String messageId) 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.
- Parameters:
messageId
- The id of the Message that should be deleted- Returns:
RestAction
- Type: Void- Throws:
IllegalArgumentException
- if the provided messageId is nullInsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not havePermission.VIEW_CHANNEL
.
-
deleteMessageById
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.
- Parameters:
messageId
- The id of the Message that should be deleted- Returns:
RestAction
- Type: Void- Throws:
IllegalArgumentException
- if the provided messageId is not positiveInsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not havePermission.VIEW_CHANNEL
.
-
endPollById
@Nonnull @CheckReturnValue default AuditableRestAction<Message> endPollById(@Nonnull String messageId) End the poll attached to this message.A bot cannot expire the polls of other users.
The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
If the poll was sent by another userCANNOT_EXPIRE_MISSING_POLL
The message did not have a poll attachedUNKNOWN_MESSAGE
The message no longer exists
- Parameters:
messageId
- The ID for the poll message- Returns:
AuditableRestAction
- Type:Message
- Throws:
IllegalArgumentException
- If the provided messageId is not a valid snowflake
-
endPollById
End the poll attached to this message.A bot cannot expire the polls of other users.
The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
If the poll was sent by another userCANNOT_EXPIRE_MISSING_POLL
The message did not have a poll attachedUNKNOWN_MESSAGE
The message no longer exists
- Parameters:
messageId
- The ID for the poll message- Returns:
AuditableRestAction
- Type:Message
-
retrievePollVotersById
@Nonnull @CheckReturnValue default PollVotersPaginationAction retrievePollVotersById(@Nonnull String messageId, long answerId) Paginate the users who voted for a poll answer.- Parameters:
messageId
- The message id for the pollanswerId
- The id of the poll answer, usually the ordinal position of the answer (first is 1)- Returns:
PollVotersPaginationAction
- Throws:
IllegalArgumentException
- If the message id is not a valid snowflake
-
retrievePollVotersById
@Nonnull @CheckReturnValue default PollVotersPaginationAction retrievePollVotersById(long messageId, long answerId) Paginate the users who voted for a poll answer.- Parameters:
messageId
- The message id for the pollanswerId
- The id of the poll answer, usually the ordinal position of the answer (first is 1)- Returns:
PollVotersPaginationAction
-
getHistory
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.- Returns:
- A
MessageHistory
related to this channel. - Throws:
InsufficientPermissionException
- If this is aGuildMessageChannel
and the currently logged in account does not have the permissionMESSAGE_HISTORY
-
getIterableHistory
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()) ); }
- Returns:
MessagePaginationAction
- Throws:
InsufficientPermissionException
- If this is aGuildMessageChannel
and the currently logged in account does not have the permissionMESSAGE_HISTORY
-
getHistoryAround
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAround(@Nonnull String messageId, int limit) 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.
- 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.- Throws:
IllegalArgumentException
-- Provided
messageId
isnull
or empty. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryAround
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAround(long messageId, int limit) Uses the providedid
of a message as a marker and retrieves messages 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.
- Parameters:
messageId
- The id of the message that will act as a marker. The id must refer to a message from this MessageChannel.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.- Throws:
IllegalArgumentException
-- Provided
messageId
is not positive. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryAround
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAround(@Nonnull Message message, int limit) Uses the providedMessage
as a marker and retrieves messages 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(message, 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 message is the 3rd most recent message.
getHistoryAround(message, 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 providedmessage
has already been deleted, thus could not be used as a marker.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Parameters:
message
- TheMessage
that will act as a marker. The provided Message must be from this MessageChannel.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.- Throws:
IllegalArgumentException
-- Provided
message
isnull
. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryAfter
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAfter(@Nonnull String messageId, int limit) 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.
- 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.- Throws:
IllegalArgumentException
-- Provided
messageId
isnull
or empty. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryAfter
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAfter(long messageId, int limit) 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.
- 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.- Throws:
IllegalArgumentException
- Providedlimit
is less than1
or greater than100
.InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryAfter
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryAfter(@Nonnull Message message, int limit) Uses the provided message as a marker and retrieves messages sent after the marker. 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(message, 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.
- Parameters:
message
- 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.- Throws:
IllegalArgumentException
-- Provided
message
isnull
. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryBefore
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryBefore(@Nonnull String messageId, int limit) 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.
- 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.- Throws:
IllegalArgumentException
-- Provided
messageId
isnull
or empty. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryBefore
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryBefore(long messageId, int limit) 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.
- 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.- Throws:
IllegalArgumentException
-- Provided
messageId
isnull
or empty. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryBefore
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryBefore(@Nonnull Message message, int limit) Uses the provided message as a marker and retrieves messages sent before the marker. 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(message, 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.
- Parameters:
message
- 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.- Throws:
IllegalArgumentException
-- Provided
message
isnull
. - Provided
limit
is less than1
or greater than100
.
- Provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
getHistoryFromBeginning
@Nonnull @CheckReturnValue default MessageHistory.MessageRetrieveAction getHistoryFromBeginning(int limit) 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.
- 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!- Throws:
IllegalArgumentException
- Providedlimit
is less than1
or greater than100
.InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have- See Also:
-
sendTyping
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.
- Returns:
RestAction
- Type: Void- Throws:
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have
-
addReactionById
@Nonnull @CheckReturnValue default RestAction<Void> addReactionById(@Nonnull String messageId, @Nonnull Emoji emoji) 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.
- Parameters:
messageId
- The messageId to attach the reaction toemoji
- The not-nullEmoji
to react with- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
emoji
isnull
.
- If provided
InsufficientPermissionException
- If the MessageChannel this message was sent in was aGuildMessageChannel
and the logged in account does not have
-
addReactionById
@Nonnull @CheckReturnValue default RestAction<Void> addReactionById(long messageId, @Nonnull Emoji emoji) 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.
- Parameters:
messageId
- The messageId to attach the reaction toemoji
- TheEmoji
to react with- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
emoji
isnull
- If provided
InsufficientPermissionException
- If the MessageChannel this message was sent in was aGuildMessageChannel
and the logged in account does not have
-
removeReactionById
@Nonnull @CheckReturnValue default RestAction<Void> removeReactionById(@Nonnull String messageId, @Nonnull Emoji emoji) 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.
- Parameters:
messageId
- The messageId to remove the reaction fromemoji
- The emoji to remove- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or not a valid snowflake. - If provided
emoji
isnull
.
- If provided
-
removeReactionById
@Nonnull @CheckReturnValue default RestAction<Void> removeReactionById(long messageId, @Nonnull Emoji emoji) 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.
- Parameters:
messageId
- The messageId to remove the reaction fromemoji
- The emoji to remove- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
emoji
isnull
.
- If provided
-
retrieveReactionUsersById
@Nonnull @CheckReturnValue default ReactionPaginationAction retrieveReactionUsersById(@Nonnull String messageId, @Nonnull Emoji emoji) This obtains theusers
who reacted to a message using the givenEmoji
.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.
- Parameters:
messageId
- The messageId to retrieve the users from.emoji
- TheEmoji
to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emoji's users. - Throws:
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
.IllegalArgumentException
-- If provided
messageId
isnull
or not a valid snowflake. - If provided
emoji
isnull
.
- If provided
-
retrieveReactionUsersById
@Nonnull @CheckReturnValue default ReactionPaginationAction retrieveReactionUsersById(long messageId, @Nonnull Emoji emoji) This obtains theusers
who reacted to a message using the givenEmoji
.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.
- Parameters:
messageId
- The messageId to retrieve the users from.emoji
- TheEmoji
to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emoji's users. - Throws:
UnsupportedOperationException
- If this is not a Received Message fromMessageType.DEFAULT
InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
.IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
emoji
isnull
.
- If provided
- Since:
- 4.2.0
-
pinMessageById
Used to pin a message. Pinned messages are retrievable viaretrievePinnedMessages()
.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.
- Parameters:
messageId
- The message to pin.- Returns:
RestAction
- Throws:
IllegalArgumentException
- if the provided messageId isnull
or empty.InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have
-
pinMessageById
Used to pin a message. Pinned messages are retrievable viaretrievePinnedMessages()
.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.
- Parameters:
messageId
- The message to pin.- Returns:
RestAction
- Throws:
IllegalArgumentException
- if the providedmessageId
is not a valid snowflake.InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have
-
unpinMessageById
Used to unpin a message. Pinned messages are retrievable viaretrievePinnedMessages()
.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.
- Parameters:
messageId
- The message to unpin.- Returns:
RestAction
- Throws:
IllegalArgumentException
- if the provided messageId isnull
or empty.InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have
-
unpinMessageById
Used to unpin a message. Pinned messages are retrievable viaretrievePinnedMessages()
.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.
- Parameters:
messageId
- The message to unpin.- Returns:
RestAction
- Throws:
IllegalArgumentException
- if the provided messageId is not positive.InsufficientPermissionException
- If this is aGuildMessageChannel
and the logged in account does not have
-
retrievePinnedMessages
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.
- Returns:
RestAction
- Type: List<Message
>
Retrieves an immutable list of pinned messages- Throws:
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
-
editMessageById
@Nonnull @CheckReturnValue default MessageEditAction editMessageById(@Nonnull String messageId, @Nonnull CharSequence newContent) 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.
- Parameters:
messageId
- The id referencing the Message that should be editednewContent
- The new content for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
newContent
isnull
or empty. - If provided
newContent
length is greater than 2000 characters.
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
-
editMessageById
@Nonnull @CheckReturnValue default MessageEditAction editMessageById(long messageId, @Nonnull CharSequence newContent) 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.
- Parameters:
messageId
- The id referencing the Message that should be editednewContent
- The new content for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
newContent
isnull
or empty. - If provided
newContent
length is greater than 2000 characters.
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
-
editMessageById
@Nonnull @CheckReturnValue default MessageEditAction editMessageById(@Nonnull String messageId, @Nonnull MessageEditData data) 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.
- Parameters:
messageId
- The id referencing the Message that should be editeddata
- The new content for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
newContent
isnull
. - If provided
Message
contains aMessageEmbed
which is notsendable
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
-
editMessageById
@Nonnull @CheckReturnValue default MessageEditAction editMessageById(long messageId, @Nonnull MessageEditData data) 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.
- Parameters:
messageId
- The id referencing the Message that should be editeddata
- The new content for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
newContent
isnull
. - If provided
Message
contains aMessageEmbed
which is notsendable
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
-
editMessageFormatById
@Nonnull @CheckReturnValue default MessageEditAction editMessageFormatById(@Nonnull String messageId, @Nonnull String format, @Nonnull Object... args) 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.
- Parameters:
messageId
- The id referencing the Message that should be editedformat
- Format String used to generate new Contentargs
- The arguments which should be used to format the given format String- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
format
isnull
or blank.
- If provided
IllegalStateException
- If the resulting message is either empty or too long to be sentInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
IllegalFormatException
- If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
-
editMessageFormatById
@Nonnull @CheckReturnValue default MessageEditAction editMessageFormatById(long messageId, @Nonnull String format, @Nonnull Object... args) 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.
- Parameters:
messageId
- The id referencing the Message that should be editedformat
- Format String used to generate new Contentargs
- The arguments which should be used to format the given format String- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
- If providedformat
isnull
or blank.IllegalStateException
- If the resulting message is either empty or too long to be sentInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
IllegalFormatException
- If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
-
editMessageEmbedsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageEmbedsById(@Nonnull String messageId, @Nonnull MessageEmbed... newEmbeds) 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.
- Parameters:
messageId
- The id referencing the Message that should be editednewEmbeds
- Up to 10 newMessageEmbeds
for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
MessageEmbed
is notsendable
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageEmbedsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageEmbedsById(long messageId, @Nonnull MessageEmbed... newEmbeds) 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.
- Parameters:
messageId
- The id referencing the Message that should be editednewEmbeds
- Up to 10 newMessageEmbeds
for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
MessageEmbed
is notsendable
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageEmbedsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageEmbedsById(@Nonnull String messageId, @Nonnull Collection<? extends MessageEmbed> newEmbeds) 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.
- Parameters:
messageId
- The id referencing the Message that should be editednewEmbeds
- Up to 10 newMessageEmbeds
for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
MessageEmbed
is notsendable
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageEmbedsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageEmbedsById(long messageId, @Nonnull Collection<? extends MessageEmbed> newEmbeds) 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.
- Parameters:
messageId
- The id referencing the Message that should be editednewEmbeds
- Up to 10 newMessageEmbeds
for the edited message- Returns:
MessageEditAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
MessageEmbed
is notsendable
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageComponentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageComponentsById(@Nonnull String messageId, @Nonnull Collection<? extends LayoutComponent> components) 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 areLayoutComponents
such asActionRow
which contain a list of components to arrange in the respective layout.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.
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();
- Parameters:
messageId
- The id referencing the Message that should be editedcomponents
- Up to 5 newLayoutComponents
for the edited message, such asActionRow
- Returns:
MessageEditAction
- Throws:
UnsupportedOperationException
- If the component layout is a custom implementation that is not supported by this interfaceIllegalArgumentException
-- If provided
messageId
isnull
or empty. - If any of the provided
LayoutComponents
is null
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageComponentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageComponentsById(long messageId, @Nonnull Collection<? extends LayoutComponent> components) 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 areLayoutComponents
such asActionRow
which contain a list of components to arrange in the respective layout.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.
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();
- Parameters:
messageId
- The id referencing the Message that should be editedcomponents
- Up to 5 newLayoutComponents
for the edited message, such asActionRow
- Returns:
MessageEditAction
- Throws:
UnsupportedOperationException
- If the component layout is a custom implementation that is not supported by this interfaceIllegalArgumentException
- If any of the providedLayoutComponents
is nullInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageComponentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageComponentsById(@Nonnull String messageId, @Nonnull LayoutComponent... components) 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 areLayoutComponents
such asActionRow
which contain a list of components to arrange in the respective layout.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.
Example
channel.editMessageComponentsById(messageId, 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 ).queue();
- Parameters:
messageId
- The id referencing the Message that should be editedcomponents
- Up to 5 newLayoutComponents
for the edited message, such asActionRow
- Returns:
MessageEditAction
- Throws:
UnsupportedOperationException
- If the component layout is a custom implementation that is not supported by this interfaceIllegalArgumentException
-- If provided
messageId
isnull
or empty. - If any of the provided
LayoutComponents
is null
- If provided
InsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageComponentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageComponentsById(long messageId, @Nonnull LayoutComponent... components) 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 areLayoutComponents
such asActionRow
which contain a list of components to arrange in the respective layout.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.
Example
channel.editMessageComponentsById(messageId, 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 ).queue();
- Parameters:
messageId
- The id referencing the Message that should be editedcomponents
- Up to 5 newLayoutComponents
for the edited message, such asActionRow
- Returns:
MessageEditAction
- Throws:
UnsupportedOperationException
- If the component layout is a custom implementation that is not supported by this interfaceIllegalArgumentException
- If any of the providedLayoutComponents
is nullInsufficientPermissionException
- If this is aGuildMessageChannel
and this account does not havePermission.VIEW_CHANNEL
orPermission.MESSAGE_SEND
-
editMessageAttachmentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageAttachmentsById(@Nonnull String messageId, @Nonnull Collection<? extends AttachedFile> attachments) 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.
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.- 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- Throws:
IllegalArgumentException
- If null is provided- See Also:
-
editMessageAttachmentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageAttachmentsById(@Nonnull String messageId, @Nonnull AttachedFile... attachments) 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.
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.- 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- Throws:
IllegalArgumentException
- If null is provided- See Also:
-
editMessageAttachmentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageAttachmentsById(long messageId, @Nonnull Collection<? extends AttachedFile> attachments) 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.
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.- 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- Throws:
IllegalArgumentException
- If null is provided- See Also:
-
editMessageAttachmentsById
@Nonnull @CheckReturnValue default MessageEditAction editMessageAttachmentsById(long messageId, @Nonnull AttachedFile... attachments) 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.
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.- 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- Throws:
IllegalArgumentException
- If null is provided- See Also:
-