Created
June 24, 2024 02:02
-
-
Save v11ncent/0daac175e7dffa5984ea6b76a3f5b38f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include __DIR__ . '/vendor/autoload.php'; | |
use Discord\Discord; | |
use Discord\Parts\Channel\Message; | |
use Discord\WebSockets\Intents; | |
use Discord\WebSockets\Event; | |
// loads our .env | |
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); | |
$dotenv->load(); | |
// require our these .env variables to be set | |
$dotenv | |
->required(['UMPIRE_APPLICATION_ID', 'UMPIRE_PUBLIC_KEY', 'UMPIRE_TOKEN']) | |
->notEmpty(); | |
// .env variables for our bot | |
$botId = $_ENV['UMPIRE_APPLICATION_ID']; | |
$botKey = $_ENV['UMPIRE_PUBLIC_KEY']; | |
$botToken = $_ENV['UMPIRE_TOKEN']; | |
$discord = new Discord([ | |
'token' => $botToken, | |
'intents' => Intents::getDefaultIntents(), | |
]); | |
$discord->on('ready', function (Discord $discord) { | |
echo 'Bot is ready!', PHP_EOL; | |
// Listen for messages. | |
$discord->on(Event::MESSAGE_CREATE, function ( | |
Message $message, | |
Discord $discord, | |
) { | |
echo "{$message->author->username}: {$message->content}", PHP_EOL; | |
}); | |
}); | |
$discord->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment