PHP code example of atakde / discord-webhook-php

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

    

atakde / discord-webhook-php example snippets




use Atakde\DiscordWebhook\DiscordWebhook;
use Atakde\DiscordWebhook\Message\MessageFactory;

$messageFactory = new MessageFactory();
$textMessage = $messageFactory->create('text');
$textMessage->setUsername("John Doe");
$textMessage->setContent("Hello World!");

$webhook = new DiscordWebhook($textMessage);
$webhook->setWebhookUrl("https://discord.com/api/...");
$webhook->send();


$embedMessage = $messageFactory->create('embed');
$embedMessage->setAvatarUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setContent("Hello World!");
$embedMessage->setUsername("John Doe");
$embedMessage->setTitle("Title");
$embedMessage->setDescription("Description");
$embedMessage->setUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setColor(0x00ff00);
$embedMessage->setTimestamp(date("Y-m-d", strtotime("now")));
$embedMessage->setFooterIcon("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setFooterText("Footer Text");
$embedMessage->setImageUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setThumbnailUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setAuthorName("Author Name");
$embedMessage->setAuthorUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setAuthorIcon("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setFields([
    [
        'name' => 'Field 1',
        'value' => 'Value 1',
        'inline' => true
    ],
    [
        'name' => 'Field 2',
        'value' => 'Value 2',
        'inline' => false
    ]
]);

$webhook = new DiscordWebhook($embedMessage);
$webhook->setWebhookUrl("https://discord.com/api/...");
$webhook->send();

$messageFactory = new MessageFactory();
$fileMessage = $messageFactory->create('file');
$fileMessage->setUsername('Atakde');
$fileMessage->setContent('Hello World!');
$fileMessage->setAvatarUrl('https://avatars.githubusercontent.com/u/25267804?v=4');
$fileMessage->setTts(false);
$fileMessage->setFileFromURL('https://avatars.githubusercontent.com/u/25267804?v=4');

$webhook = new DiscordWebhook($fileMessage);
$webhook->setWebhookUrl("https://discord.com/api/...");
$webhook->send();
bash 
composer