PHP code example of snowrunescape / discord-bot-php

1. Go to this page and download the library: Download snowrunescape/discord-bot-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/ */

    

snowrunescape / discord-bot-php example snippets




use DiscordPHP\Discord;

$discord = new Discord("YOU_DISCORD_BOT_TOKEN");
$discord->run();

$discord->event->registerCommand(new Ping($discord));

$discord->event->registerEventHandler(new MESSAGE_CREATE($discord));

class Ping extends DiscordCommand
{
    public function getCommand()
    {
        return "!ping";
    }

    public function onInit()
    {
        Logger::Info("Starting command...");
    }

    public function run(array $event, array $args)
    {
        $this->discord->discordAPI->createMessage("Pong!", $event["channel_id"]);
    }
}

public function MESSAGE_CREATE($event)
{
    Logger::Info("This event handler has been called!");
}

class MESSAGE_CREATE extends DiscordEventHandler
{
    public function onInit() {
        Logger::Info("Starting eventHandler...");
    }

    public function run(array $event)
    {
        Logger::Info("This event handler has been called!");
    }
}

composer