Class WebhookMessage


  • public class WebhookMessage
    extends java.lang.Object
    A special Message that can only be sent to a WebhookClient.
    This message provides special attributes called username and avatar_url which override the default username and avatar of a Webhook message.

    This message can send multiple embeds at once!

    • Method Detail

      • embeds

        public static WebhookMessage embeds​(MessageEmbed first,
                                            MessageEmbed... embeds)
        Creates a new WebhookMessage instance with the provided MessageEmbeds
        Parameters:
        first - The first embed to use for this message
        embeds - The other embeds to use for this message
        Returns:
        The resulting WebhookMessage instance
        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
      • embeds

        public static WebhookMessage embeds​(java.util.Collection<MessageEmbed> embeds)
        Creates a new WebhookMessage instance with the provided MessageEmbeds
        Parameters:
        embeds - The embeds to use for this message
        Returns:
        The resulting WebhookMessage instance
        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
      • files

        public static WebhookMessage files​(java.lang.String name1,
                                           java.lang.Object data1,
                                           java.lang.Object... attachments)
        Constructs a message around pairs of (Name, Data).
        You can add up to 10 attachments to one message. This means you can have up to 20 arguments.
        The supported data types are InputStream, File, and byte[].

        Example

        
         WebhookMessage message = WebhookMessage.files(
             "dog", new File("dog.png"),
             "cat", new URL("https://random.cat/meow").openStream(),
             "bird", new byte[100]
         );
         
        Parameters:
        name1 - The first name argument
        data1 - The first data argument
        attachments - Additional pairs in the form of (Name, Data)
        Returns:
        WebhookMessage for the provided files
        Throws:
        java.lang.IllegalArgumentException - If the provided arguments are not pairs of (Name, Data) or if one of the provided files is not readable
        See Also:
        WebhookMessageBuilder.addFile(String, InputStream), WebhookMessageBuilder.addFile(String, byte[]), WebhookMessageBuilder.addFile(String, File), WebhookMessageBuilder.addFile(File)
      • from

        public static WebhookMessage from​(Message message)
        Creates a new WebhookMessage instance with the provided Message as layout for copying.
        This does not copy the attachments of the provided message!
        Parameters:
        message - The message to copy
        Returns:
        The resulting WebhookMessage instance
        Throws:
        java.lang.IllegalArgumentException - If the provided message is null
      • isFile

        public boolean isFile()
        Whether this message contains an attachment
        Returns:
        True, if this message contains an attachment