laracord / framework

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

✨ Add native Select menu support (Fixes #85) #86

Closed Log1x closed 5 months ago

Log1x commented 5 months ago

This adds native select support the Laracord's message class. Very easy to use.

$this
    ->message('Pick a fruit!')
    ->select([
        'Apples' => 'apples',
        'Oranges' => 'oranges',
        'Bananas' => 'bananas',
    ], route: 'selectFruit', placeholder: 'Select a fruit...')
    ->send($message);

Getting selected values can be done through $interaction->data->values – an example using an interaction route:

public function interactions(): array
{
    return [
        'selectFruit' => fn (Interaction $interaction) => $interaction->acknowledge() && dump($interaction->data->values),
    ];
}

You can also easily create select menus for users, roles, channels, etc.

$this
    ->message('Pick a select, any select!')
    ->select(type: 'channel', route: 'handleChannel')
    ->select(type: 'mentionable', route: 'handleMentionable')
    ->select(type: 'role', route: 'handleRole')
    ->select(type: 'user', route: 'handleUser')
    ->send($message);

Documentation: https://laracord.com/docs/messages#content-select-menus