Skip to content

Commit

Permalink
Fixed some defer docs, acknowledge now has a reason to exist
Browse files Browse the repository at this point in the history
Acknowledge now works differently depending on the interaction type,
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)
  • Loading branch information
JustCat80 committed Jul 24, 2021
1 parent d3bca79 commit 1563fbd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2270,10 +2270,10 @@ declare namespace Eris {
type: InteractionType;
user?: User;
version: number;
acknowledge(): Promise<void>;
acknowledge(flags?: number): Promise<void>;
createFollowup(content: string | InteractionWebhookContent): Promise<Message<GuildTextableChannel>>;
createMessage(content: string | InteractionContent): Promise<void>;
defer(flags: number): Promise<void>;
defer(flags?: number): Promise<void>;
deferUpdate(): Promise<void>;
delete(messageId: string): Promise<void>;
edit(messageId: string, content: string | MessageWebhookContent): Promise<Message<GuildTextableChannel>>;
Expand Down
48 changes: 39 additions & 9 deletions lib/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>?} 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<Object>?} 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
Expand Down Expand Up @@ -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
}
});
}
}
}

/**
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1563fbd

Please sign in to comment.