Skip to content

Commit 3e0e337

Browse files
authored
Update flags for the Create Message endpoint (#1372)
discord/discord-api-docs@fa0ce16
1 parent 3697ae4 commit 3e0e337

File tree

2 files changed

+110
-13
lines changed

2 files changed

+110
-13
lines changed

src/Discord/Builders/MessageBuilder.php

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function addComponent(Component $component): self
443443
$component = ActionRow::new()->addComponent($component);
444444
}
445445

446-
if ($this->flags & Message::FLAG_IS_V2_COMPONENTS) {
446+
if ($this->flags & Message::FLAG_IS_COMPONENTS_V2) {
447447
$this->enforceV2Limits();
448448
} else {
449449
$this->enforceV1Limits($component);
@@ -775,27 +775,107 @@ public function getPoll(): ?Poll
775775
}
776776

777777
/**
778-
* Sets or unsets the V2 components flag for the message.
778+
* Sets or unsets the SUPPRESS_EMBEDS flag for the message.
779+
*
780+
* @since 10.19.0
781+
*
782+
* @param bool $enable
783+
* @return self
784+
*/
785+
public function setSuppressEmbedsFlag(bool $enable = true): self
786+
{
787+
if ($enable) {
788+
if (! ($this->flags & Message::FLAG_SUPPRESS_EMBEDS)) {
789+
$this->flags |= Message::FLAG_SUPPRESS_EMBEDS;
790+
}
791+
} elseif ($this->flags & Message::FLAG_SUPPRESS_EMBEDS) {
792+
$this->flags &= ~Message::FLAG_SUPPRESS_EMBEDS;
793+
}
794+
795+
return $this;
796+
}
797+
798+
/**
799+
* Sets or unsets the SUPPRESS_NOTIFICATIONS flag for the message.
800+
*
801+
* @since 10.19.0
802+
*
803+
* @param bool $enable
804+
* @return self
805+
*/
806+
public function setSuppressNotificationsFlag(bool $enable = true): self
807+
{
808+
if ($enable) {
809+
if (! ($this->flags & Message::FLAG_SUPPRESS_NOTIFICATIONS)) {
810+
$this->flags |= Message::FLAG_SUPPRESS_NOTIFICATIONS;
811+
}
812+
} elseif ($this->flags & Message::FLAG_SUPPRESS_NOTIFICATIONS) {
813+
$this->flags &= ~Message::FLAG_SUPPRESS_NOTIFICATIONS;
814+
}
815+
816+
return $this;
817+
}
818+
819+
/**
820+
* Sets or unsets the IS_VOICE_MESSAGE flag for the message.
821+
*
822+
* @since 10.19.0
823+
*
824+
* @param bool $enable
825+
* @return self
826+
*/
827+
public function setIsVoiceMessageFlag(bool $enable = true): self
828+
{
829+
if ($enable) {
830+
if (! ($this->flags & Message::FLAG_IS_VOICE_MESSAGE)) {
831+
$this->flags |= Message::FLAG_IS_VOICE_MESSAGE;
832+
}
833+
} elseif ($this->flags & Message::FLAG_IS_VOICE_MESSAGE) {
834+
$this->flags &= ~Message::FLAG_IS_VOICE_MESSAGE;
835+
}
836+
837+
return $this;
838+
}
839+
840+
/**
841+
* Sets or unsets the IS_COMPONENTS_V2 flag for the message.
842+
* Once a message has been sent with this flag, it can't be removed from that message.
843+
*
844+
* @deprecated 10.19.0 use `MessageBuilder::setIsComponentsV2Flag()` instead.
779845
*
780846
* @param bool $enable
781847
* @return self
782848
*/
783849
public function setV2Flag(bool $enable = true): self
850+
{
851+
return $this->setIsComponentsV2Flag($enable);
852+
}
853+
854+
/**
855+
* Sets or unsets the IS_COMPONENTS_V2 flag for the message.
856+
* Once a message has been sent with this flag, it can't be removed from that message.
857+
*
858+
* @since 10.19.0
859+
*
860+
* @param bool $enable
861+
* @return self
862+
*/
863+
public function setIsComponentsV2Flag(bool $enable = true): self
784864
{
785865
if ($enable) {
786-
if (! ($this->flags & Message::FLAG_IS_V2_COMPONENTS)) {
787-
$this->flags |= Message::FLAG_IS_V2_COMPONENTS;
866+
if (! ($this->flags & Message::FLAG_IS_COMPONENTS_V2)) {
867+
$this->flags |= Message::FLAG_IS_COMPONENTS_V2 ;
788868
}
789-
} elseif ($this->flags & Message::FLAG_IS_V2_COMPONENTS) {
790-
$this->flags &= ~Message::FLAG_IS_V2_COMPONENTS;
869+
} elseif ($this->flags & Message::FLAG_IS_COMPONENTS_V2) {
870+
$this->flags &= ~Message::FLAG_IS_COMPONENTS_V2;
791871
}
792872

793873
return $this;
794874
}
795875

796876
/**
797877
* Sets the flags of the message.
798-
* Only works for some message types and some message flags.
878+
* Only `SUPPRESS_EMBEDS`, `SUPPRESS_NOTIFICATIONS`, `IS_VOICE_MESSAGE`, and `IS_COMPONENTS_V2` can be set for the Create Message endpoint.
799879
*
800880
* @param int $flags
801881
*
@@ -912,7 +992,7 @@ public function jsonSerialize(): array
912992
$body = [];
913993

914994
if (isset($this->content)) {
915-
if (! ($this->flags & Message::FLAG_IS_V2_COMPONENTS)) {
995+
if (! ($this->flags & Message::FLAG_IS_COMPONENTS_V2)) {
916996
$body['content'] = $this->content;
917997
$empty = false;
918998
}
@@ -935,7 +1015,7 @@ public function jsonSerialize(): array
9351015
}
9361016

9371017
if (isset($this->embeds)) {
938-
if (! ($this->flags & Message::FLAG_IS_V2_COMPONENTS)) {
1018+
if (! ($this->flags & Message::FLAG_IS_COMPONENTS_V2)) {
9391019
$body['embeds'] = $this->embeds;
9401020
$empty = false;
9411021
}
@@ -968,14 +1048,14 @@ public function jsonSerialize(): array
9681048
}
9691049

9701050
if ($this->sticker_ids) {
971-
if (! ($this->flags & Message::FLAG_IS_V2_COMPONENTS)) {
1051+
if (! ($this->flags & Message::FLAG_IS_COMPONENTS_V2)) {
9721052
$body['sticker_ids'] = $this->sticker_ids;
9731053
$empty = false;
9741054
}
9751055
}
9761056

9771057
if (! empty($this->files)) {
978-
if (! ($this->flags & Message::FLAG_IS_V2_COMPONENTS)) {
1058+
if (! ($this->flags & Message::FLAG_IS_COMPONENTS_V2)) {
9791059
$empty = false;
9801060
}
9811061
}
@@ -986,7 +1066,7 @@ public function jsonSerialize(): array
9861066
}
9871067

9881068
if (isset($this->poll)) {
989-
if (! ($this->flags & Message::FLAG_IS_V2_COMPONENTS)) {
1069+
if (! ($this->flags & Message::FLAG_IS_COMPONENTS_V2)) {
9901070
$body['poll'] = $this->poll;
9911071
$empty = false;
9921072
}

src/Discord/Parts/Channel/Message.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,36 @@ class Message extends Part
183183
public const REFERENCE_DEFAULT = 0;
184184
public const REFERENCE_FORWARD = 1;
185185

186+
/** This message has been published to subscribed channels (via Channel Following). */
186187
public const FLAG_CROSSPOSTED = (1 << 0);
188+
/** This message originated from a message in another channel (via Channel Following). */
187189
public const FLAG_IS_CROSSPOST = (1 << 1);
190+
/** @deprecated Use `Message::FLAG_SUPPRESS_EMBEDS` instead. */
188191
public const FLAG_SUPPRESS_EMBED = (1 << 2);
192+
/** Do not include any embeds when serializing this message. */
193+
public const FLAG_SUPPRESS_EMBEDS = (1 << 2);
194+
/** The source message for this crosspost has been deleted (via Channel Following). */
189195
public const FLAG_SOURCE_MESSAGE_DELETED = (1 << 3);
196+
/** This message came from the urgent message system. */
190197
public const FLAG_URGENT = (1 << 4);
198+
/** This message has an associated thread, with the same id as the message. */
191199
public const FLAG_HAS_THREAD = (1 << 5);
200+
/** This message is only visible to the user who invoked the Interaction. */
192201
public const FLAG_EPHEMERAL = (1 << 6);
202+
/** This message is an Interaction Response and the bot is "thinking". */
193203
public const FLAG_LOADING = (1 << 7);
204+
/** This message failed to mention some roles and add their members to the thread. */
194205
public const FLAG_FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = (1 << 8);
206+
/** This message will not trigger push and desktop notifications. */
195207
public const FLAG_SUPPRESS_NOTIFICATIONS = (1 << 12);
208+
/** This message is a voice message. */
196209
public const FLAG_IS_VOICE_MESSAGE = (1 << 13);
210+
/** This message has a snapshot (via Message Forwarding). */
197211
public const FLAG_HAS_SNAPSHOT = (1 << 14);
212+
/** @deprecated Use `Message::FLAG_IS_COMPONENTS_V2` instead. */
198213
public const FLAG_IS_V2_COMPONENTS = (1 << 15);
214+
/** Allows you to create fully component-driven messages. */
215+
public const FLAG_IS_COMPONENTS_V2 = (1 << 15);
199216

200217
/**
201218
* {@inheritDoc}
@@ -276,7 +293,7 @@ protected function getIsCrosspostAttribute(): bool
276293
*/
277294
protected function getSuppressEmbedsAttribute(): bool
278295
{
279-
return (bool) ($this->flags & self::FLAG_SUPPRESS_EMBED);
296+
return (bool) ($this->flags & self::FLAG_SUPPRESS_EMBEDS);
280297
}
281298

282299
/**

0 commit comments

Comments
 (0)