Class WebhookMessageBuilder


  • public class WebhookMessageBuilder
    extends java.lang.Object
    Builder for a WebhookMessage
    • Field Detail

      • MAX_FILES

        public static final int MAX_FILES
        The maximum amount of files that can be added to a message (10)
        See Also:
        Constant Field Values
    • Constructor Detail

      • WebhookMessageBuilder

        public WebhookMessageBuilder​(Message message)
        Creates a new WebhookMessageBuilder and applies the information of the provided Message as preset values.
        This will not copy any attachments!
        Parameters:
        message - The Message used to set initial values of the builder
      • WebhookMessageBuilder

        public WebhookMessageBuilder()
        Creates a new empty WebhookMessageBuilder
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Whether this WebhookMessageBuilder contains any readable content.
        When the builder is empty it cannot successfully build a WebhookMessage.
        Returns:
        True, if this builder has no readable content
      • getFileAmount

        public int getFileAmount()
        The amount of files added to this WebhookMessageBuilder instance
        Returns:
        Amount of added files
      • reset

        public WebhookMessageBuilder reset()
        Resets this builder to default settings.
        Returns:
        The current WebhookMessageBuilder for chaining convenience
      • resetFiles

        public WebhookMessageBuilder resetFiles()
        Removes all added resources. The getFileAmount() will report 0 after this happened, however the allocated array will remain.
        Returns:
        The current WebhookMessageBuilder for chaining convenience
      • resetEmbeds

        public WebhookMessageBuilder resetEmbeds()
        Removes all embeds from this builder.
        Returns:
        The current WebhookMessageBuilder for chaining convenience
      • addEmbeds

        public WebhookMessageBuilder addEmbeds​(MessageEmbed... embeds)
        Adds the provided MessageEmbeds to this builder.

        You can send up to 10 embeds per message! If more are sent they will not be displayed.

        Parameters:
        embeds - The embeds to add
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If any of the provided embeds is null or exceeds the maximum total character count of MessageEmbed.EMBED_MAX_LENGTH_BOT
      • addEmbeds

        public WebhookMessageBuilder addEmbeds​(java.util.Collection<MessageEmbed> embeds)
        Adds the provided MessageEmbeds to this builder.

        You can send up to 10 embeds per message! If more are sent they will not be displayed.

        Parameters:
        embeds - The embeds to add
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If any of the provided embeds is null or exceeds the maximum total character count of MessageEmbed.EMBED_MAX_LENGTH_BOT
      • setContent

        public WebhookMessageBuilder setContent​(java.lang.String content)
        Sets the content of the resulting message.
        This will override the previous content.
        Parameters:
        content - The new content
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If the provided content exceeds 2000 characters in length
      • append

        public WebhookMessageBuilder append​(java.lang.String content)
        Appends to the currently set content of the resulting message.
        Parameters:
        content - The content to append
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If the provided content is null or the resulting content would exceed 2000 characters in length
      • setUsername

        public WebhookMessageBuilder setUsername​(java.lang.String username)
        Sets the username that should be used for the resulting message.
        This will override the default username of the webhook.
        Parameters:
        username - The username to use for this message
        Returns:
        The current WebhookMessageBuilder for chaining convenience
      • setAvatarUrl

        public WebhookMessageBuilder setAvatarUrl​(java.lang.String avatarUrl)
        Sets the avatar url that should be used for the resulting message.
        This will override the default avatar of the webhook.
        Parameters:
        avatarUrl - The avatar url to use for this message
        Returns:
        The current WebhookMessageBuilder for chaining convenience
      • addFile

        public WebhookMessageBuilder addFile​(java.io.File file)
        Adds the provided file to the resulting message.
        Shortcut for addFile(String, File).
        Parameters:
        file - The file to add
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If the provided file is null, does not exist, or is not readable
        java.lang.IllegalStateException - If the file limit has already been reached
        See Also:
        resetFiles()
      • addFile

        public WebhookMessageBuilder addFile​(java.lang.String name,
                                             java.io.File file)
        Adds the provided file to the resulting message.
        Parameters:
        name - The name to use for this file
        file - The file to add
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If the provided file is null, does not exist, or is not readable
        java.lang.IllegalStateException - If the file limit has already been reached
        See Also:
        resetFiles()
      • addFile

        public WebhookMessageBuilder addFile​(java.lang.String name,
                                             byte[] data)
        Adds the provided file to the resulting message.
        Parameters:
        name - The name to use for this file
        data - The file data to add
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If the provided name data is null
        java.lang.IllegalStateException - If the file limit has already been reached
        See Also:
        resetFiles()
      • addFile

        public WebhookMessageBuilder addFile​(java.lang.String name,
                                             java.io.InputStream data)
        Adds the provided file to the resulting message.
        Parameters:
        name - The name to use for this file
        data - The file data to add
        Returns:
        The current WebhookMessageBuilder for chaining convenience
        Throws:
        java.lang.IllegalArgumentException - If the provided name or data is null
        java.lang.IllegalStateException - If the file limit has already been reached
        See Also:
        resetFiles()
      • setTTS

        public WebhookMessageBuilder setTTS​(boolean tts)
        Sets whether the resulting message should use Text-To-Speech.
        Parameters:
        tts - True, if the resulting message should use Text-To-Speech
        Returns:
        The current WebhookMessageBuilder for chaining convenience
      • build

        public WebhookMessage build()
        Builds a WebhookMessage instance with the current state of this builder.
        Returns:
        The resulting WebhookMessage
        Throws:
        java.lang.IllegalStateException - If this builder is empty