Class Webhook

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

public class Webhook extends Object
A class for sending a webhook to a Discord channel. The class uses a configuration section to store the webhook settings, and can send both text and embed messages.

Text messages can be sent directly through the send() methods, while embed messages can be created and added using the register() method.

To send a message, the send() methods can be used. The message can be either provided as a parameter or set in the configuration section. If the message is not set in the configuration section and is not provided as a parameter, an empty message will be sent.

sendAsync() can be used to send asynchronously using CompletableFuture.

Since:
1.1
Author:
Kihsomray (forked by CroaBeast)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Webhook(@NotNull org.bukkit.configuration.ConfigurationSection sec)
    Create a Discord webhook setup using a default configuration section with no message to display.
    Webhook(@NotNull org.bukkit.configuration.ConfigurationSection sec, String message)
    Create a Discord webhook setup using a default configuration section and a default token "{message}".
    Webhook(@NotNull org.bukkit.configuration.ConfigurationSection sec, String token, String message)
    Create a Discord webhook setup using a default configuration section.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Sends the webhook.
    boolean
    send(String message)
    Sends the webhook.
    boolean
    send(String token, String message)
    Sends the webhook.
    void
    Sends the webhook asynchronously.
    void
    sendAsync(String message)
    Sends the webhook asynchronously.
    void
    sendAsync(String token, String message)
    Sends the webhook asynchronously.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Webhook

      public Webhook(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection sec, String token, String message)
      Create a Discord webhook setup using a default configuration section.

      Make sure the section looks something like this: webhook.yml

      Parameters:
      sec - a valid configuration section
      token - a token to replace
      message - a basic message to show
    • Webhook

      public Webhook(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection sec, String message)
      Create a Discord webhook setup using a default configuration section and a default token "{message}".

      Make sure the section looks something like this: webhook.yml

      Parameters:
      sec - a valid configuration section
      message - a basic message to show
    • Webhook

      public Webhook(@NotNull @NotNull org.bukkit.configuration.ConfigurationSection sec)
      Create a Discord webhook setup using a default configuration section with no message to display.

      Make sure the section looks something like this: webhook.yml

      Parameters:
      sec - a valid configuration section
  • Method Details

    • send

      public boolean send(String token, String message)
      Sends the webhook. If the webhook is null or isn't enabled, won't send anything.

      If any error happens when connecting to its url, will print an error in the console.

      Parameters:
      token - a token
      message - a message if no message was declared in the constructor
      Returns:
      true if was correctly sent, false otherwise
    • send

      public boolean send(String message)
      Sends the webhook. If the webhook is null or isn't enabled, won't send anything.

      If any error happens when connecting to its url, will print an error in the console.

      Parameters:
      message - a message if no message was declared in the constructor
      Returns:
      true if was correctly sent, false otherwise
    • send

      public boolean send()
      Sends the webhook. If the webhook is null or isn't enabled, won't send anything.

      If any error happens when connecting to its url, will print an error in the console.

      Returns:
      true if was correctly sent, false otherwise
    • sendAsync

      public void sendAsync(String token, String message)
      Sends the webhook asynchronously. See send(String, String) for more info.
      Parameters:
      token - a token
      message - a message if no message was declared in the constructor
    • sendAsync

      public void sendAsync(String message)
      Sends the webhook asynchronously. See send(String) for more info.
      Parameters:
      message - a message if no message was declared in the constructor
    • sendAsync

      public void sendAsync()
      Sends the webhook asynchronously. See send() for more info.