Class RawWebhook

java.lang.Object
me.croabeast.common.discord.RawWebhook

public class RawWebhook extends Object
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 Details

    • RawWebhook

      public RawWebhook(String url, String token, String message)
      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

      public void addEmbed(EmbedObject embed)
      Adds an embed object to the embeds list.
      Parameters:
      embed - an embed object
    • setContent

      public RawWebhook setContent(String text)
      Sets the content for the webhook.
      Parameters:
      text - a text
      Returns:
      the object's instance
    • setUsername

      public RawWebhook setUsername(String text)
      Sets the username for the webhook.
      Parameters:
      text - a text
      Returns:
      the object's instance
    • setAvatarUrl

      public RawWebhook setAvatarUrl(String url)
      Sets the avatar's url for the webhook.
      Parameters:
      url - an url
      Returns:
      the object's instance
    • execute

      public void execute() throws IOException
      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 invalid
      NullPointerException - if there is no content or embeds to display