Getting Started

Start the bot

$ php bot.php
<?php

require('vendor/autoload.php');

use \HobsRkm\SDK\PHPDiscordSDK\PHPDiscordSDKFactory;

class Bot {

    public function start() {
        PHPDiscordSDKFactory::getInstance()
            ->botConnect(<<<<BOT TOKEN>>>>>)
            ->then(
                function ($bot) {
                    $bot->on('message', function ($event) {
                        PHPDiscordSDKFactory::getInstance()
                        ->formatEvent($event)->then(function($message){
                        //Bot Event Listener
                        //call other APIs
                            print_r($message);//prints server details
                        }, function ($reason) {
                        //message event errors
                    });
                     $bot->on('close', function ($event) {
                       $this->start();
                    });
                });
            },
            function ($reason) {
            //other errors, bot startup, authentication
            }
        );
    }
}

$bot = new Bot();
$bot->start();

Visit https://github.com/hobsRKM/DiscordAPIWeb for all the APIs Demo

Try out all the APIs in real-time at https://discordapidemo.com

Last updated

Was this helpful?