12
SepDiscord Webhook is a fantastic package that helps you to generate beautiful discord messages and send them with webhook.
You can install this package via composer by running this command.
composer require florianrambur/discord-webhook
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',
]);
This package gives you the opportunity to work with a simple Embed
class that allows 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(),
],
]);
For more details and source code, please visit Github
Closing Note
The team of Codebrisk Laravel developers is always ready to execute even your boldest ideas. Our expert team can design and develop any type of custom CRM solution, SAAS app, or e-commerce app to meet our customer’s needs and transform our customer’s experiences. Get in touch with our team to discuss your bespoke ideas and learn more about the next steps to launching cooperation.
Published at : 12-09-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project