PHP code example of florianrambur / discord-webhook

1. Go to this page and download the library: Download florianrambur/discord-webhook library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

florianrambur / discord-webhook example snippets




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',
]);



$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',
    ]));



$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]);



(new Embed())
    ->add($body)
    ->add($footer);

(new Embed())->addMany([$body, $footer]);



$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(),
    ],
]);