Interface MessageCreateRequest<R extends MessageCreateRequest<R>>

Type Parameters:
R - The return type for method chaining convenience
All Superinterfaces:
MessageData, MessageRequest<R>
All Known Subinterfaces:
ForumPostAction, MessageCreateAction, ReplyCallbackAction, WebhookMessageCreateAction<T>
All Known Implementing Classes:
MessageCreateBuilder

public interface MessageCreateRequest<R extends MessageCreateRequest<R>> extends MessageRequest<R>
Specialized abstraction of setters and accumulators for creating messages throughout the API.
See Also:
  • Method Details

    • addContent

      @Nonnull R addContent(@Nonnull String content)
      Appends the content to the currently set content of this request.
      Use MessageRequest.setContent(String) instead, to replace the content entirely.

      Example
      Sending a message with the content "Hello World!":

      channel.sendMessage("Hello ").addContent("World!").queue();
      
      Parameters:
      content - The content to append
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException - If the provided content is null or the accumulated content is longer than 2000 characters
    • addEmbeds

      @Nonnull R addEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds)
      Appends the provided MessageEmbeds to the request.
      Use MessageRequest.setEmbeds(Collection) instead, to replace the embeds entirely.

      Example
      Sending a message with multiple embeds:

      channel.sendMessageEmbeds(embed1).addEmbeds(embed2).queue();
      
      Parameters:
      embeds - The embeds to add
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException - If null is provided or the accumulated embed list is longer than 10
    • addEmbeds

      @Nonnull default R addEmbeds(@Nonnull MessageEmbed... embeds)
      Appends the provided MessageEmbeds to the request.
      Use MessageRequest.setEmbeds(Collection) instead, to replace the embeds entirely.

      Example
      Sending a message with multiple embeds:

      channel.sendMessageEmbeds(embed1).addEmbeds(embed2).queue();
      
      Parameters:
      embeds - The embeds to add
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException - If null is provided or the accumulated embed list is longer than 10
    • addComponents

      @Nonnull R addComponents(@Nonnull Collection<? extends MessageTopLevelComponent> components)
      Appends the provided MessageTopLevelComponents to the request.
      Use MessageRequest.setComponents(Collection) instead, to replace the components entirely.

      Example
      Sending a message with multiple action rows:

      final List<MessageTopLevelComponent> list = new ArrayList<>();
      list.add(ActionRow.of(selectMenu); // first row
      list.add(ActionRow.of(button1, button2)); // second row (shows below the first)
      
      channel.sendMessage("Content here")
             .addComponents(list)
             .queue();
      
      Parameters:
      components - The MessageTopLevelComponents to add, can contain up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException -
    • addComponents

      @Nonnull default R addComponents(@Nonnull MessageTopLevelComponent... components)
      Appends the provided MessageTopLevelComponents to the request.
      Use MessageRequest.setComponents(Collection) instead, to replace the components entirely.

      Example
      Sending a message with multiple action rows:

      channel.sendMessageComponents(ActionRow.of(selectMenu))
             .addComponents(ActionRow.of(button1, button2))
             .queue();
      
      Parameters:
      components - The MessageTopLevelComponents to add, can contain up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException -
    • addComponents

      @Nonnull default R addComponents(@Nonnull ComponentTree<? extends MessageTopLevelComponent> tree)
      Appends the provided ComponentTree of MessageTopLevelComponents to the request.
      Use MessageRequest.setComponents(ComponentTree) instead, to replace the components entirely.
      Parameters:
      tree - The ComponentTree to add, containing up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException -
      See Also:
    • addFiles

      @Nonnull R addFiles(@Nonnull Collection<? extends FileUpload> files)
      Appends the provided FileUploads to the request.
      Use MessageRequest.setFiles(Collection) instead, to replace the file attachments entirely.

      Resource Handling Note: Once the request is handed off to the requester, for example when you call RestAction.queue(), the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after using FileUpload.fromData(File), before calling RestAction.queue(). You can safely use a try-with-resources to handle this, since FileUpload.close() becomes ineffective once the request is handed off.

      Example
      Sending a message with multiple files:

      channel.sendFiles(file1).addFiles(file2).queue();
      
      Parameters:
      files - The files to add
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException - If null is provided
    • addFiles

      @Nonnull default R addFiles(@Nonnull FileUpload... files)
      Appends the provided FileUploads to the request.
      Use MessageRequest.setFiles(Collection) instead, to replace the file attachments entirely.

      Resource Handling Note: Once the request is handed off to the requester, for example when you call RestAction.queue(), the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after using FileUpload.fromData(File), before calling RestAction.queue(). You can safely use a try-with-resources to handle this, since FileUpload.close() becomes ineffective once the request is handed off.

      Example
      Sending a message with multiple files:

      channel.sendFiles(file1).addFiles(file2).queue();
      
      Parameters:
      files - The files to add
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException - If null is provided
    • getAttachments

      @Nonnull List<FileUpload> getAttachments()
      Description copied from interface: MessageData
      The configured message attachments as AttachedFile, this is the opposite of MessageRequest.setFiles(Collection) and only returns what was set using that setter.

      For message edit requests, this will not be the current file attachments of the message.

      Specified by:
      getAttachments in interface MessageData
      Returns:
      The currently configured attachments, or an empty list if none were set yet
      See Also:
    • getPoll

      @Nullable MessagePollData getPoll()
      The poll attached to this message
      Returns:
      The attached poll, or null if no poll is present
    • setPoll

      @Nonnull R setPoll(@Nullable MessagePollData poll)
      Add a poll to this message.
      Parameters:
      poll - The poll to send
      Returns:
      The same instance for chaining
      See Also:
    • setTTS

      @Nonnull R setTTS(boolean tts)
      Whether the message should use Text-to-Speech (TTS).

      Requires Permission.MESSAGE_TTS to be enabled.

      Parameters:
      tts - True, if the message should use TTS
      Returns:
      The same instance for chaining
    • setSuppressedNotifications

      @Nonnull R setSuppressedNotifications(boolean suppressed)
      Set whether this message should trigger push/desktop notifications to other users.
      When a message is suppressed, it will not trigger push/desktop notifications.
      Parameters:
      suppressed - True, if this message should not trigger push/desktop notifications
      Returns:
      The same instance for chaining
    • setVoiceMessage

      @Nonnull R setVoiceMessage(boolean voiceMessage)
      Whether this message should be considered a voice message.
      Voice messages must upload a valid voice message attachment, using FileUpload.asVoiceMessage(MediaType, byte[], double).
      Parameters:
      voiceMessage - True, if this message is a voice message. Turned on automatically if attachment is a valid voice message attachment.
      Returns:
      The same instance for chaining
    • applyData

      @Nonnull default R applyData(@Nonnull MessageCreateData data)
      Applies the provided MessageCreateData to this request.
      Parameters:
      data - The message create data to apply
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException - If the data is null
    • applyMessage

      @Nonnull default R applyMessage(@Nonnull Message message)
      Description copied from interface: MessageRequest
      Applies all the data of the provided Message and attempts to copy it.
      This cannot copy the file attachments of the message, they must be manually downloaded and provided to MessageRequest.setFiles(FileUpload...).
      The allowed mentions are not updated to reflect the provided message, and might mention users that the message did not.

      For edit requests, this will set MessageEditRequest.setReplace(boolean) to true, and replace the existing message completely.

      Specified by:
      applyMessage in interface MessageRequest<R extends MessageCreateRequest<R>>
      Parameters:
      message - The message to copy the data from
      Returns:
      The same instance for chaining
    • applyEditData

      @Nonnull default R applyEditData(@Nonnull MessageEditData data)
      Applies the provided MessageEditData to this request.
      This will only set fields which were explicitly set on the MessageEditBuilder, unless it was configured to be replacing.

      This will not copy the message's attachments, only any configured FileUploads. To copy attachments, you must download them explicitly instead.

      Parameters:
      data - The message create data to apply
      Returns:
      The same instance for chaining
      Throws:
      IllegalArgumentException - If the data is null