From 29d42ed31959a0b5e518b46e45029b99cb15aa59 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Wed, 2 Mar 2022 09:32:36 +0000 Subject: [PATCH] feat: Backport sending message flags (#7560) --- src/structures/MessagePayload.js | 12 +++++++++--- src/structures/Webhook.js | 1 + src/structures/interfaces/InteractionResponses.js | 2 ++ src/structures/interfaces/TextBasedChannel.js | 1 + typings/index.d.ts | 6 ++++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index 7f890df1381a..8c1bb94b5a2f 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -148,11 +148,17 @@ class MessagePayload { } let flags; - if ((this.isMessage && typeof this.options.reply === 'undefined') || this.isMessageManager) { + if ( + typeof this.options.flags !== 'undefined' || + (this.isMessage && typeof this.options.reply === 'undefined') || + this.isMessageManager + ) { // eslint-disable-next-line eqeqeq flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags?.bitfield; - } else if (isInteraction && this.options.ephemeral) { - flags = MessageFlags.FLAGS.EPHEMERAL; + } + + if (isInteraction && this.options.ephemeral) { + flags |= MessageFlags.FLAGS.EPHEMERAL; } let allowedMentions = diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index 022270a875cd..33540b992bf8 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -116,6 +116,7 @@ class Webhook { * @property {string} [avatarURL] Avatar URL override for the message * @property {Snowflake} [threadId] The id of the thread in the channel to send to. * For interaction webhooks, this property is ignored + * @property {MessageFlags} [flags] Which flags to set for the message. Only `SUPPRESS_EMBEDS` can be set. */ /** diff --git a/src/structures/interfaces/InteractionResponses.js b/src/structures/interfaces/InteractionResponses.js index dbe7c2327e8a..17badddefb57 100644 --- a/src/structures/interfaces/InteractionResponses.js +++ b/src/structures/interfaces/InteractionResponses.js @@ -28,6 +28,8 @@ class InteractionResponses { * @typedef {BaseMessageOptions} InteractionReplyOptions * @property {boolean} [ephemeral] Whether the reply should be ephemeral * @property {boolean} [fetchReply] Whether to fetch the reply + * @property {MessageFlags} [flags] Which flags to set for the message. + * Only `SUPPRESS_EMBEDS` and `EPHEMERAL` can be set. */ /** diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index a8b83149772b..c80edd271c15 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -73,6 +73,7 @@ class TextBasedChannel { * @typedef {BaseMessageOptions} MessageOptions * @property {ReplyOptions} [reply] The options for replying to a message * @property {StickerResolvable[]} [stickers=[]] Stickers to send in the message + * @property {MessageFlags} [flags] Which flags to set for the message. Only `SUPPRESS_EMBEDS` can be set. */ /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 6d82cf002abb..14ccbf4f0342 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3348,7 +3348,7 @@ export interface PartialWebhookFields { /** @deprecated */ fetchMessage(message: Snowflake | '@original', cache?: boolean): Promise; /* tslint:enable:unified-signatures */ - send(options: string | MessagePayload | WebhookMessageOptions): Promise; + send(options: string | MessagePayload | Omit): Promise; } export interface WebhookFields extends PartialWebhookFields { @@ -4911,9 +4911,10 @@ export interface InteractionDeferReplyOptions { export type InteractionDeferUpdateOptions = Omit; -export interface InteractionReplyOptions extends Omit { +export interface InteractionReplyOptions extends Omit { ephemeral?: boolean; fetchReply?: boolean; + flags?: BitFieldResolvable<'SUPPRESS_EMBEDS' | 'EPHEMERAL', number>; } export type InteractionResponseType = keyof typeof InteractionResponseTypes; @@ -5180,6 +5181,7 @@ export interface MessageOptions { reply?: ReplyOptions; stickers?: StickerResolvable[]; attachments?: MessageAttachment[]; + flags?: BitFieldResolvable<'SUPPRESS_EMBEDS', number>; } export type MessageReactionResolvable =