Skip to content

Instantly share code, notes, and snippets.

@xDimGG
Last active June 9, 2021 15:49
Show Gist options
  • Save xDimGG/244e75099856333ade45ffa12fcbbbea to your computer and use it in GitHub Desktop.
Save xDimGG/244e75099856333ade45ffa12fcbbbea to your computer and use it in GitHub Desktop.
Populated Discord WebHook
<?php
$url = 'https://discordapp.com/api/webhooks/402545221445091348/Cu8aLPPtgGMTyINj-DOjy91NCdnDMKczdFmsJmO2u4I6l7fzyNV_YYtezwwU7QF4CkrD';
$image = 'https://via.placeholder.com/400x400';
$data = json_encode([
// These 2 should usually be left out
// as they will override whatever your
// users have set
// 'username' => 'Test WebHook',
// 'avatar_url' => $image,
'content' => 'Hello, world!',
'embeds' => [
[
'title' => 'My Title!',
'description' => 'My Description!',
'url' => 'https://example.com',
'color' => 0xFFFFFF,
'timestamp' => (new DateTime())->format('c'),
'author' => [
'name' => 'My Author!',
'url' => 'https://example.com',
'icon_url' => $image
],
'thumbnail' => [
'url' => $image
],
'footer' => [
'text' => 'Footer Text',
'icon_url' => $image
],
'image' => [
'url' => $image
],
'fields' => [
[
'name' => 'My First Field Name',
'value' => 'My First Field Value',
'inline' => true
],
[
'name' => 'My Second Field Name',
'value' => 'My Second Field Value',
'inline' => true
]
]
]
]
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
]);
echo curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment