Interface MessageChannel
-
- All Superinterfaces:
Formattable
,ISnowflake
- All Known Subinterfaces:
PrivateChannel
,TextChannel
public interface MessageChannel extends ISnowflake, Formattable
Represents a Discord channel that can haveMessages
and files sent to it.Formattable
This interface extendsFormattable
and can be used with aFormatter
such as used byString.format(String, Object...)
orPrintStream.printf(String, Object...)
.This will use
getName()
rather thanObject.toString()
!
Supported Features:- Alternative
- Prepends the name with#
(Example:%#s
- results in#
)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
!TextChannel
is a special case which usesIMentionable.getAsMention()
by default and uses the#
format as alternativegetName()
- See Also:
TextChannel
,PrivateChannel
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default RestAction<Void>
addReactionById(long messageId, String unicode)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.default RestAction<Void>
addReactionById(long messageId, Emote emote)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.default RestAction<Void>
addReactionById(String messageId, String unicode)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.default RestAction<Void>
addReactionById(String messageId, Emote emote)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.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 MessageAction
editMessageById(long messageId, CharSequence newContent)
Attempts to edit a message by its id in this MessageChannel.default MessageAction
editMessageById(long messageId, Message newContent)
Attempts to edit a message by its id in this MessageChannel.default MessageAction
editMessageById(long messageId, MessageEmbed newEmbed)
Attempts to edit a message by its id in this MessageChannel.default MessageAction
editMessageById(String messageId, CharSequence newContent)
Attempts to edit a message by its id in this MessageChannel.default MessageAction
editMessageById(String messageId, Message newContent)
Attempts to edit a message by its id in this MessageChannel.default MessageAction
editMessageById(String messageId, MessageEmbed newEmbed)
Attempts to edit a message by its id in this MessageChannel.default MessageAction
editMessageFormatById(long messageId, String format, Object... args)
Attempts to edit a message by its id in this MessageChannel.default MessageAction
editMessageFormatById(String messageId, String format, Object... args)
Attempts to edit a message by its id in this MessageChannel.default void
formatTo(Formatter formatter, int flags, int width, int precision)
default MessageHistory
getHistory()
Creates a newMessageHistory
object for each call of this method.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.default MessageHistory.MessageRetrieveAction
getHistoryAfter(String messageId, int limit)
Uses the providedid
of a message as a marker and retrieves messages sent after the marker ID.default MessageHistory.MessageRetrieveAction
getHistoryAfter(Message message, int limit)
Uses the provided message as a marker and retrieves messages sent after the marker.default MessageHistory.MessageRetrieveAction
getHistoryAround(long messageId, int limit)
Uses the providedid
of a message as a marker and retrieves messages around the marker.default MessageHistory.MessageRetrieveAction
getHistoryAround(String messageId, int limit)
Uses the providedid
of a message as a marker and retrieves messages sent around the marker.default MessageHistory.MessageRetrieveAction
getHistoryAround(Message message, int limit)
Uses the providedMessage
as a marker and retrieves messages around the marker.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.default MessageHistory.MessageRetrieveAction
getHistoryBefore(String messageId, int limit)
Uses the providedid
of a message as a marker and retrieves messages sent before the marker ID.default MessageHistory.MessageRetrieveAction
getHistoryBefore(Message message, int limit)
Uses the provided message as a marker and retrieves messages sent before the marker.default MessageHistory.MessageRetrieveAction
getHistoryFromBeginning(int limit)
Retrieves messages from the beginning of thisMessageChannel
.default MessagePaginationAction
getIterableHistory()
APaginationAction
implementation that allows toiterate
over recentMessages
of this MessageChannel.JDA
getJDA()
Returns theJDA
instance of this MessageChanneldefault String
getLatestMessageId()
The id for the most recent message sent in this current MessageChannel.long
getLatestMessageIdLong()
The id for the most recent message sent in this current MessageChannel.String
getName()
This method is a shortcut method to return the following information in the following situation: If the MessageChannel is instance of..ChannelType
getType()
TheChannelType
of this MessageChannel.boolean
hasLatestMessage()
Whether this MessageChannel contains a tracked most recent message or not.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, String unicode)
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.default RestAction<Void>
removeReactionById(long messageId, Emote emote)
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.default RestAction<Void>
removeReactionById(String messageId, String unicode)
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.default RestAction<Void>
removeReactionById(String messageId, Emote emote)
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<List<Message>>
retrievePinnedMessages()
Retrieves a List ofMessages
that have been pinned in this channel.default ReactionPaginationAction
retrieveReactionUsersById(long messageId, String unicode)
This obtains theusers
who reacted to a message using the given unicode emoji.default ReactionPaginationAction
retrieveReactionUsersById(long messageId, Emote emote)
default ReactionPaginationAction
retrieveReactionUsersById(String messageId, String unicode)
This obtains theusers
who reacted to a message using the given unicode emoji.default ReactionPaginationAction
retrieveReactionUsersById(String messageId, Emote emote)
default MessageAction
sendFile(byte[] data, String fileName, AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
.default MessageAction
sendFile(File file, String fileName, AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
.default MessageAction
sendFile(File file, AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
.default MessageAction
sendFile(InputStream data, String fileName, AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
.default MessageAction
sendMessage(CharSequence text)
Sends a plain text message to this channel.default MessageAction
sendMessage(Message msg)
Sends a specifiedMessage
to this channel.default MessageAction
sendMessage(MessageEmbed embed)
Sends a specifiedMessageEmbed
as aMessage
to this channel.default MessageAction
sendMessageFormat(String format, Object... args)
Sends a formatted text message to this channel.default RestAction<Void>
sendTyping()
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.ISnowflake
getId, getIdLong, getTimeCreated
-
-
-
-
Method Detail
-
getLatestMessageId
@Nonnull default String getLatestMessageId()
The id for the most recent message sent in this current MessageChannel.
This should only be used ifhasLatestMessage()
returnstrue
!This value is updated on each
MessageReceivedEvent
and will be reset tonull
if the message associated with this ID gets deleted- Returns:
- The most recent message's id
- Throws:
IllegalStateException
- If no message id is available
-
purgeMessagesById
@Nonnull default List<CompletableFuture<Void>> purgeMessagesById(@Nonnull List<String> messageIds)
Convenience method to delete messages in the most efficient way available.
This combines bothTextChannel.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:
CompletableFuture.allOf(java.util.concurrent.CompletableFuture[])
-
purgeMessagesById
@Nonnull default List<CompletableFuture<Void>> purgeMessagesById(@Nonnull String... messageIds)
Convenience method to delete messages in the most efficient way available.
This combines bothTextChannel.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:
CompletableFuture.allOf(java.util.concurrent.CompletableFuture[])
-
purgeMessages
@Nonnull default List<CompletableFuture<Void>> purgeMessages(@Nonnull Message... messages)
Convenience method to delete messages in the most efficient way available.
This combines bothTextChannel.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:
CompletableFuture.allOf(java.util.concurrent.CompletableFuture[])
-
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 bothTextChannel.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:
CompletableFuture.allOf(java.util.concurrent.CompletableFuture[])
-
purgeMessagesById
@Nonnull default List<CompletableFuture<Void>> purgeMessagesById(@Nonnull long... messageIds)
Convenience method to delete messages in the most efficient way available.
This combines bothTextChannel.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:
CompletableFuture.allOf(java.util.concurrent.CompletableFuture[])
-
getLatestMessageIdLong
long getLatestMessageIdLong()
The id for the most recent message sent in this current MessageChannel.
This should only be used ifhasLatestMessage()
returnstrue
!This value is updated on each
MessageReceivedEvent
and will be reset tonull
if the message associated with this ID gets deleted- Returns:
- The most recent message's id
- Throws:
IllegalStateException
- If no message id is available
-
hasLatestMessage
boolean hasLatestMessage()
Whether this MessageChannel contains a tracked most recent message or not.This does not directly mean that
getHistory()
will be unable to retrieve past messages, it merely means that the latest message is untracked by our internal cache meaning that if this returnsfalse
thegetLatestMessageId()
method will throw anNoSuchElementException
- Returns:
- True, if a latest message id is available for retrieval by
getLatestMessageId()
- See Also:
getLatestMessageId()
-
getName
@Nonnull String getName()
This method is a shortcut method to return the following information in the following situation: If the MessageChannel is instance of..- TextChannel - Returns
GuildChannel.getName()
- PrivateChannel Returns
PrivateChannel.getUser()
.getName()
- Returns:
- Never-null "name" of the MessageChannel. Different implementations determine what the name.
- TextChannel - Returns
-
getType
@Nonnull ChannelType getType()
TheChannelType
of this MessageChannel.- Returns:
- The ChannelType for this channel
-
getJDA
@Nonnull JDA getJDA()
Returns theJDA
instance of this MessageChannel- Returns:
- the corresponding JDA instance
-
sendMessage
@Nonnull @CheckReturnValue default MessageAction sendMessage(@Nonnull CharSequence text)
Sends a plain text message to this channel.
This will fail if this channel is an instance ofTextChannel
and the currently logged in account does not have permissions to send a message to this channel.
To determine if you are able to send a message in aTextChannel
useguild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)
.For
ErrorResponse
information, refer tosendMessage(Message)
.- Parameters:
text
- the text to send to the MessageChannel.- Returns:
MessageAction
The newly created Message after it has been sent to Discord.- Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not havePermission.MESSAGE_WRITE
IllegalArgumentException
- if the provided text is null, empty or longer than 2000 charactersUnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.- See Also:
MessageBuilder
-
sendMessageFormat
@Nonnull @CheckReturnValue default MessageAction sendMessageFormat(@Nonnull String format, @Nonnull Object... args)
Sends a formatted text message to this channel.
This will fail if this channel is an instance ofTextChannel
and the currently logged in account does not have permissions to send a message to this channel.
To determine if you are able to send a message in aTextChannel
useguild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)
.For
ErrorResponse
information, refer tosendMessage(Message)
.- Parameters:
format
- The string that should be formatted, if this isnull
or empty the content of the Message would be empty and cause a builder exception.args
- The arguments for your format- Returns:
MessageAction
The newly created Message after it has been sent to Discord.- Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not haveIllegalArgumentException
- If the provided format text isnull
, empty or longer than 2000 charactersUnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.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.
-
sendMessage
@Nonnull @CheckReturnValue default MessageAction sendMessage(@Nonnull MessageEmbed embed)
Sends a specifiedMessageEmbed
as aMessage
to this channel.
This will fail if this channel is an instance ofTextChannel
and the currently logged in account does not have permissions to send a message to this channel.
To determine if you are able to send a message in aTextChannel
useguild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)
.For
ErrorResponse
information, refer tosendMessage(Message)
.- Parameters:
embed
- theMessageEmbed
to send- Returns:
MessageAction
The newly created Message after it has been sent to Discord.- Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not haveIllegalArgumentException
- If the provided embed isnull
or if the providedMessageEmbed
is notsendable
UnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.- See Also:
MessageBuilder
,EmbedBuilder
-
sendMessage
@Nonnull @CheckReturnValue default MessageAction sendMessage(@Nonnull Message msg)
Sends a specifiedMessage
to this channel.
This will fail if this channel is an instance ofTextChannel
and the currently logged in account does not have permissions to send a message to this channel.
To determine if you are able to send a message in aTextChannel
useguild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)
.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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The send request was attempted after the account lostPermission.MESSAGE_WRITE
in theTextChannel
.CANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserUNKNOWN_CHANNEL
The send request was attempted after the channel was deleted.
- Parameters:
msg
- theMessage
to send- Returns:
MessageAction
The newly created Message after it has been sent to Discord.- Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not havePermission.MESSAGE_READ
Permission.MESSAGE_WRITE
Permission.MESSAGE_EMBED_LINKS
(if this message is only an embed)
IllegalArgumentException
- If the provided message isnull
or the providedMessage
contains anMessageEmbed
that is notsendable
UnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.- See Also:
MessageBuilder
-
sendFile
@Nonnull @CheckReturnValue default MessageAction sendFile(@Nonnull File file, @Nonnull AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
. Sends the providedMessage
with the uploaded file.
If you want to send a Message with the uploaded file, you can add the file to theMessageAction
returned bysendMessage(Message)
.This is a shortcut to
sendFile(java.io.File, String, AttachmentOption...)
by way of usingFile.getName()
.sendFile(file, file.getName())
Uploading images with Embeds
When uploading an image you can reference said image using the specified filename as URIattachment://filename.ext
.Example
MessageChannel channel; // = reference of a MessageChannel EmbedBuilder embed = new EmbedBuilder(); File file = new File("cat.gif"); embed.setImage("attachment://cat.gif") .setDescription("This is a cute cat :3"); channel.sendFile(file).embed(embed.build()).queue();
For
ErrorResponse
information, refer to the documentation forsendFile(java.io.File, String, AttachmentOption...)
.- Parameters:
file
- The file to upload to theMessageChannel
.options
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Providing theMessage
created from this upload.- Throws:
IllegalArgumentException
-- Provided
file
is null. - Provided
file
does not exist. - Provided
file
is unreadable. - Provided
file
is greater than 8 MiB on a normal or 50 MiB on a nitro account.
- Provided
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not haveUnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.
-
sendFile
@Nonnull @CheckReturnValue default MessageAction sendFile(@Nonnull File file, @Nonnull String fileName, @Nonnull AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
. Sends the providedMessage
with the uploaded file.
If you want to send a Message with the uploaded file, you can add the file to theMessageAction
returned bysendMessage(Message)
.The
fileName
parameter is used to inform Discord about what the file should be called. This is 2 fold:- The file name provided is the name that is found in
Message.Attachment.getFileName()
after upload and it is the name that will show up in the client when the upload is displayed.
Note: The fileName does not show up on the Desktop client for images. It does on mobile however. - The extension of the provided fileName also determines how Discord will treat the file. Discord currently only has special handling for image file types, but the fileName's extension must indicate that it is an image file. This means it has to end in something like .png, .jpg, .jpeg, .gif, etc. As a note, you can also not provide a full name for the file and instead ONLY provide the extension like "png" or "gif" and Discord will generate a name for the upload and append the fileName as the extension.
Uploading images with Embeds
When uploading an image you can reference said image using the specified filename as URIattachment://filename.ext
.Example
MessageChannel channel; // = reference of a MessageChannel EmbedBuilder embed = new EmbedBuilder(); File file = new File("cat_01.gif"); embed.setImage("attachment://cat.gif") // we specify this in sendFile as "cat.gif" .setDescription("This is a cute cat :3"); channel.sendFile(file, "cat.gif").embed(embed.build()).queue();
The following
ErrorResponses
are possible:MISSING_ACCESS
The send request was attempted after the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The send request was attempted after the account lostPermission.MESSAGE_WRITE
orPermission.MESSAGE_ATTACH_FILES
in theTextChannel
.CANNOT_SEND_TO_USER
If this is aPrivateChannel
and the currently logged in account does not share any Guilds with the recipient UserUNKNOWN_CHANNEL
The send request was attempted after the channel was deleted.
- Parameters:
file
- The file to upload to theMessageChannel
.fileName
- The name that should be sent to discordoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Providing theMessage
created from this upload.- Throws:
IllegalArgumentException
-- Provided
file
is null. - Provided
file
does not exist. - Provided
file
is unreadable. - Provided
file
is greater than 8 MiB on a normal or 50 MiB on a nitro account.
- Provided
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not haveUnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.
- The file name provided is the name that is found in
-
sendFile
@Nonnull @CheckReturnValue default MessageAction sendFile(@Nonnull InputStream data, @Nonnull String fileName, @Nonnull AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
. Sends the providedMessage
with the uploaded file.
If you want to send a Message with the uploaded file, you can add the file to theMessageAction
returned bysendMessage(Message)
.
This allows you to send anInputStream
as substitute to a file.For information about the
fileName
parameter, Refer to the documentation forsendFile(java.io.File, String, AttachmentOption...)
.
ForErrorResponse
information, refer to the documentation forsendFile(java.io.File, String, AttachmentOption...)
.Uploading images with Embeds
When uploading an image you can reference said image using the specified filename as URIattachment://filename.ext
.Example
MessageChannel channel; // = reference of a MessageChannel EmbedBuilder embed = new EmbedBuilder(); InputStream file = new URL("https://http.cat/500").openStream(); embed.setImage("attachment://cat.png") // we specify this in sendFile as "cat.png" .setDescription("This is a cute cat :3"); channel.sendFile(file, "cat.png").embed(embed.build()).queue();
- Parameters:
data
- The InputStream data to upload to theMessageChannel
.fileName
- The name that should be sent to discord
Refer to the documentation forsendFile(java.io.File, String, AttachmentOption...)
for information about this parameter.options
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Provides theMessage
created from this upload.- Throws:
IllegalArgumentException
- If the provided file or filename isnull
orempty
.InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not haveUnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.
-
sendFile
@Nonnull @CheckReturnValue default MessageAction sendFile(@Nonnull byte[] data, @Nonnull String fileName, @Nonnull AttachmentOption... options)
Uploads a file to the Discord servers and sends it to thisMessageChannel
. Sends the providedMessage
with the uploaded file.
If you want to send a Message with the uploaded file, you can add the file to theMessageAction
returned bysendMessage(Message)
.
This allows you to send anbyte[]
as substitute to a file.For information about the
fileName
parameter, Refer to the documentation forsendFile(java.io.File, String, AttachmentOption...)
.
ForErrorResponse
information, refer to the documentation forsendFile(java.io.File, String, AttachmentOption...)
.Uploading images with Embeds
When uploading an image you can reference said image using the specified filename as URIattachment://filename.ext
.Example
MessageChannel channel; // = reference of a MessageChannel EmbedBuilder embed = new EmbedBuilder(); byte[] file = IOUtil.readFully(new URL("https://http.cat/500").openStream()); embed.setImage("attachment://cat.png") // we specify this in sendFile as "cat.png" .setDescription("This is a cute cat :3"); channel.sendFile(file, "cat.png").embed(embed.build()).queue();
- Parameters:
data
- Thebyte[]
data to upload to theMessageChannel
.fileName
- The name that should be sent to discord.
Refer to the documentation forsendFile(java.io.File, String, AttachmentOption...)
for information about this parameter.options
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Provides theMessage
created from this upload.- Throws:
IllegalArgumentException
-- If the provided filename is
null
orempty
- If the provided data is larger than 8 MiB on a normal or 50 MiB on a nitro account
- If the provided filename is
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not haveUnsupportedOperationException
- If this is aPrivateChannel
and both the currently logged in account and the target user are bots.
-
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!Only bots can use this endpoint! A similar behaviour can be simulated using
getHistoryAround(long, int)
!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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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:
AccountTypeException
- If the currently logged in account is not fromAccountType.BOT
IllegalArgumentException
- if the providedmessageId
is null or empty.InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not have
-
retrieveMessageById
@Nonnull @CheckReturnValue default RestAction<Message> retrieveMessageById(long 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!Only bots can use this endpoint! A similar behaviour can be simulated using
getHistoryAround(long, int)
!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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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:
AccountTypeException
- If the currently logged in account is not fromAccountType.BOT
InsufficientPermissionException
- If this is aTextChannel
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request attempted to delete a Message in aTextChannel
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 aTextChannel
and the logged in account does not havePermission.MESSAGE_READ
.
-
deleteMessageById
@Nonnull @CheckReturnValue default AuditableRestAction<Void> deleteMessageById(long 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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request attempted to delete a Message in aTextChannel
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 aTextChannel
and the logged in account does not havePermission.MESSAGE_READ
.
-
getHistory
default MessageHistory 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 aTextChannel
and the currently logged in account does not have the permissionMESSAGE_HISTORY
-
getIterableHistory
@Nonnull @CheckReturnValue default MessagePaginationAction 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 aTextChannel
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryAround(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryAround(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryAround(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryAfter(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryAfter(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryAfter(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryBefore(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryBefore(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.getHistoryBefore(MessageChannel, String)
-
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_HISTORY
in theTextChannel
.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 aTextChannel
and the logged in account does not have- See Also:
MessageHistory.retrieveFuture(int)
,MessageHistory.getHistoryAfter(MessageChannel, String)
-
sendTyping
@Nonnull @CheckReturnValue default RestAction<Void> 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.MESSAGE_READ
orPermission.MESSAGE_WRITE
was revoked in theTextChannel
UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Returns:
RestAction
- Type: Void- Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not have
-
addReactionById
@Nonnull @CheckReturnValue default RestAction<Void> addReactionById(@Nonnull String messageId, @Nonnull String unicode)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.The unicode provided has to be a unicode representation of the emoji that is supposed to be used for the Reaction.
To retrieve the characters needed you can use an api or the official discord client by escaping the emoji (\:emoji-name:) and copying the resulting emoji from the sent message.This method encodes the provided unicode for you. Do not encode the emoji before providing the unicode.
Examples
// custom
channel.addReactionById(messageId, "minn:245267426227388416").queue();
// unicode escape
channel.addReactionById(messageId, "\uD83D\uDE02").queue();
// codepoint notation
channel.addReactionById(messageId, "U+1F602").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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_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 tounicode
- The unicode characters to react with- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or not a valid snowflake. - If provided
unicode
isnull
or empty.
- If provided
InsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not have:
-
addReactionById
@Nonnull @CheckReturnValue default RestAction<Void> addReactionById(long messageId, @Nonnull String unicode)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.The unicode provided has to be a unicode representation of the emoji that is supposed to be used for the Reaction.
To retrieve the characters needed you can use an api or the official discord client by escaping the emoji (\:emoji-name:) and copying the resulting emoji from the sent message.This method encodes the provided unicode for you. Do not encode the emoji before providing the unicode.
Examples
// custom
channel.addReactionById(messageId, "minn:245267426227388416").queue();
// unicode escape
channel.addReactionById(messageId, "\uD83D\uDE02").queue();
// codepoint notation
channel.addReactionById(messageId, "U+1F602").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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_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 tounicode
- The unicode characters to react with- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
unicode
isnull
or empty.
- If provided
InsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not have:
-
addReactionById
@Nonnull @CheckReturnValue default RestAction<Void> addReactionById(@Nonnull String messageId, @Nonnull Emote emote)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.An Emote is not the same as an emoji!
Emotes are custom guild-specific images unlike global unicode emojis!Unicode emojis are not included as
Emote
!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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided emote 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 toemote
- The not-nullEmote
to react with- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
emote
isnull
.
- If provided
InsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not have
-
addReactionById
@Nonnull @CheckReturnValue default RestAction<Void> addReactionById(long messageId, @Nonnull Emote emote)
Attempts to react to a message represented by the specifiedmessageId
in this MessageChannel.An Emote is not the same as an emoji!
Emotes are custom guild-specific images unlike global unicode emojis!Unicode emojis are not included as
Emote
!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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided emote 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 toemote
- The not-nullEmote
to react with- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
emote
isnull
- If provided
InsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not have
-
removeReactionById
@Nonnull @CheckReturnValue default RestAction<Void> removeReactionById(@Nonnull String messageId, @Nonnull String unicode)
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.The unicode provided has to be a unicode representation of the emoji that is supposed to be represented by the Reaction.
To retrieve the characters needed you can use an api or the official discord client by escaping the emoji (\:emoji-name:) and copying the resulting emoji from the sent message.This method encodes the provided unicode for you. Do not encode the emoji before providing the unicode.
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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_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 fromunicode
- The unicode characters of the emoji- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or not a valid snowflake. - If provided
unicode
isnull
or empty.
- If provided
-
removeReactionById
@Nonnull @CheckReturnValue default RestAction<Void> removeReactionById(long messageId, @Nonnull String unicode)
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.The unicode provided has to be a unicode representation of the emoji that is supposed to be represented by the Reaction.
To retrieve the characters needed you can use an api or the official discord client by escaping the emoji (\:emoji-name:) and copying the resulting emoji from the sent message.This method encodes the provided unicode for you. Do not encode the emoji before providing the unicode.
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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_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 fromunicode
- The unicode characters of the emoji- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
unicode
isnull
or empty.
- If provided
-
removeReactionById
@Nonnull @CheckReturnValue default RestAction<Void> removeReactionById(@Nonnull String messageId, @Nonnull Emote emote)
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.An Emote is not the same as an emoji!
Emotes are custom guild-specific images unlike global unicode emojis!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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided emote 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 fromemote
- The emote to remove- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or not a valid snowflake. - If provided
emote
isnull
.
- If provided
-
removeReactionById
@Nonnull @CheckReturnValue default RestAction<Void> removeReactionById(long messageId, @Nonnull Emote emote)
Attempts to remove the reaction from a message represented by the specifiedmessageId
in this MessageChannel.An Emote is not the same as an emoji!
Emotes are custom guild-specific images unlike global unicode emojis!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.MESSAGE_READ
was revoked in theTextChannel
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
in theTextChannel
.UNKNOWN_EMOJI
The provided emote 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 fromemote
- The emote to remove- Returns:
RestAction
- Throws:
IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
emote
isnull
.
- If provided
-
retrieveReactionUsersById
@Nonnull @CheckReturnValue default ReactionPaginationAction retrieveReactionUsersById(@Nonnull String messageId, @Nonnull String unicode)
This obtains theusers
who reacted to a message using the given unicode emoji.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 this message.The following
ErrorResponses
are possible:MISSING_ACCESS
The retrieve request was attempted after the account lost access to theTextChannel
due toPermission.MESSAGE_READ
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_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.unicode
- The unicode emote to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emoji's users. - Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
.IllegalArgumentException
-- If provided
messageId
isnull
or not a valid snowflake. - If the provided unicode emoji is
null
or empty.
- If provided
- Since:
- 4.2.0
-
retrieveReactionUsersById
@Nonnull @CheckReturnValue default ReactionPaginationAction retrieveReactionUsersById(long messageId, @Nonnull String unicode)
This obtains theusers
who reacted to a message using the given unicode emoji.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 this message.The following
ErrorResponses
are possible:MISSING_ACCESS
The retrieve request was attempted after the account lost access to theTextChannel
due toPermission.MESSAGE_READ
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_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.unicode
- The unicode emote to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emoji's users. - Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
.IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided unicode emoji is
null
or empty.
- If provided
- Since:
- 4.2.0
-
retrieveReactionUsersById
@Nonnull @CheckReturnValue default ReactionPaginationAction retrieveReactionUsersById(@Nonnull String messageId, @Nonnull Emote emote)
This obtains theusers
who reacted to a message using the givenemote
.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 theTextChannel
due toPermission.MESSAGE_READ
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided emote 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.emote
- Theemote
to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emote's users. - Throws:
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
.IllegalArgumentException
-- If provided
messageId
isnull
or not a valid snowflake. - If provided
Emote
isnull
.
- If provided
- Since:
- 4.2.0
-
retrieveReactionUsersById
@Nonnull @CheckReturnValue default ReactionPaginationAction retrieveReactionUsersById(long messageId, @Nonnull Emote emote)
This obtains theusers
who reacted to a message using the givenemote
.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 theTextChannel
due toPermission.MESSAGE_READ
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided emote 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.emote
- Theemote
to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emote's users. - Throws:
UnsupportedOperationException
- If this is not a Received Message fromMessageType.DEFAULT
InsufficientPermissionException
- If this is aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
.IllegalArgumentException
-- If provided
messageId
is not a valid snowflake. - If provided
Emote
isnull
.
- If provided
- Since:
- 4.2.0
-
pinMessageById
@Nonnull @CheckReturnValue default RestAction<Void> pinMessageById(@Nonnull String messageId)
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in theTextChannel
.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 aTextChannel
and the logged in account does not have
-
pinMessageById
@Nonnull @CheckReturnValue default RestAction<Void> pinMessageById(long messageId)
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in theTextChannel
.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 aTextChannel
and the logged in account does not have
-
unpinMessageById
@Nonnull @CheckReturnValue default RestAction<Void> unpinMessageById(@Nonnull String messageId)
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in theTextChannel
.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 aTextChannel
and the logged in account does not have
-
unpinMessageById
@Nonnull @CheckReturnValue default RestAction<Void> unpinMessageById(long messageId)
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.MESSAGE_READ
was revoked in theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in theTextChannel
.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 aTextChannel
and the logged in account does not have
-
retrievePinnedMessages
@Nonnull @CheckReturnValue default RestAction<List<Message>> 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.MESSAGE_READ
was revoked in theTextChannel
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 a TextChannel and this account does not havePermission.MESSAGE_READ
-
editMessageById
@Nonnull @CheckReturnValue default MessageAction editMessageById(@Nonnull String messageId, @Nonnull CharSequence newContent)
Attempts to edit a message by its id in this MessageChannel. The string provided asnewContent
must have a length that is greater than 0 and less-than or equal to 2000. This is a Discord message length limitation.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.MESSAGE_READ
was revoked in theTextChannel
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:
MessageAction
The modified Message after it has been sent to Discord.- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
newContent
isnull
or empty. - If provided
newContent
length is greater than2000
characters.
- If provided
InsufficientPermissionException
- If this is a TextChannel and this account does not havePermission.MESSAGE_READ
-
editMessageById
@Nonnull @CheckReturnValue default MessageAction editMessageById(long messageId, @Nonnull CharSequence newContent)
Attempts to edit a message by its id in this MessageChannel. The string provided asnewContent
must have a length that is greater than 0 and less-than or equal to 2000. This is a Discord message length limitation.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.MESSAGE_READ
was revoked in theTextChannel
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:
MessageAction
The modified Message after it has been sent to Discord.- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
newContent
isnull
or empty. - If provided
newContent
length is greater than2000
characters.
- If provided
PermissionException
- If this is a TextChannel and this account does not havePermission.MESSAGE_READ
-
editMessageById
@Nonnull @CheckReturnValue default MessageAction editMessageById(@Nonnull String messageId, @Nonnull Message newContent)
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.MESSAGE_READ
was revoked in theTextChannel
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:
MessageAction
The modified Message after it has been sent to discord- 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 a TextChannel and this account does not havePermission.MESSAGE_READ
-
editMessageById
@Nonnull @CheckReturnValue default MessageAction editMessageById(long messageId, @Nonnull Message newContent)
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.MESSAGE_READ
was revoked in theTextChannel
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:
MessageAction
The modified Message after it has been sent to discord- Throws:
IllegalArgumentException
-- If provided
messageId
is not positive. - If provided
newContent
isnull
. - If provided
Message
contains aMessageEmbed
which is notsendable
- If provided
InsufficientPermissionException
- If this is a TextChannel and this account does not havePermission.MESSAGE_READ
-
editMessageFormatById
@Nonnull @CheckReturnValue default MessageAction editMessageFormatById(@Nonnull String messageId, @Nonnull String format, @Nonnull Object... args)
Attempts to edit a message by its id in this MessageChannel.
Shortcut forMessageBuilder.appendFormat(String, Object...)
.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.MESSAGE_READ
was revoked in theTextChannel
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:
MessageAction
The modified Message after it has been sent to discord- 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 a TextChannel and this account does not havePermission.MESSAGE_READ
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 MessageAction editMessageFormatById(long messageId, @Nonnull String format, @Nonnull Object... args)
Attempts to edit a message by its id in this MessageChannel.
Shortcut forMessageBuilder.appendFormat(String, Object...)
.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.MESSAGE_READ
was revoked in theTextChannel
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:
MessageAction
The modified Message after it has been sent to discord- Throws:
IllegalArgumentException
-- If provided
messageId
is not positive. - 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 a TextChannel and this account does not havePermission.MESSAGE_READ
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.
-
editMessageById
@Nonnull @CheckReturnValue default MessageAction editMessageById(@Nonnull String messageId, @Nonnull MessageEmbed newEmbed)
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.MESSAGE_READ
was revoked in theTextChannel
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 editednewEmbed
- The newMessageEmbed
for the edited message- Returns:
MessageAction
The modified Message after it has been sent to discord- Throws:
IllegalArgumentException
-- If provided
messageId
isnull
or empty. - If provided
MessageEmbed
is notsendable
- If provided
IllegalStateException
- If the provided MessageEmbed isnull
InsufficientPermissionException
- If this is a TextChannel and this account does not havePermission.MESSAGE_READ
orPermission.MESSAGE_WRITE
-
editMessageById
@Nonnull @CheckReturnValue default MessageAction editMessageById(long messageId, @Nonnull MessageEmbed newEmbed)
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.MESSAGE_READ
was revoked in theTextChannel
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 editednewEmbed
- The newMessageEmbed
for the edited message- Returns:
MessageAction
The modified Message after it has been sent to discord- Throws:
IllegalArgumentException
-- If provided
messageId
is not positive. - If provided
MessageEmbed
is notsendable
- If provided
IllegalStateException
- If the provided MessageEmbed isnull
InsufficientPermissionException
- If this is a TextChannel and this account does not havePermission.MESSAGE_READ
orPermission.MESSAGE_WRITE
-
formatTo
default void formatTo(Formatter formatter, int flags, int width, int precision)
- Specified by:
formatTo
in interfaceFormattable
-
-