Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atakde/discord-webhook-php
A php package for sending message to discord with webhook.
https://github.com/atakde/discord-webhook-php
discord discord-api discord-bot discord-php discord-webhook discord-webhook-api discord-webhook-notifications discord-webhooks php php-discord webhook
Last synced: 20 days ago
JSON representation
A php package for sending message to discord with webhook.
- Host: GitHub
- URL: https://github.com/atakde/discord-webhook-php
- Owner: atakde
- License: mit
- Created: 2022-02-27T14:59:20.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-12T12:17:59.000Z (over 1 year ago)
- Last Synced: 2024-11-20T20:41:27.212Z (about 2 months ago)
- Topics: discord, discord-api, discord-bot, discord-php, discord-webhook, discord-webhook-api, discord-webhook-notifications, discord-webhooks, php, php-discord, webhook
- Language: PHP
- Homepage:
- Size: 55.7 KB
- Stars: 15
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# discord-webhook-php
A php package for sending message to discord with webhook. Supports both text and embed messages types.
## Installation
Install via composer
```bash
composer require atakde/discord-webhook-php
```## Usage (Text Message)
```php
require 'vendor/autoload.php';
use Atakde\DiscordWebhook\DiscordWebhook;
use Atakde\DiscordWebhook\Message\MessageFactory;$messageFactory = new MessageFactory();
$textMessage = $messageFactory->create('text');
$textMessage->setUsername("John Doe");
$textMessage->setContent("Hello World!");$webhook = new DiscordWebhook($textMessage);
$webhook->setWebhookUrl("https://discord.com/api/...");
$webhook->send();```
## Usage (Embed Message)
```php
$embedMessage = $messageFactory->create('embed');
$embedMessage->setAvatarUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setContent("Hello World!");
$embedMessage->setUsername("John Doe");
$embedMessage->setTitle("Title");
$embedMessage->setDescription("Description");
$embedMessage->setUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setColor(0x00ff00);
$embedMessage->setTimestamp(date("Y-m-d", strtotime("now")));
$embedMessage->setFooterIcon("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setFooterText("Footer Text");
$embedMessage->setImageUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setThumbnailUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setAuthorName("Author Name");
$embedMessage->setAuthorUrl("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setAuthorIcon("https://doodleipsum.com/700?i=f8b1abea359b643310916a38aa0b0562");
$embedMessage->setFields([
[
'name' => 'Field 1',
'value' => 'Value 1',
'inline' => true
],
[
'name' => 'Field 2',
'value' => 'Value 2',
'inline' => false
]
]);$webhook = new DiscordWebhook($embedMessage);
$webhook->setWebhookUrl("https://discord.com/api/...");
$webhook->send();
```## Usage (File Message)
```php
$messageFactory = new MessageFactory();
$fileMessage = $messageFactory->create('file');
$fileMessage->setUsername('Atakde');
$fileMessage->setContent('Hello World!');
$fileMessage->setAvatarUrl('https://avatars.githubusercontent.com/u/25267804?v=4');
$fileMessage->setTts(false);
$fileMessage->setFileFromURL('https://avatars.githubusercontent.com/u/25267804?v=4');$webhook = new DiscordWebhook($fileMessage);
$webhook->setWebhookUrl("https://discord.com/api/...");
$webhook->send();
```