composer require enlumop/discord-webhook-client
<?php
use Enlumop\DiscordWebhooks\Embed;
use Enlumop\DiscordWebhooks\Payload;
use Enlumop\DiscordWebhooks\WebhookClient;
// Create embed
$embed = new Embed();
$embed->setDescription('This is an embed'); // with description
$url = 'DISCORD_WEBHOOK_URL'; // Put your discord webhook url
// Create Payload
$payload = new Payload();
$payload->setUsername('Example Webhook Bot') // Change discord bot webhook username
->setMessage('This is a message') // Some text before embed
->addEmbed($embed) // Add embed
;
// New discord webhook client
$webhook = new WebhookClient();
// Send message
$webhook->send($url, $payload);
The project is MIT licensed. To read the full license, open LICENSE.md.
Pull requests and issues are open!
<?php
use Enlumop\DiscordWebhooks\Payload;
use Enlumop\DiscordWebhooks\WebhookClient;
$url = 'DISCORD_WEBHOOK_URL'; // Put your discord webhook url
// Create Payload
$payload = new Payload();
$payload->setMessage('This is a message'); // Some text. If You need use the Message Builder
// New discord webhook client
$webhook = new WebhookClient();
// Send message
$webhook->send($url, $payload);
<?php
use Enlumop\DiscordWebhooks\Builder\TextFormattingCombine;
use Enlumop\DiscordWebhooks\Builder\TextMessageBuilder;
use Enlumop\DiscordWebhooks\Payload;
use Enlumop\DiscordWebhooks\WebhookClient;
$url = 'DISCORD_WEBHOOK_URL'; // Put your discord webhook url
// Builder with on auto-newline mode (to disable auto-newline use new TextMessageBuilder(false))
$messageBuilder = new TextMessageBuilder();
$message = $messageBuilder->addText('<@ROLE_ID>') // ping some role
->addText('How are you?') // some text without format
->addBold("It's time for new webhook tool!") // **Text with bold**
/**
* Text with multiline codeblock:
* ```php
* // It's can using codeblock
* ```
*/
->addMultilineCodeBlock("// It's can using codeblock", 'php')
->addQuoteBlock('And some quote!') // > Text with quote block
->addCombineTextFormatting(
"It's awesome!!!111oneone",
(new TextFormattingCombine())
->withBold()
->withItalic()
->withUnderline()
) // ***__Text with: Bold, Italic and Underline__***
->addText('Are you reade for this??')
->build() // build message (it was returned string)
;
// Create Payload
$payload = new Payload();
// Set message
$payload->setMessage($message);
// Send message
$webhook = new WebhookClient();
$webhook->send($url, $payload);
You can also use Message Builder with embed e.g. to field or description
If you want to see the rest of the documentation and examples, please click HERE