justinkluever / discord-webhook-builder
a simple and fluent builder for discord webhook messages with embeds or components v2
Package info
github.com/justinkluever/discord-webhook-builder
pkg:composer/justinkluever/discord-webhook-builder
Requires
- php: ^8.3
Requires (Dev)
- laravel/pint: ^v1.29.1
- pestphp/pest: ^4.7.3
- pestphp/pest-plugin-arch: ^4.0.2
- pestphp/pest-plugin-type-coverage: ^4.0.4
- phpstan/phpstan: ^2.2.2
- rector/rector: ^2.4.5
- symfony/var-dumper: ^7.0.0|^8.0.0
This package is auto-updated.
Last update: 2026-06-15 02:35:04 UTC
README
A simple discord webhook builder.
This package only provides a fluent way of building the payload, you still have to send it yourself currently.
Note
Components that are not supported by the simple discord webhook endpoint may be missing or limited currently as they where not the primary goal of this package
you can install it via composer:
composer require justinkluever/discord-webhook-builder
Usage
Using this package should be simple:
use JustinKluever\DiscordWebhookBuilder\Components\TextDisplay; use JustinKluever\DiscordWebhookBuilder\Enums\Support\MessageFlag; use JustinKluever\DiscordWebhookBuilder\Support\Webhook\Embed; use JustinKluever\DiscordWebhookBuilder\Webhook; // Components V2 $webhook = Webhook::make() ->flag(MessageFlag::IS_COMPONENTS_V2) // Required for Components V2 by Discord ->component( TextDisplay::make('This is a Text Display!'), ); // Classic Webhooks $webhook = Webhook::make() ->content('Embed Test webhook') ->embed( Embed::make()->description('This is a Embed description'), )
After creating your webhook payload you can use your preferred way of POSTing:
// Laravel HTTP Client use Illuminate\Support\Facades\Http; Http::post('https://discord.com/api/webhooks/...', $webhook); // The Webhook builder implements Stringable for ease of use // Guzzle $client->post('https://discord.com/api/webhooks/...', [ 'json' => $webhook ]); // cURL $ch = curl_init('https://discord.com/api/webhooks/...'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $webhook); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch);
For more details on how to use specific Components check the Source or look at Discord's Documentation:
License
The MIT License (MIT). Please see License File for more information.