florianrambur / discord-webhook
1.2.1
2023-05-11 14:21 UTC
Requires
- php: >=7.2
- guzzlehttp/guzzle: ^7.3
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- larapack/dd: 1.*
- phpunit/phpunit: *
README
Installation
composer require florianrambur/discord-webhook
Usage
Here is a simple example
<?php use FlorianRambur\DiscordWebhook\Client; $config = [ 'url' => 'https://your-discord-webhook-url', 'author' => [ 'username' => 'Florian', 'avatar_url' => 'https://i.imgur.com/ZGPxFN2.jpg', ], ]; $client = new Client($config); $response = $client->send([ 'content' => 'This is the main content', ]);
Work with Embed
This package give you the opportunity to work with a simple Embed
class that allow you to create an advanced message. To do that, you can pass data into the constructor or use some methods like name($value)
<?php $embed = (new Embed()) ->add(new Author([ 'name' => 'This is the author', 'url' => 'https://github.com/florianrambur/discord-webhook', 'icon_url' => 'https://github.com/florianrambur/discord-webhook/icon.jpg', ])) ->add(new Body([ 'title' => 'Webhook Title', 'description' => 'Webhook Description', 'color' => 5814783, ])) ->add(new Image([ 'images' => ['https://i.imgur.com/ZGPxFN2.jpg'], ])) ->add(new Footer([ 'text' => 'This is the footer', 'timestamp' => '2021-07-06T22:00:00.000Z', ]));
<?php $author = (new Author()) ->name('This is the author') ->url('https://github.com/florianrambur/discord-webhook') ->iconUrl('https://github.com/florianrambur/discord-webhook/icon.jpg'); $body = (new Body()) ->title('Webhook Title') ->description('Webhook Description') ->color(5814783); $image = (new Image())->image('https://i.imgur.com/ZGPxFN2.jpg'); $footer = (new Footer()) ->text('This is the footer') ->timestamp('2021-07-06T22:00:00.000Z'); $embed = (new Embed())->addMany([$author, $body, $image, $footer]);
The Embed
provides two methods to add an attribute class
<?php (new Embed()) ->add($body) ->add($footer); (new Embed())->addMany([$body, $footer]);
Then, pass your data and your config to the Client
class
<?php $config = [ 'url' => 'https://your-discord-webhook-url', 'author' => [ 'username' => 'Florian', 'avatar_url' => 'https://i.imgur.com/ZGPxFN2.jpg', ], ]; $client = new Client($config); $response = $client->send([ 'embeds' => [ $embed->toArray(), ], ]);
What's next
This package is under development and few things are missing :
- some constraints on attributes are missing
- few templates will be created to give you the possibility to create a message easier and faster