Button - discord-php/DiscordPHP GitHub Wiki
Buttons are a part of Component.
use Discord\Builders\Components\Button;
Methods
new()
getCustomId()
getEmoji()
getLabel()
getStyle()
getURL()
isDisabled()
setListener()
removeListener()
setCustomId()
setDisabled()
setEmoji()
setLabel()
setStyle()
setURL()
Styles
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}";
});