'', // Put your Bot token here from https://discord.com/developers/applications/ ]); // Create a $browser with same loop as $discord $browser = new Browser(null, $discord->getLoop()); $discord->registerCommand('discordstatus', function (Message $message, $params) use ($discord, $browser) { coroutine(function (Message $message, $params) use ($discord, $browser) { // Ignore messages from any Bots if ($message->author->bot) return; try { // Make GET request to API of discordstatus.com $response = yield $browser->get('https://discordstatus.com/api/v2/status.json'); assert($response instanceof ResponseInterface); // Check if request succeed // Get response body $result = (string) $response->getBody(); // Uncomment to debug result $discord->logger->debug('Browser response', ['response' => $result]); // Parse JSON $discordstatus = json_decode($result); // Send reply about the discord status $message->reply('Discord status: ' . $discordstatus->status->description); } catch (Exception $e) { // Request failed // Uncomment to debug exceptions $discord->logger->error('Browser request failed', ['exception' => $e->getMessage()]); // Send reply about the discord status $message->reply('Unable to acesss the Discord status API :('); } }, $message, $params); }); // Start the Bot (must be at the bottom) $discord->run();