Download the PHP package php-channels/discord-webhook without Composer
On this page you can find all versions of the php package php-channels/discord-webhook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-channels/discord-webhook
More information about php-channels/discord-webhook
Files in php-channels/discord-webhook
Package discord-webhook
Short Description Interface for quick and direct communication with Discord channels via Webhook.
License MIT
Informations about the package discord-webhook
PHP Discord Webhook
PHP package that contains a set of methods for simple, direct and elegant communication with Discord channels via Webhooks.
Composer
Install
Update
QA
Unit Tests
To run unit tests using PHPUnit:
PHP Stan
To run code static analysis using PHP Stan:
General
The main goal of this package is to allow highly customizable messages to be sent to Discord channels in a simple and semantic way via Webhooks. The base payload used to build the code can be accessed at ./documentation/payload.json
.
Basic Usage
1. Define Webhook
There are two ways which the destination webhook of the message can be defined. The first is to pass the URL of the webhook as parameter to the message (?string $webhook = null)
method, as in the example below:
Or the webhook can be set via the setWebhook (string $webhook)
method, as in the second example:
2. Username
The name of the sender of the message can be set using the setUsername (string $username)
method, as in the example below:
3. Avatar
The avatar of the sender of the message can be set using the setAvatar (string $avatar_url)
method, as in the example below:
4. Content
A simple text content of the message can be set using the setContent (string $content)
method, as in the example below:
5. Embeds
However, the message content can be enriched through the setEmbeds (array $embeds)
method, which takes an array as a parameter, enabling a wide range of customizations, as in the example below:
Working with Embeds
Working with embeds content through a single array that fully handles this property is very powerful and can certainly be very useful on many occasions. But it can get really confusing when we are working with a very large array of settings, making it difficult to read and maintain the code. To solve this problem methods for manipulating embeds were added to the package, which are described below.
1. Author
To handle the embeds[0]['author']
property, the setAuthor (string $name, ?string $url = '', ?string $icon_url = '')
method can be used, as in the examples below:
2. Title
To handle the embeds[0]['title']
property, the setTitle (string $title)
method can be used, as in the examples below:
3. URL
To handle the embeds[0]['url']
property, the setUrl (string $url)
method can be used, as in the examples below:
4. Description
To handle the embeds[0]['description']
property, the setDescription (string $description)
method can be used, as in the examples below:
5. Color
To handle the embeds[0]['color']
property, the setColor (string $color)
method can be used, as in the examples below:
Note: The color value should be a decimal number. We suggest to use this converter to convert hexadecimal values to decimal.
Or you can use setColor
method passing a string reference color
, as in the example below:
The possible color references are:
'info', 'error', 'notice', 'warning', 'success'
.
6. Fields
To add fields to embeds[0]['fields']
property, the setField (string $name, string $value, bool $inline = null)
method can be used, as in the examples below:
Note: This method can be invoked several times, each time adding a new field to the array.
7. Thumbnail
To add fields to embeds[0]['thumbnail']
property, the setThumbnail (string $thumbnail)
method can be used, as in the examples below:
8. Image
To add fields to embeds[0]['image']
property, the setImage (string $image)
method can be used, as in the examples below:
9. Footer
To add fields to embeds[0]['footer']
property, the setFooter (string $text, ?string $icon_url = '')
method can be used, as in the examples below:
Usage Example
Note: The above example is for documentation purposes only, and that all the methods presented in this file can be combined to send the message as you need.