nozell/webhookapi

A PocketMine-MP Virion to easily send messages via Discord Webhooks

v1.0.0 2024-10-11 14:38 UTC

This package is auto-updated.

Last update: 2025-07-11 16:31:42 UTC


README

#DiscordWebhookAPI

馃帀 Join the BlockForDevs Discord Community! 馃帀

馃憠 Click Here to Join Now! 馃憟

DiscordWebhookAPI

A PocketMine-MP Virion to easily send messages via Discord Webhooks

Una Virion para PocketMine-MP para enviar mensajes f谩cilmente mediante Discord Webhooks

馃帀 Installation / Instalaci贸n

Installation is easy. You may get a compiled .phar here or integrate the virion itself into your plugin.
La instalaci贸n es f谩cil. Puedes obtener un .phar compilado aqu铆 o integrar directamente el virion en tu plugin.

This virion is purely object-oriented. To use it, you'll need to import the Webhook, Message, and optionally, the Embed object (if needed).
Esta API es completamente orientada a objetos. Para usarla, deber谩s importar los objetos Webhook, Message, y opcionalmente, Embed si es necesario.

馃洜 Basic Usage / Uso b谩sico

Import the classes / Importar las clases

To use this API in your code, you'll need to import the following classes:
Para usar esta API en tu c贸digo, necesitar谩s importar las siguientes clases:

<?php
use CortexPE\DiscordWebhookAPI\Message;
use CortexPE\DiscordWebhookAPI\Webhook;
use CortexPE\DiscordWebhookAPI\Embed; // optional / opcional

Construct a Webhook object / Crear un objeto Webhook

You'll need the Webhook URL. For more information on how to create Discord webhooks, click here.
Necesitar谩s la URL del Webhook. Para m谩s informaci贸n sobre c贸mo crear webhooks en Discord, haz clic aqu铆.

$webHook = new Webhook("YOUR WEBHOOK URL");

Construct a Message object / Crear un objeto Message

You must create a new Message object for each message you want to send.
Deber谩s crear un nuevo objeto Message para cada mensaje que desees enviar.

$msg = new Message();
$msg->setUsername("USERNAME"); // optional / opcional
$msg->setAvatarURL("https://cortexpe.xyz/utils/kitsu.png"); // optional / opcional
$msg->setContent("INSERT TEXT HERE"); // optional. Max length 2000 characters / opcional. M谩ximo 2000 caracteres

Send the message / Enviar el mensaje

Now you can send the message using the send() method. This will schedule an AsyncTask to avoid blocking the main thread.
Ahora puedes enviar el mensaje usando el m茅todo send(). Esto programar谩 una AsyncTask para evitar bloquear el hilo principal.

$webHook->send($msg);

馃摝 Embeds

Before sending a message, you may want to add an embed. You can construct an Embed object and use Message->addEmbed() to include it.
Antes de enviar un mensaje, quiz谩 quieras agregar un embed. Puedes construir un objeto Embed y usar Message->addEmbed() para incluirlo.

$embed = new Embed();
$embed->setTitle("Embed Title Here");
$embed->setDescription("A very awesome description / Una descripci贸n muy genial");

You can also add a footer:
Tambi茅n puedes a帽adir un pie de p谩gina:

$embed->setFooter("Footer text / Texto del pie de p谩gina");

Finally, add the embed to the message:
Finalmente, agrega el embed al mensaje:

$msg->addEmbed($embed);

Example Code / C贸digo de ejemplo:

$webHook = new Webhook("YOUR WEBHOOK URL");
$msg = new Message();
$msg->setUsername("USERNAME");
$msg->setAvatarURL("https://cortexpe.xyz/utils/kitsu.png");
$msg->setContent("INSERT TEXT HERE");

$embed = new Embed();
$embed->setTitle("EMBED 1");
$embed->setColor(0xFF0000);
$msg->addEmbed($embed);

$embed = new Embed();
$embed->setTitle("EMBED 2");
$embed->setColor(0x00FF00);
$embed->setAuthor("AUTHOR", "https://CortexPE.xyz", "https://cortexpe.xyz/utils/kitsu.png");
$embed->setDescription("Lorem ipsum dolor sit amet.");
$msg->addEmbed($embed);

$webHook->send($msg);

This API was made with 鉂わ笍 by CortexPE updated by Nozell. Enjoy!~ :3
Esta API fue hecha con 鉂わ笍 por CortexPE actualizado por Nozell. 隆Disfr煤tala!~ :3