-
-
Notifications
You must be signed in to change notification settings - Fork 240
Option_commands
FoxWorn3365 edited this page Jan 24, 2023
·
8 revisions
Options are part of Components.
use Discord\Parts\Interactions\Command\Option;
Add options to Slash Commands
In this case, the example proposed in the link above is used.
use Discord\Builders\CommandBuilder;
//...
$discord->application->commands->save($discord->application->commands->create(CommandBuilder::new()
->setName('greet')
->setDescriptions('Greet an user')
->addOption((new Option($discord))
->setName('user')
->setDescription('User to greet')
->setType(Option::USER)
->setRequired(true)
)
->toArray()
));
Then:
// Handle
$discord->listenCommand('greet', function (Interaction $interaction) {
$args = $interaction->data->options->toArray();
$interaction->respondWithMessage(MessageBuilder::new()->setContent('Hello, <@[' . $args['user']['value'] . '>!'));
});
If you want an Object:
// ...
$args = (object)$interaction->data->options->toArray();
// ..
ⓘ Note
If you need to easily recover the data instead of using the Collector you can do it like this BUT is not recommended, rather it is better to use the above method:$args = json_decode(json_encode($interaction->data->options));
Note: This wiki is currently Work In Progress. Consider reading the docs instead.
- Application Command (Slash based)
Command Client (Message based)
- Activity
- Application
- Guild
- Private Channel
- User
Components
-
ActionRow
- Buttons
- Option (commands)
- SelectMenu
- TextInput
Builders