From 274952c502f604fbf5199e80991a8e0935ec94bc Mon Sep 17 00:00:00 2001 From: Monbrey Date: Thu, 13 May 2021 11:06:55 +1000 Subject: [PATCH 1/5] feat(CommandInteraction): ephemeral followup messages --- src/structures/CommandInteraction.js | 18 ++++++++++++++++++ typings/index.d.ts | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index 2cdd9179785a..e765b0de800a 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -187,6 +187,24 @@ class CommandInteraction extends Interaction { * @property {Role|Object} [role] The resolved role */ + /** + * Send a followup message to this interaction. + * @param {string|APIMessage|MessageAdditions} content The content for the reply + * @param {InteractionReplyOptions} [options] Additional options for the reply + * @returns {Promise} + */ + async followup(content, options) { + const apiMessage = content instanceof APIMessage ? content : APIMessage.create(this, content, options); + const { data, files } = await apiMessage.resolveData().resolveFiles(); + + await this.client.api.webhooks(this.applicationID, this.token).post({ + data: { + data, + }, + files, + }); + } + /** * Transforms an option received from the API. * @param {Object} option The received option diff --git a/typings/index.d.ts b/typings/index.d.ts index 6efebd1993f6..08390bbe78f2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -425,6 +425,8 @@ declare module 'discord.js' { ): Promise; public editReply(content: string, options?: WebhookEditMessageOptions): Promise; public fetchReply(): Promise; + public followup(content: string | APIMessage | InteractionReplyOptions | MessageAdditions): Promise; + public followup(content: string, options?: InteractionReplyOptions): Promise; public reply(content: string | APIMessage | InteractionReplyOptions | MessageAdditions): Promise; public reply(content: string, options?: InteractionReplyOptions): Promise; private transformOption(option: object, resolved: object): CommandInteractionOption; From 7bd62e8e7e65188a586657675e1f0deac7f47268 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Thu, 13 May 2021 11:30:42 +1000 Subject: [PATCH 2/5] fix: pass data correctly --- src/structures/CommandInteraction.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index e765b0de800a..431baf7e77f8 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -198,9 +198,7 @@ class CommandInteraction extends Interaction { const { data, files } = await apiMessage.resolveData().resolveFiles(); await this.client.api.webhooks(this.applicationID, this.token).post({ - data: { - data, - }, + data, files, }); } From a90e4d05b380ac267bc16fcd027e903923f4d426 Mon Sep 17 00:00:00 2001 From: Monbrey Date: Thu, 13 May 2021 11:45:51 +1000 Subject: [PATCH 3/5] feat: return the Message --- src/structures/CommandInteraction.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index 431baf7e77f8..8af11b1c1515 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -191,16 +191,18 @@ class CommandInteraction extends Interaction { * Send a followup message to this interaction. * @param {string|APIMessage|MessageAdditions} content The content for the reply * @param {InteractionReplyOptions} [options] Additional options for the reply - * @returns {Promise} + * @returns {Promise} */ async followup(content, options) { const apiMessage = content instanceof APIMessage ? content : APIMessage.create(this, content, options); const { data, files } = await apiMessage.resolveData().resolveFiles(); - await this.client.api.webhooks(this.applicationID, this.token).post({ + const raw = await this.client.api.webhooks(this.applicationID, this.token).post({ data, files, }); + + return this.channel?.messages.add(raw) ?? raw; } /** From af8fc7019071ffe7c2c763a91c09093de78c85ee Mon Sep 17 00:00:00 2001 From: Monbrey Date: Thu, 13 May 2021 13:30:47 +1000 Subject: [PATCH 4/5] fix: typings for previous change --- typings/index.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 08390bbe78f2..359e62b448ee 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -425,8 +425,10 @@ declare module 'discord.js' { ): Promise; public editReply(content: string, options?: WebhookEditMessageOptions): Promise; public fetchReply(): Promise; - public followup(content: string | APIMessage | InteractionReplyOptions | MessageAdditions): Promise; - public followup(content: string, options?: InteractionReplyOptions): Promise; + public followup( + content: string | APIMessage | InteractionReplyOptions | MessageAdditions, + ): Promise; + public followup(content: string, options?: InteractionReplyOptions): Promise; public reply(content: string | APIMessage | InteractionReplyOptions | MessageAdditions): Promise; public reply(content: string, options?: InteractionReplyOptions): Promise; private transformOption(option: object, resolved: object): CommandInteractionOption; From 27be0880d13110411c9b5377ca9a9e86ce0db753 Mon Sep 17 00:00:00 2001 From: monbrey Date: Fri, 14 May 2021 04:26:59 +1000 Subject: [PATCH 5/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Román --- src/structures/CommandInteraction.js | 4 ++-- typings/index.d.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index 8af11b1c1515..22851239e642 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -188,12 +188,12 @@ class CommandInteraction extends Interaction { */ /** - * Send a followup message to this interaction. + * Send a follow-up message to this interaction. * @param {string|APIMessage|MessageAdditions} content The content for the reply * @param {InteractionReplyOptions} [options] Additional options for the reply * @returns {Promise} */ - async followup(content, options) { + async followUp(content, options) { const apiMessage = content instanceof APIMessage ? content : APIMessage.create(this, content, options); const { data, files } = await apiMessage.resolveData().resolveFiles(); diff --git a/typings/index.d.ts b/typings/index.d.ts index 359e62b448ee..0e574ac27145 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -425,10 +425,10 @@ declare module 'discord.js' { ): Promise; public editReply(content: string, options?: WebhookEditMessageOptions): Promise; public fetchReply(): Promise; - public followup( + public followUp( content: string | APIMessage | InteractionReplyOptions | MessageAdditions, ): Promise; - public followup(content: string, options?: InteractionReplyOptions): Promise; + public followUp(content: string, options?: InteractionReplyOptions): Promise; public reply(content: string | APIMessage | InteractionReplyOptions | MessageAdditions): Promise; public reply(content: string, options?: InteractionReplyOptions): Promise; private transformOption(option: object, resolved: object): CommandInteractionOption;