Skip to content

Commit

Permalink
feat(InteractionResponses): add message parameter (#8773)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMythicalYT authored Oct 31, 2022
1 parent 88cd9d9 commit 8b400ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,49 +122,56 @@ class InteractionResponses {
}

/**
* Fetches the initial reply to this interaction.
* Fetches a reply to this interaction.
* @see Webhook#fetchMessage
* @param {Snowflake|'@original'} [message='@original'] The response to fetch
* @returns {Promise<Message>}
* @example
* // Fetch the reply to this interaction
* // Fetch the initial reply to this interaction
* interaction.fetchReply()
* .then(reply => console.log(`Replied with ${reply.content}`))
* .catch(console.error);
*/
fetchReply() {
return this.webhook.fetchMessage('@original');
fetchReply(message = '@original') {
return this.webhook.fetchMessage(message);
}

/**
* Edits the initial reply to this interaction.
* @typedef {WebhookEditMessageOptions} InteractionEditReplyOptions
* @property {MessageResolvable|'@original'} [message='@original'] The response to edit
*/

/**
* Edits a reply to this interaction.
* @see Webhook#editMessage
* @param {string|MessagePayload|WebhookEditMessageOptions} options The new options for the message
* @param {string|MessagePayload|InteractionEditReplyOptions} options The new options for the message
* @returns {Promise<Message>}
* @example
* // Edit the reply to this interaction
* // Edit the initial reply to this interaction
* interaction.editReply('New content')
* .then(console.log)
* .catch(console.error);
*/
async editReply(options) {
if (!this.deferred && !this.replied) throw new DiscordjsError(ErrorCodes.InteractionNotReplied);
const message = await this.webhook.editMessage('@original', options);
const msg = await this.webhook.editMessage(options.message ?? '@original', options);
this.replied = true;
return message;
return msg;
}

/**
* Deletes the initial reply to this interaction.
* Deletes a reply to this interaction.
* @see Webhook#deleteMessage
* @param {MessageResolvable|'@original'} [message='@original'] The response to delete
* @returns {Promise<void>}
* @example
* // Delete the reply to this interaction
* // Delete the initial reply to this interaction
* interaction.deleteReply()
* .then(console.log)
* .catch(console.error);
*/
async deleteReply() {
await this.webhook.deleteMessage('@original');
async deleteReply(message = '@original') {
await this.webhook.deleteMessage(message);
}

/**
Expand Down
22 changes: 13 additions & 9 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,11 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
options: InteractionDeferReplyOptions & { fetchReply: true },
): Promise<Message<BooleanCache<Cached>>>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deleteReply(): Promise<void>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(
options: string | MessagePayload | WebhookEditMessageOptions,
options: string | MessagePayload | InteractionEditReplyOptions,
): Promise<Message<BooleanCache<Cached>>>;
public fetchReply(): Promise<Message<BooleanCache<Cached>>>;
public fetchReply(message?: Snowflake | '@original'): Promise<Message<BooleanCache<Cached>>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message<BooleanCache<Cached>>>;
public reply(
Expand Down Expand Up @@ -1830,11 +1830,11 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
options: InteractionDeferUpdateOptions & { fetchReply: true },
): Promise<Message<BooleanCache<Cached>>>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deleteReply(): Promise<void>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(
options: string | MessagePayload | WebhookEditMessageOptions,
options: string | MessagePayload | InteractionEditReplyOptions,
): Promise<Message<BooleanCache<Cached>>>;
public fetchReply(): Promise<Message<BooleanCache<Cached>>>;
public fetchReply(message?: Snowflake | '@original'): Promise<Message<BooleanCache<Cached>>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message<BooleanCache<Cached>>>;
public reply(
Expand Down Expand Up @@ -2020,15 +2020,15 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
public reply(
options: string | MessagePayload | InteractionReplyOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
public deleteReply(): Promise<void>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(
options: string | MessagePayload | WebhookEditMessageOptions,
options: string | MessagePayload | InteractionEditReplyOptions,
): Promise<Message<BooleanCache<Cached>>>;
public deferReply(
options: InteractionDeferReplyOptions & { fetchReply: true },
): Promise<Message<BooleanCache<Cached>>>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
public fetchReply(): Promise<Message<BooleanCache<Cached>>>;
public fetchReply(message?: Snowflake | '@original'): Promise<Message<BooleanCache<Cached>>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message<BooleanCache<Cached>>>;
public deferUpdate(
options: InteractionDeferUpdateOptions & { fetchReply: true },
Expand Down Expand Up @@ -5758,6 +5758,10 @@ export interface WebhookEditMessageOptions extends Omit<MessageEditOptions, 'fla
threadId?: Snowflake;
}

export interface InteractionEditReplyOptions extends WebhookEditMessageOptions {
message?: MessageResolvable | '@original';
}

export interface WebhookFetchMessageOptions {
threadId?: Snowflake;
}
Expand Down

0 comments on commit 8b400ca

Please sign in to comment.