Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Support over 5 buttons in messages (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Jul 21, 2024
1 parent ec1702b commit a3a1a0c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Discord/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ public function build(): MessageBuilder
}

if ($this->hasButtons()) {
$message->addComponent($this->getButtons());
foreach ($this->getButtons() as $button) {
$message->addComponent($button);
}
}

if ($this->hasFiles()) {
Expand Down Expand Up @@ -407,21 +409,23 @@ public function getComponents(): array
}

/**
* Get the buttons.
* Get the button components.
*/
public function getButtons()
public function getButtons(): array
{
if (! $this->hasButtons()) {
return;
return [];
}

$buttons = ActionRow::new();
return collect($this->buttons)->chunk(5)->map(function ($buttons) {
$row = ActionRow::new();

foreach ($this->buttons as $button) {
$buttons->addComponent($button);
}
foreach ($buttons as $button) {
$row->addComponent($button);
}

return $buttons;
return $row;
})->all();
}

/**
Expand Down

0 comments on commit a3a1a0c

Please sign in to comment.