diff --git a/index.d.ts b/index.d.ts index 770df4676..b6fa1b0b6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2270,10 +2270,10 @@ declare namespace Eris { type: InteractionType; user?: User; version: number; - acknowledge(): Promise; + acknowledge(flags?: number): Promise; createFollowup(content: string | InteractionWebhookContent): Promise>; createMessage(content: string | InteractionContent): Promise; - defer(flags: number): Promise; + defer(flags?: number): Promise; deferUpdate(): Promise; delete(messageId: string): Promise; edit(messageId: string, content: string | MessageWebhookContent): Promise>; diff --git a/lib/structures/Interaction.js b/lib/structures/Interaction.js index c9bc32e3b..c132b318d 100644 --- a/lib/structures/Interaction.js +++ b/lib/structures/Interaction.js @@ -16,8 +16,8 @@ const Constants = require("../Constants"); * @prop {String?} data.id The ID of the Slash Command (Slash Command) * @prop {String?} data.name The command name (Slash Command only) * @prop {Array?} data.options The run Slash Command options (Slash Command only) -* @prop {String} data.options.name The name of the Slash Command option -* @prop {Number} data.options.type Command option type, 1-9 +* @prop {String} data.options.name The name of the Slash Command option +* @prop {Number} data.options.type Command option type, 1-9 * @prop {Number?} data.options.value The value of the run Slash Command (Mutually exclusive with options) * @prop {Array?} data.options.options The run Slash Command options (Mutually exclusive with value) * @prop {String?} guildId The id of the guild in which the interaction was created @@ -69,15 +69,45 @@ class Interaction extends Base { } /** - * Acknowledges the interaction without replying. (Message Component only) - * Is a renamed deferUpdate() method + * Acknowledges the interaction. + * Works as a Pong when used on a type 1 interaction. (Ping) + * Works as defer() when used on a type 2 interaction. (Slash Command) + * Works as deferUpdate() when used on a type 3 interaction. (Message Comonent) * Note: You can **not** use more than 1 initial interaction response per interaction. + * @arg {Number} [flags] 64 for Ephemeral (only when used on a Slash Command interaction) * @returns {Promise} */ - async acknowledge() { - return this._client.createInteractionResponse.call(this._client, this.id, this.token, { - type: Constants.InteractionResponseTypes.DEFERRED_UPDATE_MESSAGE - }); + async acknowledge(flags) { + switch(this.type) { + case Constants.InteractionTypes.ping: { + return this._client.createInteractionResponse.call(this._client, this.id, this.token, { + type: Constants.InteractionResponseTypes.PONG + }); + } + case Constants.InteractionTypes.slashCommand: { + return this._client.createInteractionResponse.call(this._client, this.id, this.token, { + type: Constants.InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, + data: { + flags: flags || 0 + } + }); + } + case Constants.InteractionTypes.messageComponent: { + return this._client.createInteractionResponse.call(this._client, this.id, this.token, { + type: Constants.InteractionResponseTypes.DEFERRED_UPDATE_MESSAGE + }); + } + default: { + this.client.emit("warn", new Error(`Unknown Interaction Type: ${this.type}`)); + + return this._client.createInteractionResponse.call(this._client, this.id, this.token, { + type: Constants.InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, + data: { + flags: flags || 0 + } + }); + } + } } /** @@ -147,7 +177,7 @@ class Interaction extends Base { /** * Defer response to the interaction * Note: You can **not** use more than 1 initial interaction response per interaction. - * @arg {Boolean} [flags] 64 for Ephemeral + * @arg {Number} [flags] 64 for Ephemeral * @returns {Promise} */ async defer(flags) {