tassilo/discord-webhooks

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple PHP library to execute Discord webhooks.

dev-master 2020-06-28 19:09 UTC

This package is auto-updated.

Last update: 2021-10-28 21:59:36 UTC


README

A simple, single-file PHP library to execute Discord webhooks.

Example

Firstly, you need to include the DiscordWebhooks.php file. Change the path to wherever you store it.

include(__DIR__ . '/DiscordWebhooks.php');
const URL = 'https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}';

You can quickly execute a webhook using a chain syntax:

// Chain Syntax
(new DiscordWebhook())->setContent('A chained webhook!')->execute(URL);

You can also execute more complex webhooks like below:

$webhook = new DiscordWebhook();
$webhook->setContent('Hello World!');
$webhook->setUsername('Octocat');
$webhook->setAvatarURL('https://github.githubassets.com/images/modules/logos_page/Octocat.png');

$embed = new DiscordWebhookEmbed();
$embed->setTitle('This is the title!');
$embed->setDescription('And this is the description! It supports **Markdown**!');
$embed->setURL('https://github.com/');
$embed->setTimestamp(time());
$embed->setColor(255, 0, 0);
$embed->setFooter('Posted by the cool Octocat!', 'https://github.githubassets.com/images/modules/logos_page/Octocat.png');
$embed->setThumbnail('https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png');
$embed->setImage('https://github.githubassets.com/images/modules/logos_page/GitHub-Logo.png');
$embed->setAuthor('Pikachuuuu', 'https://github.com/TASSIA710', 'https://avatars1.githubusercontent.com/u/38081490');

$embed->addField(new DiscordWebhookEmbedField('Cool field!', 'This is a very cool field. **Markdown** is supported here aswell.'));
$embed->addField(new DiscordWebhookEmbedField('2nd cool field!', 'These two fields', true));
$embed->addField(new DiscordWebhookEmbedField('3rd cool field!', 'are inline!', true));
$webhook->addEmbed($embed);

echo $webhook->execute(URL);

Requirements

This library requires the following extensions to be installed:

  • curl
  • json