Class Message

java.lang.Object
com.marcpg.libpg.web.discord.Message

public final class Message extends Object
Represents a full Discord webhook message that can be converted into a raw JSON.
Since:
0.0.4
See Also:
  • Field Details

  • Constructor Details

    • Message

      public Message(String threadName, boolean tts, String content, List<Embed> embeds, boolean silent)
      Creates a new message with all settings.
      Parameters:
      threadName - The channel's thread name. Only valid in forums or in text channels containing threads.
      tts - If the message should be sent as a text-to-speech message. Might run into issues with some other settings.
      content - The raw message content.
      embeds - A list of all embeds that should be appended to the message.
      silent - If the message should be silent, which means that no one will be notified.
    • Message

      public Message(String content, List<Embed> embeds, boolean silent)
      Creates a new message with embeds.
      Parameters:
      content - The raw message content.
      embeds - A list of all embeds that should be appended to the message.
      silent - If the message should be silent, which means that no one will be notified.
    • Message

      public Message(String content, boolean silent)
      Creates a new plaintext message.
      Parameters:
      content - The raw message content.
      silent - If the message should be silent, which means that no one will be notified.
    • Message

      public Message(String content, boolean tts, boolean silent)
      Creates a new plaintext message.
      Parameters:
      content - The raw message content.
      tts - If the message should be sent as text-to-speech.
      silent - If the message should be silent, which means that no one will be notified.
    • Message

      public Message(String username, URL avatarUrl, String threadName, boolean tts, String content, List<Embed> embeds, boolean silent)
      Creates a new message with all settings and a custom avatar.
      Parameters:
      username - The custom avatar's username.
      avatarUrl - The custom avatar's profile picture URL.
      threadName - The channel's thread name. Only valid in forums or in text channels containing threads.
      tts - If the message should be sent as a text-to-speech message. Might run into issues with some other settings.
      content - The raw message content.
      embeds - A list of all embeds that should be appended to the message.
      silent - If the message should be silent, which means that no one will be notified.
    • Message

      public Message(String username, URL avatarUrl, String content, List<Embed> embeds, boolean silent)
      Creates a new message with embeds and a custom avatar.
      Parameters:
      username - The custom avatar's username.
      avatarUrl - The custom avatar's profile picture URL.
      content - The raw message content.
      embeds - A list of all embeds that should be appended to the message.
      silent - If the message should be silent, which means that no one will be notified.
    • Message

      public Message(String username, URL avatarUrl, String content, boolean silent)
      Creates a new plaintext message with a custom avatar.
      Parameters:
      username - The custom avatar's username.
      avatarUrl - The custom avatar's profile picture URL.
      content - The raw message content.
      silent - If the message should be silent, which means that no one will be notified.
    • Message

      public Message()
      Creates a completely empty message. Same as Message.EMPTY.
  • Method Details

    • build

      public String build()
      Formats the message into a compact representation in JSON, which is required for sending it to the Discord API.
      Returns:
      The formatted JSON representation.
    • clear

      public Message clear()
      Clears the whole message by setting all values to null.
      Returns:
      A reference to this object.
    • clearNullAvoiding

      public Message clearNullAvoiding()
      Clears the whole message while trying to avoid settings values to null.
      Returns:
      A reference to this object.
    • isEmpty

      public boolean isEmpty()
      Checks if the message is empty. This doesn't only include if the values are null, but also if they are empty/blank.
      Returns:
      true if the message is empty, false otherwise.
    • getUsername

      public String getUsername()
      Gets the custom avatar's username.
      Returns:
      The custom avatar's username.
    • setUsername

      public Message setUsername(String username)
      Sets the custom avatar's username.
      Parameters:
      username - The custom avatar's username.
      Returns:
      A reference to this object.
    • getAvatarUrl

      public URL getAvatarUrl()
      Gets the custom avatar's profile picture URL.
      Returns:
      The custom avatar's profile picture URL.
    • setAvatarUrl

      public Message setAvatarUrl(URL avatarUrl)
      Sets the custom avatar's profile picture URL.
      Parameters:
      avatarUrl - The custom avatar's profile picture URL.
      Returns:
      A reference to this object.
    • getThreadName

      public String getThreadName()
      Gets the targeted thread name.
      Returns:
      The name of the channel's thread to post in.
    • setThreadName

      public Message setThreadName(String threadName)
      Sets the targeted thread name.
      Parameters:
      threadName - The name of the channel's thread to post in.
      Returns:
      A reference to this object.
    • isTTS

      public boolean isTTS()
      Gets if the message is tts.
      Returns:
      If the message is sent as a text-to-speech message.
    • setTTS

      public Message setTTS(boolean tts)
      Sets if the message is tts.
      Parameters:
      tts - If the message is sent as a text-to-speech message.
      Returns:
      A reference to this object.
    • getContent

      public String getContent()
      Gets the message's content.
      Returns:
      The message's raw content.
    • setContent

      public Message setContent(String content)
      Sets the message's content.
      Parameters:
      content - The raw message content.
      Returns:
      A reference to this object.
    • getEmbeds

      public List<Embed> getEmbeds()
      Gets the attached embeds.
      Returns:
      A list of all embeds.
    • setEmbeds

      public Message setEmbeds(List<Embed> embeds)
      Sets the attached embeds.
      Parameters:
      embeds - A list of all embeds.
      Returns:
      A reference to this object.
    • setEmbeds

      public Message setEmbeds(Embed... embeds)
      Gets the attached embeds.
      Parameters:
      embeds - All embeds.
      Returns:
      A reference to this object.
    • addEmbeds

      public Message addEmbeds(Embed... embeds)
      Appends a new embed to the message.
      Parameters:
      embeds - All embeds to be appended.
      Returns:
      A reference to this object.
    • addEmbeds

      public Message addEmbeds(List<Embed> embeds)
      Appends a new embed to the message.
      Parameters:
      embeds - A list of all embeds to be appended.
      Returns:
      A reference to this object.
    • isSilent

      public boolean isSilent()
      Gets if the message is a silent message or not.
      Returns:
      If the message is a silent message.
    • setSilent

      public Message setSilent(boolean silent)
      Sets if the message is a silent message or not.
      Parameters:
      silent - If the message is a silent message.
      Returns:
      A reference to this object.