PHP code example of jbdabes / discord-webhooks

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

    

jbdabes / discord-webhooks example snippets


$webhookURL = "https://discordapp.com/api/webhooks/my-webhook-url";

$jsonData = [
    "embeds" => [
        [
            "title" => "My Webhook Title",
            "description" => "My Webhook Description",
            "url" => "https://playersquared.com",
            "color" => 4433631,
            "timestamp" => date("Y-m-d\\TH:i:s.u\\Z"),
            "thumbnail" => [
                "url" => "https://cdn.discordapp.com/embed/avatars/0.png",
            ],
            "author" => [
                "name" => "JB",
                "url" => "https://playersquared.com/forums/members/jb/",
                "icon_url" => "https://cdn.discordapp.com/embed/avatars/4.png",
            ]
        ]
    ]
];

$ch = curl_init($webhookURL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($jsonData));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

$webhook = new \DiscordWebhooks\Webhook("https://discordapp.com/api/webhooks/my-webhook-url");
$embed   = new \DiscordWebhooks\Embeds\Embed();

$embed->setTitle("My Webhook Title")
    ->setDescription("My Webhook Description")
    ->setUrl("https://playersquared.com")
    ->setColor("#43a6df")
    ->setTimestamp($webhook->currentTimestamp());

$embed->thumbnail()->setUrl("https://cdn.discordapp.com/embed/avatars/0.png");
$embed->author()->setName("JB")
    ->setUrl("https://playersquared.com/forums/members/jb/")
    ->setIconUrl("https://cdn.discordapp.com/embed/avatars/4.png");

$webhook->embeds()->add($embed);
$webhook->send();