An API to interact with the popular text and voice service Discord.
- Chris Boden for the WebSocket client that is based off RatchetPHP/Pawl
Todo list is available in the TODO.md
file.
- If your bot is in a large number of guilds, PHP may crash because it has ran out of allocated memory. (200 guilds, 140mb memory usage and increases)
- You can increase the allocated memory by doing
ini_set('memory_limit', '{number-of-mb}M');
at the top of your bot file. Note: Change{number-of-mb}
to the number of megabytes.
- You can increase the allocated memory by doing
- If a guild has more than 250 members, only online members will be available.
<?php
include 'vendor/autoload.php';
use Discord\Discord;
use Discord\WebSockets\Event;
use Discord\WebSockets\WebSocket;
$discord = new Discord(':email', ':password');
$websocket = new WebSocket($discord);
$websocket->on(Event::MESSAGE_CREATE, function ($message, $discord, $new) {
echo "New message from {$message->author->username}: {$message->content}".PHP_EOL;
});
$websocket->run();
I have generated documentation which can be viewed here. The code is well documentated so feel free to read through it if you want.
If you have any questions feel free to message me on Discord which can be viewed below.
There is caching built into the API. By default, the time to live for an item in the cache is 300 seconds (5 minutes). If you would like to change that, do the following:
use Discord\Helpers\Guzzle;
Guzzle::setCacheTtl(:time);
If you would like to disable the cache, set the TTL to 0
.
If you need any help feel free to join the DiscordAPI Server and ask in the #php_discordphp
channel. Tag @Uniquoooo
if you need any help specific to the API.
You can find a comparison and list of all other Discord libraries over at the DiscordAPI Comparison Page (thanks @abalabahaha!)
We are open to anyone contributing as long as you follow our code standards. We use PSR-4 for our autoloading standard and PSR-2 for our code formatting standard. Please, if you send in pull requests follow these standards.