Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(InteractionResponses): add message parameter #8773

Merged
merged 10 commits into from Oct 31, 2022
Expand Up @@ -122,50 +122,57 @@ class InteractionResponses {
}

/**
* Fetches the initial reply to this interaction.
* Fetches a reply to this interaction.
* @see Webhook#fetchMessage
* @param {MessageResolvable|'@original'} [message='@original'] The response to fetch
MrMythicalYT marked this conversation as resolved.
Show resolved Hide resolved
* @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] The response to edit
MrMythicalYT marked this conversation as resolved.
Show resolved Hide resolved
*/

/**
* 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
MrMythicalYT marked this conversation as resolved.
Show resolved Hide resolved
* 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() {
async deleteReply(message = '@original') {
if (this.ephemeral) throw new DiscordjsError(ErrorCodes.InteractionEphemeralReplied);
await this.webhook.deleteMessage('@original');
await this.webhook.deleteMessage(message);
}

/**
Expand Down
22 changes: 13 additions & 9 deletions packages/discord.js/typings/index.d.ts
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?: MessageResolvable | '@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 @@ -1829,11 +1829,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?: MessageResolvable | '@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 @@ -2019,15 +2019,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?: MessageResolvable | '@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 @@ -5755,6 +5755,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