Skip to content

Commit

Permalink
📝 Add docs for State
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Jan 31, 2024
1 parent db56909 commit 1f611f0
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions content/docs/state.md
Original file line number Diff line number Diff line change
@@ -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();
```

0 comments on commit 1f611f0

Please sign in to comment.