Skip to content

Commit

Permalink
📝 Add missing documentation (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Jun 26, 2024
2 parents 297ec16 + 8698541 commit a54e233
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 11 deletions.
8 changes: 8 additions & 0 deletions content/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ For convenience, Laracord comes with a console command to set a specified user a
$ php laracord bot:admin <id>
```

### Tinker (REPL)

Laracord comes with full support for [Tinker](https://github.com/laravel/tinker) out of the box.

```sh
$ php laracord tinker
```

### Additional Commands

To view all built-in console commands, you can run the `list` command:
Expand Down
45 changes: 34 additions & 11 deletions content/docs/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,36 @@ This gives you a sensibly styled embed with the username and avatar of your bot.

![Simple Message](/images/simple-message.png)

To send a plain message without an embed, you may pass your content to the `->body()` method:
### Replying to Messages

When sending messages, an easy way to improve user experience is to have the bot reply to a user when responding to their commands/input instead of just sending the message openly into the channel.

To do this, you must have some sort of context to respond to whether it be an existing message or interaction.

```php
$this
->message()
->body('Hello world!');
->message('Hello to you!')
->reply($message|$interaction);
```

## Direct Usage
### Editing Messages

When `$this->message()` is not available in your class, you can typically access and make `Message` directly:
Similar to replying, Laracord also lets you easily edit existing messages and interactions.

```php
use Laracord\Discord\Message;
$this
->message('Nevermind...')
->edit($message|$interaction);
```

Under the hood, this will update an existing interaction message using `$interaction->updateMessage()` or an existing message using `$message->edit()`.

Another common scenario you might run into is the need to edit an existing message if it is owned by the bot otherwise replying instead.

Message::make()->content('Hello world!');
```php
$this
->message('Hello world')
->editOrReply($message|$interaction);
```

## Available Methods
Expand All @@ -69,7 +83,6 @@ Message::make()->content('Hello world!');
- [Select Menus](#content-select-menus)
- [Menu Types](#content-menu-types)


### Title

Set the title of the embed:
Expand All @@ -82,7 +95,7 @@ $this

### URL

Set the url of the title:
Set the URL of the title:

```php
$this
Expand All @@ -103,14 +116,24 @@ $this

### Body

Set the body of the embed, that send a message before the embed:
The message body in Laracord refers to a message's generic content outside of the stylized embed that Laracord uses by default. This is otherwise the typical format that messages are sent and received on Discord.

One limitation of stylizing message output as an embed is the inabiliity to send a notification to a user/role when mentioning them. One way to remedy this is to pass the mention into `->body()` making it appear above the embed in a mostly non-invasive way:

```php
$this
->message('Hello world!')
->body('@everyone');
```

There may be a time where you do not want Laracord to send your message using an embed. In this case, simply pass your message content using `->body()` without specifying a message directly to `->message()` or `->content()`:

```php
$this
->message()
->body('Hello world!');
```

### Username

By default, this is the username of your bot application.
Expand Down Expand Up @@ -405,4 +428,4 @@ $this
->select(type: 'mentionable', route: 'handleMentionable')
->select(type: 'role', route: 'handleRole')
->select(type: 'user', route: 'handleUser');
```
```
62 changes: 62 additions & 0 deletions content/docs/slash-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,65 @@ To retrieve all flattened option values, you can simply omit passing a key:
```php
$values = $this->value();
```

## Command Autocomplete

When asking for input from commands like the channel `id` above for `/ticket set channel <id>`, Laracord allows you to easily provide autocomplete results to assist the user.

> #### Note
>
> Autocomplete choices may only contain up to 25 items at a time and will automatically be limited.
How you can approach this is rather flexible and any command/subcommand can be targeted using dot-notation.

In it's simplest form, you may pass a simple array of options to autocomplete to:

```php
/**
* Set the autocomplete choices.
*/
public function autocomplete(): array
{
return [
'set.channel.id' => [
'00000',
'11111',
],
];
}
```

By default, Laracord will automatically handle creating slug values out of passed options. To control the label and value yourself, you may pass them using key value pairs:

```php
/**
* Set the autocomplete choices.
*/
public function autocomplete(): array
{
return [
'set.channel.id' => [
'General Chat' => '00000',
'Staff Chat' => '11111'
],
];
}
```

For dynamic autocomplete choices, you may pass a callback instead consisting of the current state of the command interaction and the value they currently have entered:

```php
use Discord\Parts\Interactions\Interaction;

/**
* Set the autocomplete choices.
*/
public function autocomplete(): array
{
return [
'set.channel.id' => fn (Interaction $interaction, mixed $value) => $value
? TicketChannel::where('channel_id', 'like', "%{$value}%")->take(25)->pluck('channel_id')
: TicketChannel::take(25)->pluck('channel_id'),
];
}
```

0 comments on commit a54e233

Please sign in to comment.