PHP code example of team-reflex / discord-php
1. Go to this page and download the library: Download team-reflex/discord-php 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/ */
team-reflex / discord-php example snippets
iscord\Discord;
use Discord\Parts\Channel\Message;
use Discord\WebSockets\Intents;
use Discord\WebSockets\Event;
$discord = new Discord([
'token' => 'bot-token',
'intents' => Intents::getDefaultIntents()
// | Intents::MESSAGE_CONTENT, // Note: MESSAGE_CONTENT is privileged, see https://dis.gd/mcfaq
]);
$discord->on('ready', function (Discord $discord) {
$discord->logger->info("Bot is ready!");
// Listen for messages.
$discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
// Note: MESSAGE_CONTENT intent must be enabled to get the content if the bot is not mentioned/DMed.
$discord->logger->info("{$message->author->username}: {$message->content}");
});
});
$discord->run();