Skip to content

WebHookManager Guides

Wenox edited this page Oct 19, 2025 · 1 revision

WebHookManager

Overview

The WebHookManager class handles sending Discord webhooks asynchronously within the SkyblockCore plugin. It provides a static method to send rich embed messages to Discord channels via webhooks, supporting titles, descriptions, colors, thumbnails, footers, fields, and custom avatars.

Key Features

  • Send Discord webhook messages asynchronously using PocketMine's async pool.
  • Support for rich embeds with customizable elements.
  • Automatic validation of webhook URLs (must be HTTPS).
  • Error handling for invalid payloads and network issues.
  • Uses a dedicated async task (DiscordWebhookSendTask) for non-blocking execution.

Usage from Other Plugins

To use WebHookManager from another plugin:

  1. Add dependency in your plugin.yml:

    depend: [SkyblockCore]
    
  2. Import the class:

    use Biswajit\Core\Managers\WebHookManager;
  3. Call the static sendWebhook method with required parameters.

Method Signature

public static function sendWebhook(
    string $url,
    string $title,
    string $description,
    string $username,
    string $color = '00ff00',
    ?string $thumbnail = null,
    ?string $footer = null,
    ?array $fields = null,
    ?string $avatar = null
): void

Parameters

  • $url (string): The Discord webhook URL. Must start with "https://".
  • $title (string): The title of the embed.
  • $description (string): The description text of the embed.
  • $username (string): The username to display for the webhook.
  • $color (string, optional): Hex color code for the embed (default: '00ff00' for green).
  • $thumbnail (string, optional): URL of the thumbnail image.
  • $footer (string, optional): Footer text for the embed.
  • $fields (array, optional): Array of fields to add to the embed. Each field should be an associative array with 'name' and 'value' keys.
  • $avatar (string, optional): URL of the avatar image (default: a predefined image).

Example Usage

// Basic webhook
WebHookManager::sendWebhook(
    "https://discord.com/api/webhooks/1234567890/abcdef",
    "Server Started",
    "The server has started successfully.",
    "SkyblockCore Bot"
);

// Advanced webhook with fields and thumbnail
WebHookManager::sendWebhook(
    "https://discord.com/api/webhooks/1234567890/abcdef",
    "Player Achievement",
    "Player has reached a new milestone!",
    "SkyblockCore Bot",
    "ff0000",
    "https://example.com/thumbnail.png",
    "Powered by SkyblockCore",
    [
        ["name" => "Player", "value" => "Steve", "inline" => true],
        ["name" => "Achievement", "value" => "First Island", "inline" => true]
    ],
    "https://example.com/avatar.png"
);

Important Notes

  • Webhooks are sent asynchronously to avoid blocking the main thread.
  • Invalid URLs or malformed payloads will log warnings but not throw exceptions.
  • The default avatar is "https://i.imgur.com/jjwlRAI.png" if none is provided.
  • Color is converted from hex string to decimal using hexdec().
  • The embed includes a timestamp and default footer if not specified.
  • Uses cURL for HTTP requests with SSL verification disabled for compatibility.

Dependencies

  • Relies on DiscordWebhookSendTask for async execution.
  • Requires PocketMine's async pool for task submission.

Version Information

  • Package: Biswajit\Core\Managers
  • Author: Biswajit
  • Version: 0.1.4
  • API Version: 5.30.0

Clone this wiki locally