Interface MessageEditBuilderMixin<R extends MessageEditRequest<R>>

All Superinterfaces:
AbstractMessageBuilderMixin<R,MessageEditBuilder>, MessageData, MessageEditRequest<R>, MessageRequest<R>
All Known Implementing Classes:
MessageEditActionImpl, MessageEditCallbackActionImpl, WebhookMessageEditActionImpl

public interface MessageEditBuilderMixin<R extends MessageEditRequest<R>> extends AbstractMessageBuilderMixin<R,MessageEditBuilder>, MessageEditRequest<R>
  • Method Details

    • setAttachments

      @Nonnull default R setAttachments(@Nullable Collection<? extends AttachedFile> attachments)
      Description copied from interface: MessageEditRequest
      The AttachedFiles that should be attached to the message.
      This will replace all the existing attachments on the message, you can use Collections.emptyList() or null to clear all attachments.

      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

      
       // Here "message" is an instance of the Message interface
      
       // Creates a list of the currently attached files of the message, important to get the generic parameter of the list right
       List<AttachedFile> attachments = new ArrayList<>(message.getAttachments());
      
       // The name here will be "cat.png" to discord, what the file is called on your computer is irrelevant and only used to read the data of the image.
       FileUpload file = FileUpload.fromData(new File("mycat-final-copy.png"), "cat.png"); // Opens the file called "cat.png" and provides the data used for sending
      
       // Adds another file to upload in addition the current attachments of the message
       attachments.add(file);
      
       message.editMessage("New content")
              .setAttachments(attachments)
              .queue();
       
      Specified by:
      setAttachments in interface MessageEditRequest<R extends MessageEditRequest<R>>
      Parameters:
      attachments - The AttachedFiles to attach to the message, null or an empty list will set the attachments to an empty list and remove them from the message
      Returns:
      The same instance for chaining
      See Also:
    • setReplace

      @Nonnull default R setReplace(boolean isReplace)
      Description copied from interface: MessageEditRequest
      Whether to replace the existing message completely.

      By default, edit requests will only update the message fields which were explicitly set. Changing this to true, will instead replace everything and remove all unset fields.

      Example Default
      A request such as this will only edit the content of the message, and leave any existing embeds or attachments intact.

      
       message.editMessage("hello").queue();
       

      Example Replace
      A request such as this will replace the entire message, and remove any existing embeds, attachments, components, etc.

      
       message.editMessage("hello").setReplace(true).queue();
       
      Specified by:
      setReplace in interface MessageEditRequest<R extends MessageEditRequest<R>>
      Parameters:
      isReplace - True, if only things explicitly set on this request should be present after the message is edited.
      Returns:
      The same message edit request builder
    • setFiles

      @Nonnull default R setFiles(@Nullable Collection<? extends FileUpload> files)
      Description copied from interface: MessageRequest
      The FileUploads that should be attached to the message.
      This will replace all the existing attachments on the message, if this is an edit request. You can use MessageEditRequest.setAttachments(Collection) to keep existing attachments, instead of this method.

      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
      Create an embed with a custom image, uploaded alongside the message:

      
       MessageEmbed embed = new EmbedBuilder()
               .setDescription("Image of a cute cat")
               .setImage("attachment://cat.png") // here "cat.png" is the name used in the FileUpload.fromData factory method
               .build();
      
       // The name here will be "cat.png" to discord, what the file is called on your computer is irrelevant and only used to read the data of the image.
       FileUpload file = FileUpload.fromData(new File("mycat-final-copy.png"), "cat.png"); // Opens the file called "cat.png" and provides the data used for sending
      
       channel.sendMessageEmbeds(embed)
              .setFiles(file)
              .queue();
       
      Specified by:
      setFiles in interface AbstractMessageBuilderMixin<R extends MessageEditRequest<R>,MessageEditBuilder>
      Specified by:
      setFiles in interface MessageEditRequest<R extends MessageEditRequest<R>>
      Specified by:
      setFiles in interface MessageRequest<R extends MessageEditRequest<R>>
      Parameters:
      files - The FileUploads to attach to the message, null or an empty list will set the attachments to an empty list and remove them from the message
      Returns:
      The same instance for chaining
    • applyData

      @Nonnull default R applyData(@Nonnull MessageEditData data)
      Description copied from interface: MessageEditRequest
      Applies the provided MessageEditData to this request.

      Note that this method will only call the setters which were also configured when building the message edit data instance, unless it was set to replace.

      Specified by:
      applyData in interface MessageEditRequest<R extends MessageEditRequest<R>>
      Parameters:
      data - The message edit data to apply
      Returns:
      The same instance for chaining
    • isReplace

      default boolean isReplace()
      Description copied from interface: MessageEditRequest
      Whether this request will replace the message and remove everything that is not currently set.

      If this is false, the request will only edit the message fields which were explicitly set.

      Specified by:
      isReplace in interface MessageEditRequest<R extends MessageEditRequest<R>>
      Returns:
      True, if this is a replacing request
      See Also: