-
-
Notifications
You must be signed in to change notification settings - Fork 240
Button
Federico edited this page Jan 21, 2023
·
1 revision
Buttons are a part of Component.
use Discord\Builders\Components\Button;
For this it is mandatory to use the ActionRow class.
To send a Message you must have the Channel object!
Create a button with a text
// REMEMBER THIS -> Discord\Builders\Components\ActionRow
// First we create a MessageBuilder
$builder = MessageBuilder::new();
// Now we create an actionRow instance
$action = ActionRow::new()
// Let's create the button
$button = Button::new(Button::STYLE_PRIMARY)->setLabel('Click me!')->setListener(function (Interaction $interaction) {
// CODE...
$interaction->respondWithMessage(MessageBuilder::new()->setContent("{$interaction->user} You clicked the button!"));
}, $discord);
$channel->sendMessage($builder->addComponent($action->addComponent($button)))->then(function (Message $message) {
echo "Message sent in the channel {$message->channel->id}";
});
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