PHP code example of php-channels / discord-webhook

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

    

php-channels / discord-webhook example snippets


use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setUsername('My Bot')
    ->setContent('Hello World!')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path');
// ...

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message()
    ->setWebhook('https://discord.com/api/webhooks/your-webhook-path');
// ...

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setUsername('Your Name')
    ->setContent('Hello World!')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setUsername('My Bot')
    ->setContent('Hello World!')
    ->setAvatar('https://fake-avatar.com/avatar.png')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setContent('A simple text message you want to send!')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setEmbeds(['color' => '123456', 'title' => 'Embed content!'])
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setAuthor('Author Name')
    ->send();

// optional param $url
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setAuthor('Author Name', 'https://fake-author.com')
    ->send();

// optional param $icon_url
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setAuthor('Author Name', 'https://fake-author.com', 'https://fake-icon.com/icon.png')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setTitle('Your title here!')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setUrl('https://fake-url.com')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setDescription('Your description here!')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setColor('2450411')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setColor('info')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setField('Name', 'Value')
    ->send();

// optional param $inline
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setField('Name', 'Value', true)
    ->send();

// multiple fields
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setField('Name 1', 'Value 1')
    ->setField('Name 2', 'Value 2', true)
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setThumbnail('https://fake-thumb.com/thumb.png')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setImage('https://fake-image.com/image.png')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setFooter('Text to footer here!')
    ->send();

// optional param $icon_url
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setFooter('Text to footer here!', 'https://fake-icon.com/icon.png')
    ->send();

use PhpChannels\DiscordWebhook\Discord;
...
Discord::message('https://discord.com/api/webhooks/your-webhook-path')
    ->setUsername('Application Bot')
    ->setAvatarUrl('https://fake-avatar.com/avatar.png')
    ->setContent('Content here!')
    ->setColor('2450411')
    ->setTitle('Title here!')
    ->setDescription('Description here!')
    ->send();
sh
composer update php-channels/discord-webhook