Skip to content

Instantly share code, notes, and snippets.

@mpociot
Last active March 25, 2021 18:48
Show Gist options
  • Save mpociot/d86ff15a07df107e04b8347e8a850905 to your computer and use it in GitHub Desktop.
Save mpociot/d86ff15a07df107e04b8347e8a850905 to your computer and use it in GitHub Desktop.
Discord + BotMan example

BotMan - Discord example chatbot

Once you set up your discord bot, you need to add it to your server:

Look up your chatbot's client ID and visit this URL:

https://discordapp.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot&permissions=0

Run the discord.php file through CLI:

php discord.php
<?php
use React\EventLoop\Factory;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\Drivers\Discord\DiscordDriver;
require_once 'vendor/autoload.php';
DriverManager::loadDriver(DiscordDriver::class);
$loop = Factory::create();
$botman = BotManFactory::createForDiscord([
'discord' => [
'token' => 'YOUR-TOKEN',
]
], $loop);
$botman->hears('hello', function($botman) {
$botman->reply('Hi there!');
});
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment