laracord / framework

A Discord bot micro-framework powered by Laravel.
https://laracord.com
MIT License
33 stars 10 forks source link

✨Native option autocomplete support #95

Closed Alejandro-AP00 closed 4 months ago

Alejandro-AP00 commented 4 months ago

This PR adds a better syntax and the possibility to handle autocomplete within Slash Commands It provides 3 ways of syntax

Using a choice class

public function autocomplete(): array
    {
        return [
            'attribute' => fn ($interaction, $value) => [
                Choice::new($this->discord(), 'attribute', 'attribute'),
            ],
        ];
    }

Using key value pairs

public function autocomplete(): array
    {
        return [
            'attribute' => fn ($interaction, $value) => [
                'attribute' => 'attribute',
            ],
        ];
    }

Using just an array of strings, with this option the autocomplete handler takes the liberty of using the string to create a name for the choice slugified, this last option might be too opinionated but let me know your thoughts.

public function autocomplete(): array
    {
        return [
            'attribute' => fn ($interaction, $value) => [
                'attribute',
            ],
        ];
    }
Log1x commented 4 months ago

Great work! Let me know when you're ready for me to merge.

Alejandro-AP00 commented 4 months ago

Thanks, Ready when you are! Thanks for the support as well!