Skip to content
Federico edited this page Jan 21, 2023 · 1 revision

Buttons are a part of Component.

use Discord\Builders\Components\Button;

STYLE_DANGER

STYLE_LINK

STYLE_PRIMARY

STYLE_SECONDARY

STYLE_SUCCESS


Create a message with a 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}";
});
Clone this wiki locally