PHP code example of forien / discord-webhooks
1. Go to this page and download the library: Download forien/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/ */
forien / discord-webhooks example snippets
// dispatcher manages building and sending webhooks
$dispatch = \Forien\WebhookDispatcher::getInstance();
// to create new Webhook object you can use either:
$webhook = $dispatch->createWebhook();
// or:
$webhook = new \Forien\DiscordHelpers\Webhook();
$webhook->setContent('some basic text');
$embed = $webhook->addEmbed();
$embed->addAuthor(['name' => 'Forien', 'icon_url' => '/*...*/']);
$embed->addField()->setName('name')->setValue('value');
$embed->addField()->setName('name2')->setValue('value2');
$embed->setColor('#cba');
// you can either add Hooks (Discord webhook urls) through either:
$dispatch->addHook('https://...');
$dispatch->setHooks(['https://...', ...])
// you can send attach Webhook object to Dispatcher if you created it independly:
$dispatch->addWebhook($webhook);
// you can send all attached Webhook objects at once (every will be sent to every Hook):
$dispatch->send()
// you can also specify single webhook-hook:
$dispatch->send($webhook, $hook);