diff --git a/src/Console/Commands/BootCommand.php b/src/Console/Commands/BootCommand.php index 2c01427..045b8b5 100644 --- a/src/Console/Commands/BootCommand.php +++ b/src/Console/Commands/BootCommand.php @@ -2,6 +2,7 @@ namespace Laracord\Console\Commands; +use Illuminate\Console\Command; use Illuminate\Support\Str; class BootCommand extends Command @@ -12,7 +13,9 @@ class BootCommand extends Command * @var string */ protected $signature = 'bot:boot - {--no-migrate : Boot without running database migrations}'; + {--no-migrate : Boot without running database migrations} + {--bot_name= : The name of the bot} + {--bot_token= : The token of the bot}'; /** * The description of the command. @@ -28,12 +31,33 @@ class BootCommand extends Command */ public function handle() { + // Run migrations unless --no-migrate is specified if (! $this->option('no-migrate')) { $this->callSilent('migrate', ['--force' => true]); } - $this->app->singleton('bot', fn () => $this->getClass()::make($this)); + // Retrieve bot name and token from options or environment + $botName = $this->option('bot_name') ?? config('discord.description'); + $botToken = $this->option('bot_token') ?? config('discord.token'); + // Check if bot token is provided + if (empty($botToken)) { + $this->error('Bot token is required.'); + + return; + } + + // Set the bot name and token in the environment dynamically + config(['discord.description' => $botName, 'discord.token' => $botToken]); + + // Create the bot instance using singleton with the bot name and token + $this->app->singleton('bot', function () { + $botClass = $this->getClass(); + + return $botClass::make($this, config('discord.description'), config('discord.token')); + }); + + // Boot the bot $this->app->make('bot')->boot(); }