1. Go to this page and download the library: Download renzojohnson/discord-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
renzojohnson / discord-api example snippets
use RenzoJohnson\Discord\Discord;
$discord = new Discord('your-bot-token');
// Send a text message to a channel
$discord->sendMessage('CHANNEL_ID', 'Hello from PHP!');
use RenzoJohnson\Discord\Webhook\InteractionVerifier;
// Verify signature and get body
$body = InteractionVerifier::verify('YOUR_PUBLIC_KEY');
$interaction = json_decode($body, true);
// Respond to PING
if ($interaction['type'] === 1) {
InteractionVerifier::respondToPing();
}
use RenzoJohnson\Discord\Exception\AuthenticationException;
use RenzoJohnson\Discord\Exception\RateLimitException;
use RenzoJohnson\Discord\Exception\DiscordException;
try {
$discord->sendMessage('CHANNEL_ID', 'Hello');
} catch (AuthenticationException $e) {
// Invalid bot token (401)
} catch (RateLimitException $e) {
$retryAfter = $e->getRetryAfter(); // seconds (float)
} catch (DiscordException $e) {
// Other API errors
$errorData = $e->getErrorData();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.