Package me.croabeast.common.discord
Class RawWebhook
java.lang.Object
me.croabeast.common.discord.RawWebhook
A class that represents a raw webhook for sending messages to a Discord channel.
This class can be used to create and send simple messages or messages with embedded content, such as images and links.
To use this class, create an instance of it with the URL of the webhook and the message to be sent.
The message can then be further customized with methods to add embedded content and set additional parameters such as the username, avatar URL, and text-to-speech (TTS) settings.
Finally, call the execute() method to send the message to the Discord
channel.
Note: This class requires the Apache Commons Lang and JSON libraries, as well as Java 11 or higher.
- Since:
- 1.1
- Author:
- Kihsomray (forked by CroaBeast)
-
Constructor Summary
ConstructorsConstructorDescriptionRawWebhook(String url, String token, String message) Constructs a new RawWebhook instance with the specified URL, token and message. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEmbed(EmbedObject embed) Adds an embed object to theembedslist.voidexecute()Executes the webhook by sending the message to the channel.setAvatarUrl(String url) Sets the avatar's url for the webhook.setContent(String text) Sets the content for the webhook.setUsername(String text) Sets the username for the webhook.
-
Constructor Details
-
RawWebhook
Constructs a new RawWebhook instance with the specified URL, token and message.- Parameters:
url- the URL of the webhook.token- the token of the webhook.message- the message of the webhook.- Throws:
NullPointerException- if the URL is blank.
-
-
Method Details
-
addEmbed
Adds an embed object to theembedslist.- Parameters:
embed- an embed object
-
setContent
Sets the content for the webhook.- Parameters:
text- a text- Returns:
- the object's instance
-
setUsername
Sets the username for the webhook.- Parameters:
text- a text- Returns:
- the object's instance
-
setAvatarUrl
Sets the avatar's url for the webhook.- Parameters:
url- an url- Returns:
- the object's instance
-
execute
Executes the webhook by sending the message to the channel.- Throws:
IOException- if it has an error connecting to the url or if the url is invalidNullPointerException- if there is no content or embeds to display
-