3 namespace App\Console\Commands;
6 use Discord\Parts\Channel\Message;
7 use Discord\WebSockets\Event;
8 use Illuminate\Console\Command;
9 use Monolog\Handler\StreamHandler;
11 use React\EventLoop\Loop;
13 class DiscordBotCommand extends Command
16 * The name and signature of the console command.
20 protected $signature = 'discord:bot';
23 * The console command description.
27 protected $description = 'Runs the discord bot';
30 * Execute the console command.
34 public function handle()
36 $logger = new Logger('DiscordBot');
37 $logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
38 $discord = new Discord([
40 'token' => config('discord.token'),
42 $discord->on('ready', function (Discord $discord) {
43 $discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
44 if (!empty($message->guild_id)) return;
45 if (!empty($message->webhook_id)) return;
46 if (!empty($message->application_id)) return;
47 if (is_null($message->author)) return;
48 if ($message->author->bot) return;
49 $discord->getLoop()->addTimer(0.6, function() use ($message) {
50 $message->react('😄');
52 if (!is_null($message->channel)) {
53 $discord->getLoop()->addTimer(2.0, function() use ($message) {
54 $message->channel->sendMessage('bugger off');
57 $message->delayedReply('bugger off', 2000);
61 $discord->getLoop()->addSignal(SIGINT, function() use ($discord) {