Package com.marcpg.libpg.web.discord
Class Message
java.lang.Object
com.marcpg.libpg.web.discord.Message
Represents a full Discord webhook message that can be converted into a raw JSON.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMessage()
Creates a completely empty message.Creates a new plaintext message.Creates a new plaintext message.Creates a new message with all settings.Creates a new plaintext message with a custom avatar.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.Creates a new message with embeds and a custom avatar.Creates a new message with embeds. -
Method Summary
Modifier and TypeMethodDescriptionAppends a new embed to the message.Appends a new embed to the message.build()
Formats the message into a compact representation in JSON, which is required for sending it to the Discord API.clear()
Clears the whole message by setting all values to null.Clears the whole message while trying to avoid settings values to null.Gets the custom avatar's profile picture URL.Gets the message's content.Gets the attached embeds.Gets the targeted thread name.Gets the custom avatar's username.boolean
isEmpty()
Checks if the message is empty.boolean
isSilent()
Gets if the message is a silent message or not.boolean
isTTS()
Gets if the message is tts.setAvatarUrl
(URL avatarUrl) Sets the custom avatar's profile picture URL.setContent
(String content) Sets the message's content.Gets the attached embeds.Sets the attached embeds.setSilent
(boolean silent) Sets if the message is a silent message or not.setThreadName
(String threadName) Sets the targeted thread name.setTTS
(boolean tts) Sets if the message is tts.setUsername
(String username) Sets the custom avatar's username.
-
Field Details
-
EMPTY
A completely emptyMessage
object. Same asnew Message()
.
-
-
Constructor Details
-
Message
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
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
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
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
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
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 asMessage.EMPTY
.
-
-
Method Details
-
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
Clears the whole message by setting all values to null.- Returns:
- A reference to this object.
-
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 arenull
, but also if they are empty/blank.- Returns:
true
if the message is empty,false
otherwise.
-
getUsername
Gets the custom avatar's username.- Returns:
- The custom avatar's username.
-
setUsername
Sets the custom avatar's username.- Parameters:
username
- The custom avatar's username.- Returns:
- A reference to this object.
-
getAvatarUrl
Gets the custom avatar's profile picture URL.- Returns:
- The custom avatar's profile picture URL.
-
setAvatarUrl
Sets the custom avatar's profile picture URL.- Parameters:
avatarUrl
- The custom avatar's profile picture URL.- Returns:
- A reference to this object.
-
getThreadName
Gets the targeted thread name.- Returns:
- The name of the channel's thread to post in.
-
setThreadName
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
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
Gets the message's content.- Returns:
- The message's raw content.
-
setContent
Sets the message's content.- Parameters:
content
- The raw message content.- Returns:
- A reference to this object.
-
getEmbeds
Gets the attached embeds.- Returns:
- A list of all embeds.
-
setEmbeds
Sets the attached embeds.- Parameters:
embeds
- A list of all embeds.- Returns:
- A reference to this object.
-
setEmbeds
Gets the attached embeds.- Parameters:
embeds
- All embeds.- Returns:
- A reference to this object.
-
addEmbeds
Appends a new embed to the message.- Parameters:
embeds
- All embeds to be appended.- Returns:
- A reference to this object.
-
addEmbeds
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
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.
-