A wrapper for the official Discord REST, gateway and voice APIs.
Project is currently being revived so please check out any Github issues. The develop branch is the most stable at the moment.
- Can I run DiscordPHP on a webserver (e.g. Apache, nginx)?
- No, DiscordPHP will only run in CLI. If you want to have an interface for your bot you can integrate react/http with your bot and run it through CLI.
- PHP is running out of memory?
- Try increase your memory limit using
ini_set('memory_limit', '-1');.
- Try increase your memory limit using
DiscordPHP is installed using Composer. Make sure you have installed Composer and are used to how it operates. We require a minimum PHP version of PHP 7.0. PHP 7.1 will be required in the near future.
- Run
composer require team-reflex/discord-php. This will install the lastest release.- If you would like, you can also install the development branch by running
composer require team-reflex/discord-php dev-develop.
- If you would like, you can also install the development branch by running
- Include the Composer autoload file at the top of your main file:
include __DIR__.'/vendor/autoload.php';
- Make a bot!
<?php
include __DIR__.'/vendor/autoload.php';
use Discord\Discord;
$discord = new Discord([
'token' => 'bot-token',
]);
$discord->on('ready', function ($discord) {
echo "Bot is ready!", PHP_EOL;
// Listen for messages.
$discord->on('message', function ($message, $discord) {
echo "{$message->author->username}: {$message->content}",PHP_EOL;
});
});
$discord->run();Raw documentation can be found in-line in the code and on the DiscordPHP Class Reference. More user friendly and examples will soon be coming on the DiscordPHP Wiki.
We are open to contributions. However, please make sure you follow our coding standards (PSR-4 autoloading and custom styling). Please run php-cs-fixer before opening a pull request by running composer run-script cs.
MIT License, © David Cole and other contributers 2016--present.