Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions src/Discord/Builders/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,36 +422,41 @@ public function getForward(): ?Message
/**
* Adds a component to the builder.
*
* @param ComponentObject $component Component to add.
* @param ComponentObject[]|ComponentObject $components Component to add.
*
* @throws \InvalidArgumentException Component is not a valid type.
* @throws \OverflowException Builder exceeds component limits.
*
* @return $this
*/
public function addComponent(ComponentObject $component): self
public function addComponent(Component ...$components): self
{
/*
if (! in_array($component::USAGE, ['Message'])) {
throw new \InvalidArgumentException('Invalid component type for messages.');
}
*/

if ($component instanceof Interactive) {
$component = ActionRow::new()->addComponent($component);
}

if ($component instanceof ComponentV2) {
$this->setV2Flag();
}

if ($this->flags & Message::FLAG_IS_COMPONENTS_V2) {
$this->enforceV2Limits();
} else {
$this->enforceV1Limits($component);
}

$this->components ??= [];

foreach ($components as $component) {
if (! $component instanceof ComponentObject) {
throw new \InvalidArgumentException('You can only add component objects to a message.');
}
/*
if (! in_array($component::USAGE, ['Message'])) {
throw new \InvalidArgumentException('Invalid component type for messages.');
}
*/

if ($component instanceof Interactive) {
$component = ActionRow::new()->addComponent($component);
}

if ($component instanceof ComponentV2) {
$this->setIsComponentsV2Flag();
}

if ($this->flags & Message::FLAG_IS_COMPONENTS_V2) {
$this->enforceV2Limits();
} else {
$this->enforceV1Limits($component);
}
}

$this->components[] = $component;

Expand All @@ -469,13 +474,13 @@ public function addComponent(ComponentObject $component): self
* @return $this
*
* @since 10.19.0
*
* @deprecated 10.19.0 Use `MessageBuilder::addComponent()` instead.
*/
public function addComponents($components): self
{
foreach ($components as $component) {
$this->addComponent($component);
}

$this->addComponent(...$components);

return $this;
}

Expand Down Expand Up @@ -581,7 +586,7 @@ public function getComponents(): array
/**
* Adds a sticker to the builder. Only used for sending message or creating forum thread.
*
* @param string|Sticker $sticker Sticker to add.
* @param Sticker|string $sticker Sticker to add.
*
* @throws \OverflowException Builder exceeds 3 stickers.
*
Expand Down Expand Up @@ -625,7 +630,7 @@ public function removeSticker($sticker): self
/**
* Sets the stickers of the builder. Removes the existing stickers in the process.
*
* @param array $stickers New sticker ids.
* @param Sticker[]|string[] $stickers New sticker ids.
*
* @return $this
*/
Expand Down