Class MessageBuilder



  • public class MessageBuilder
    extends Object
    This class can help you to create messages.
    • Constructor Detail

      • MessageBuilder

        public MessageBuilder​()
    • Method Detail

      • fromMessage

        public static MessageBuilder fromMessage​(Message message)
        Creates a message builder from a message.
        Parameters:
        message - The message to copy.
        Returns:
        A message builder which would produce the same text as the given message.
      • appendCode

        public MessageBuilder appendCode​(String language,
                                         String code)
        Appends code to the message.
        Parameters:
        language - The language, e.g. "java".
        code - The code.
        Returns:
        The current instance in order to chain call methods.
      • append

        public MessageBuilder append​(String message,
                                     MessageDecoration... decorations)
        Appends a sting with or without decoration to the message.
        Parameters:
        message - The string to append.
        decorations - The decorations of the string.
        Returns:
        The current instance in order to chain call methods.
      • append

        public MessageBuilder append​(Mentionable entity)
        Appends a mentionable entity (usually a user or channel) to the message.
        Parameters:
        entity - The entity to mention.
        Returns:
        The current instance in order to chain call methods.
      • appendNewLine

        public MessageBuilder appendNewLine​()
        Appends a new line to the message.
        Returns:
        The current instance in order to chain call methods.
      • setContent

        public MessageBuilder setContent​(String content)
        Sets the content of the message. This method overwrites all previous content changes (using append(String, MessageDecoration...) for example).
        Parameters:
        content - The new content of the message.
        Returns:
        The current instance in order to chain call methods.
      • setEmbed

        public MessageBuilder setEmbed​(EmbedBuilder embed)
        Sets the embed of the message.
        Parameters:
        embed - The embed to set.
        Returns:
        The current instance in order to chain call methods.
      • setTts

        public MessageBuilder setTts​(boolean tts)
        Sets if the message should be text to speech.
        Parameters:
        tts - Whether the message should be text to speech or not.
        Returns:
        The current instance in order to chain call methods.
      • addFile

        public MessageBuilder addFile​(File file)
        Adds a file to the message.
        Parameters:
        file - The file to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachment(File)
      • addFile

        public MessageBuilder addFile​(Icon icon)
        Adds a file to the message.
        Parameters:
        icon - The icon to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachment(Icon)
      • addFile

        public MessageBuilder addFile​(URL url)
        Adds a file to the message.
        Parameters:
        url - The url of the attachment.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachment(URL)
      • addFile

        public MessageBuilder addFile​(byte[] bytes,
                                      String fileName)
        Adds a file to the message.
        Parameters:
        bytes - The bytes of the file.
        fileName - The name of the file.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachment(byte[], String)
      • addFileAsSpoiler

        public MessageBuilder addFileAsSpoiler​(File file)
        Adds a file to the message and marks it as spoiler.
        Parameters:
        file - The file to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachmentAsSpoiler(File)
      • addFileAsSpoiler

        public MessageBuilder addFileAsSpoiler​(Icon icon)
        Adds a file to the message and marks it as spoiler.
        Parameters:
        icon - The icon to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachmentAsSpoiler(Icon)
      • addFileAsSpoiler

        public MessageBuilder addFileAsSpoiler​(URL url)
        Adds a file to the message.
        Parameters:
        url - The url of the attachment.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachment(URL)
      • addFileAsSpoiler

        public MessageBuilder addFileAsSpoiler​(byte[] bytes,
                                               String fileName)
        Adds a file to the message and marks it as spoiler.
        Parameters:
        bytes - The bytes of the file.
        fileName - The name of the file.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachmentAsSpoiler(byte[], String)
      • addFileAsSpoiler

        public MessageBuilder addFileAsSpoiler​(InputStream stream,
                                               String fileName)
        Adds a file to the message and marks it as spoiler.
        Parameters:
        stream - The stream of the file.
        fileName - The name of the file.
        Returns:
        The current instance in order to chain call methods.
        See Also:
        addAttachment(InputStream, String)
      • addAttachment

        public MessageBuilder addAttachment​(BufferedImage image,
                                            String fileName)
        Adds an attachment to the message.
        Parameters:
        image - The image to add as an attachment.
        fileName - The file name of the image.
        Returns:
        The current instance in order to chain call methods.
      • addAttachment

        public MessageBuilder addAttachment​(File file)
        Adds an attachment to the message.
        Parameters:
        file - The file to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
      • addAttachment

        public MessageBuilder addAttachment​(Icon icon)
        Adds an attachment to the message.
        Parameters:
        icon - The icon to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
      • addAttachment

        public MessageBuilder addAttachment​(URL url)
        Adds an attachment to the message.
        Parameters:
        url - The url of the attachment.
        Returns:
        The current instance in order to chain call methods.
      • addAttachment

        public MessageBuilder addAttachment​(byte[] bytes,
                                            String fileName)
        Adds an attachment to the message.
        Parameters:
        bytes - The bytes of the file.
        fileName - The name of the file.
        Returns:
        The current instance in order to chain call methods.
      • addAttachment

        public MessageBuilder addAttachment​(InputStream stream,
                                            String fileName)
        Adds an attachment to the message.
        Parameters:
        stream - The stream of the file.
        fileName - The name of the file.
        Returns:
        The current instance in order to chain call methods.
      • addAttachmentAsSpoiler

        public MessageBuilder addAttachmentAsSpoiler​(BufferedImage image,
                                                     String fileName)
        Adds an attachment to the message and marks it as spoiler.
        Parameters:
        image - The image to add as an attachment.
        fileName - The file name of the image.
        Returns:
        The current instance in order to chain call methods.
      • addAttachmentAsSpoiler

        public MessageBuilder addAttachmentAsSpoiler​(File file)
        Adds an attachment to the message and marks it as spoiler.
        Parameters:
        file - The file to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
      • addAttachmentAsSpoiler

        public MessageBuilder addAttachmentAsSpoiler​(Icon icon)
        Adds an attachment to the message and marks it as spoiler.
        Parameters:
        icon - The icon to add as an attachment.
        Returns:
        The current instance in order to chain call methods.
      • addAttachmentAsSpoiler

        public MessageBuilder addAttachmentAsSpoiler​(URL url)
        Adds an attachment to the message and marks it as spoiler.
        Parameters:
        url - The url of the attachment.
        Returns:
        The current instance in order to chain call methods.
      • addAttachmentAsSpoiler

        public MessageBuilder addAttachmentAsSpoiler​(byte[] bytes,
                                                     String fileName)
        Adds an attachment to the message and marks it as spoiler.
        Parameters:
        bytes - The bytes of the file.
        fileName - The name of the file.
        Returns:
        The current instance in order to chain call methods.
      • addAttachmentAsSpoiler

        public MessageBuilder addAttachmentAsSpoiler​(InputStream stream,
                                                     String fileName)
        Adds an attachment to the message and marks it as spoiler.
        Parameters:
        stream - The stream of the file.
        fileName - The name of the file.
        Returns:
        The current instance in order to chain call methods.
      • setNonce

        public MessageBuilder setNonce​(String nonce)
        Sets the nonce of the message.
        Parameters:
        nonce - The nonce to set.
        Returns:
        The current instance in order to chain call methods.
      • getStringBuilder

        public StringBuilder getStringBuilder​()
        Gets the StringBuilder which is used to build the message.
        Returns:
        The StringBuilder which is used to build the message.
      • send

        public CompletableFuture<Message> send​(User user)
        Sends the message.
        Parameters:
        user - The user to which the message should be sent.
        Returns:
        The sent message.
      • send

        public CompletableFuture<Message> send​(TextChannel channel)
        Sends the message.
        Parameters:
        channel - The channel in which the message should be sent.
        Returns:
        The sent message.
      • send

        public CompletableFuture<Message> send​(Messageable messageable)
        Sends the message.
        Parameters:
        messageable - The receiver of the message.
        Returns:
        The sent message.