Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 1.71 KB

Readme.md

File metadata and controls

64 lines (52 loc) · 1.71 KB

Discord-PHP

A PHP library that makes sending Discord webhooks easier. Supports plain-text messages and Discord embeds messages.

Installation

composer require woeler/phpdiscord

Usage

Sending a text message

$message = (new DiscordTextMessage())
    ->setContent('Hello World')
    ->setAvatar('https://example.com/avatar.png')
    ->setUsername('Webhook Test');

$webhook = new DiscordWebhook('https://discordapp.com/api/webhooks/SomeWebHook');
$messageData = $webhook->send($message);

Sending an embed message

$message = (new DiscordEmbedMessage())
    ->setContent('Hello World')
    ->setAvatar('https://example.com/avatar.png')
    ->setUsername('Webhook Test')
    ->setTitle('Hello Title')
    ->setDescription('Some nice description')
    ->addField('Field name', 'Field value')
    ->setImage('https://example.com/someimage.png');

$webhook = new DiscordWebhook('https://discordapp.com/api/webhooks/SomeWebHook');
$messageData = $webhook->send($message);

Updating a message

$messageId = '12345';
$message = (new DiscordTextMessage())
    ->setContent('Hello World')
    ->setAvatar('https://example.com/avatar.png')
    ->setUsername('Webhook Test');

$webhook = new DiscordWebhook('https://discordapp.com/api/webhooks/SomeWebHook');
$messageData = $webhook->update($messageId, $message);

Deleting a message

$messageId = '12345';

$webhook = new DiscordWebhook('https://discordapp.com/api/webhooks/SomeWebHook');
$webhook->delete($messageId);

Getting a message

$messageId = '12345';

$webhook = new DiscordWebhook('https://discordapp.com/api/webhooks/SomeWebHook');
$messageData = $webhook->get($messageId);

Ratelimits are automatically handled for all calls.