Skip to content

Dongu-Yapim/Discord-Webhooks-PHP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Webhooks Wrapper for PHP

A lightweight wrapper to interact with Discord webhooks!

Getting Started

This wrapper is installed by using Composer. You also need to have (at least) PHP 5.3 installed, along with ext-curl. This wrapper has not been tested with HHVM, but there's no reason it shouldn't work!

  1. Run composer require auroraari/discord-webhooks to install the latest release.
  2. Include the Composer autoload file at the top of your file:
    • include __DIR__.'/vendor/autoload.php';
  3. Enjoy!

Setting up a webhook in Discord

This currently only works in Discord's public test build, which can be found here for Windows and here for Mac.

  1. On a server you own (or have the "Manage Webhooks" permission on), open Server Settings, and select 'Webhooks' on the menu: Step 2

  2. Click the "Create Webhook" button and complete the form. The "Name" field and avatar that you set are the defaults, and may be overriden in this wrapper, but the channel you pick cannot be changed by the wrapper. You'll need a separate URL for each channel you want to post to. Step 2

  3. Copy the "Webhook URL," and use that when initializing the class.

  4. Enjoy!

Example

<?php
    include __DIR__.'/vendor/autoload.php';

    use \DiscordWebhooks\Client as DiscordWebhook;
    
    $discord = new DiscordWebhook('URL-FROM-DISCORD');
    $discord->name('AuroraAri'); // Optionally, provide a name that the message will be sent from. If not set, uses the name set in Discord.
    $discord->avatar('http://i.imgur.com/RNYMCQp.png'); // Optionally, a URL for the user's avatar. If not set, uses the avatar set in Discord.
    $discord->message('Hi, Discord!'); // Optionally, set the message to be sent here. If not set, uses the message in $this->send().
    $discord->send('Hi again, Discord!'); // If the message wasn't set in $this->message, it must be set here. This method sends the message.

About

A (really) lightweight wrapper to use Discord webhooks

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%