Skip to content

Commit

Permalink
feat(InteractionResponses): add message parameter (v13) (#8838)
Browse files Browse the repository at this point in the history
Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com>
Co-authored-by: Noel <buechler.noel@outlook.com>
  • Loading branch information
3 people committed Nov 25, 2022
1 parent eecc50b commit 0e0851a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
32 changes: 20 additions & 12 deletions src/structures/interfaces/InteractionResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,50 +114,58 @@ 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
* @returns {Promise<Message|APIMessage>}
* @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.
* Options that can be passed into {@link InteractionResponses#editReply}.
* @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|APIMessage>}
* @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 Error('INTERACTION_NOT_REPLIED');
const message = await this.webhook.editMessage('@original', options);
const message = await this.webhook.editMessage(options.messsage ?? '@original', options);
this.replied = true;
return message;
}

/**
* 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 Error('INTERACTION_EPHEMERAL_REPLIED');
await this.webhook.deleteMessage('@original');
await this.webhook.deleteMessage(message);
}

/**
Expand Down
27 changes: 15 additions & 12 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ export interface InteractionResponseFields<Cached extends CacheType = CacheType>
webhook: InteractionWebhook;
reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
deleteReply(): Promise<void>;
editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise<GuildCacheMessage<Cached>>;
deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
fetchReply(): Promise<GuildCacheMessage<Cached>>;
fetchReply(message?: MessageResolvable | '@original'): Promise<GuildCacheMessage<Cached>>;
followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
}

Expand Down Expand Up @@ -394,9 +394,9 @@ export abstract class BaseCommandInteraction<Cached extends CacheType = CacheTyp
public inRawGuild(): this is BaseCommandInteraction<'raw'>;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deleteReply(): Promise<void>;
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
public fetchReply(): Promise<GuildCacheMessage<Cached>>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise<GuildCacheMessage<Cached>>;
public fetchReply(message?: MessageResolvable | '@original'): Promise<GuildCacheMessage<Cached>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
Expand Down Expand Up @@ -1721,9 +1721,9 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<void>;
public deleteReply(): Promise<void>;
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
public fetchReply(): Promise<GuildCacheMessage<Cached>>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise<GuildCacheMessage<Cached>>;
public fetchReply(message?: MessageResolvable | '@original'): Promise<GuildCacheMessage<Cached>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
Expand Down Expand Up @@ -1954,13 +1954,13 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
public webhook: InteractionWebhook;
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
public deleteReply(): Promise<void>;
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<GuildCacheMessage<Cached>>;
public deleteReply(message?: MessageResolvable | '@original'): Promise<void>;
public editReply(options: string | MessagePayload | InteractionEditReplyOptions): Promise<GuildCacheMessage<Cached>>;
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise<GuildCacheMessage<Cached>>;
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<void>;
public fetchReply(): Promise<GuildCacheMessage<Cached>>;
public fetchReply(message?: MessageResolvable | '@original'): Promise<GuildCacheMessage<Cached>>;
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<GuildCacheMessage<Cached>>;
public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is ModalSubmitInteraction<'cached'>;
Expand Down Expand Up @@ -6057,6 +6057,9 @@ export type WebhookEditMessageOptions = Pick<
WebhookMessageOptions,
'content' | 'embeds' | 'files' | 'allowedMentions' | 'components' | 'attachments' | 'threadId'
>;
export interface InteractionEditReplyOptions extends WebhookEditMessageOptions {
message?: MessageResolvable | '@original';
}

export interface WebhookFetchMessageOptions {
cache?: boolean;
Expand Down

0 comments on commit 0e0851a

Please sign in to comment.