From f0c2ce76697e3b84eef19ec1c79f461e4b3593fd Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 21 Jul 2024 11:52:37 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Support=20o?= =?UTF-8?q?ver=205=20buttons=20in=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Discord/Message.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Discord/Message.php b/src/Discord/Message.php index 899235c..847733f 100644 --- a/src/Discord/Message.php +++ b/src/Discord/Message.php @@ -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()) { @@ -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(); } /**