PHP code example of axl1232 / php-discord-webhook

1. Go to this page and download the library: Download axl1232/php-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/ */

    

axl1232 / php-discord-webhook example snippets


$message = (new Axl1232\PhpDiscordWebhook\Message())
    ->setContent('Hello world')
    ->setUsername('Test hook')
    ->setAvatarUrl('https://example.com/avatar.png');

$hook = new Axl1232\PhpDiscordWebhook\Webhook('https://discordapp.com/api/webhooks/test/hook');
$hook->send($message);

$message = (new Axl1232\PhpDiscordWebhook\Message())
    ->setContent('Hello world')
    ->setUsername('Test hook')
    ->setAvatarUrl('https://example.com/avatar.png')
    ->setFile('/path/to/file.png');

$hook = new Axl1232\PhpDiscordWebhook\Webhook('https://discordapp.com/api/webhooks/test/hook');
$hook->send($message);

$message = (new Axl1232\PhpDiscordWebhook\Message())
    ->setContent('Hello world')
    ->setUsername('Test hook')
    ->setAvatarUrl('https://example.com/avatar.png')
    ->addEmbed(
        (new Axl1232\PhpDiscordWebhook\Embed())
        ->setTitle('Test embed')
        ->setUrl('https://example.com/')
        ->setDescription('Some embed description')
        ->setImage(
            (new Axl1232\PhpDiscordWebhook\Embed\Image())
            ->setUrl('https://example.com/image.jpg')
        )
        ->setAuthor(
            (new Axl1232\PhpDiscordWebhook\Embed\Author())
            ->setName('Author')
            ->setUrl('https://example.com')
            ->setIconUrl('https://example.com/author_icon.png')
        )
        ->setColor(Axl1232\PhpDiscordWebhook\Tools\ColorHelper::FUSCHIA)
        ->setFooter(
            (new Axl1232\PhpDiscordWebhook\Embed\Footer())
            ->setText('Footer text')
            ->setIconUrl('https://example.com/footer_icon.png')
        )
        ->setTimestamp(new DateTime('-1 week'))
        ->setThumbnail(
            (new Axl1232\PhpDiscordWebhook\Embed\Thumbnail())
            ->setUrl('https://example.com/thumbnail.png')
        )
        ->addField(
            (new Axl1232\PhpDiscordWebhook\Embed\Field())
            ->setName('Field 1')
            ->setValue('Value 1')
        )
        ->addField(
            (new Axl1232\PhpDiscordWebhook\Embed\Field())
            ->setName('Field 2')
            ->setValue('Value 2')
        )
    );

$hook = new Axl1232\PhpDiscordWebhook\Webhook('https://discordapp.com/api/webhooks/test/hook');
$hook->send($message);