From 1f611f0999f770a7dadb155045160a53147d242f Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 31 Jan 2024 03:49:56 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docs=20for=20State?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/docs/state.md | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 content/docs/state.md diff --git a/content/docs/state.md b/content/docs/state.md new file mode 100644 index 0000000..a68dd12 --- /dev/null +++ b/content/docs/state.md @@ -0,0 +1,54 @@ +--- +slug: state +title: 'State' +priority: 5 +group: Usage +--- + +Any class extended from Laracord's framework will typically have multiple methods available to access various components/state such as the Bot, Discord, and Console instances. + +## Accessing the Bot + +The `bot` instance in this context is the `Laracord` class instance that is initialized when booting the bot. This instance contains the event loop and boot logic. + +The `bot` instance is registered with the application container and can be accessed globally using `app()`: + +```php +$bot = app('bot'); +``` + +When inside of a class that extends Laracord, the `bot` instance will always be available on the `bot()` getter: + +```php +$bot = $this->bot(); +``` + +## Accessing Discord + +The Discord instance consists of the DiscordPHP client and can be used anywhere in the bot as long as you have access to the application container. + +When inside of a class that extends Laracord, the Discord instance is available using the `discord()` getter: + +```php +$channel = $this->discord()->getChannel('your-channel-id'); +``` + +If you need to access the Discord instance outside of Laracord, you can use the `bot` instance in the application container: + +```php +$discord = app('bot')->discord(); +``` + +## Accessing Console + +Console works the same way as the Discord instance. It is always available using the `console()` getter: + +```php +$this->console()->log('Hello world!'); +``` + +Or by using the application container: + +```php +$console = app('bot')->console(); +```