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!: Rename interaction methods #8832

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/discord.js/src/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ class CommandInteraction extends BaseInteraction {
/* eslint-disable no-empty-function */
deferReply() {}
reply() {}
fetchReply() {}
editReply() {}
deleteReply() {}
fetchResponse() {}
editResponse() {}
deleteResponse() {}
followUp() {}
showModal() {}
sendPremiumRequired() {}
awaitModalSubmit() {}
}

InteractionResponses.applyToClass(CommandInteraction, ['deferUpdate', 'update']);
InteractionResponses.applyToClass(CommandInteraction, ['deferMessageUpdate', 'updateMessage']);

module.exports = CommandInteraction;
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ class MessageComponentInteraction extends BaseInteraction {
/* eslint-disable no-empty-function */
deferReply() {}
reply() {}
fetchReply() {}
editReply() {}
deleteReply() {}
fetchResponse() {}
editResponse() {}
deleteResponse() {}
followUp() {}
deferUpdate() {}
update() {}
deferMessageUpdate() {}
updateMessage() {}
showModal() {}
sendPremiumRequired() {}
awaitModalSubmit() {}
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/MessagePayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ module.exports = MessagePayload;
/**
* A possible payload option.
* @typedef {MessageCreateOptions|MessageEditOptions|WebhookMessageCreateOptions|WebhookMessageEditOptions|
* InteractionReplyOptions|InteractionUpdateOptions} MessagePayloadOption
* InteractionReplyOptions|InteractionUpdateMessageOptions} MessagePayloadOption
*/

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/discord.js/src/structures/ModalSubmitInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ class ModalSubmitInteraction extends BaseInteraction {
/* eslint-disable no-empty-function */
deferReply() {}
reply() {}
fetchReply() {}
editReply() {}
deleteReply() {}
fetchResponse() {}
editResponse() {}
deleteResponse() {}
followUp() {}
deferUpdate() {}
update() {}
deferMessageUpdate() {}
updateMessage() {}
sendPremiumRequired() {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ class InteractionResponses {
* Options for deferring the reply to an {@link BaseInteraction}.
* @typedef {Object} InteractionDeferReplyOptions
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
* @property {boolean} [fetchReply] Whether to fetch the reply
* @property {boolean} [fetchResponse] Whether to fetch the reply
*/

/**
* Options for deferring and updating the reply to a {@link MessageComponentInteraction}.
* @typedef {Object} InteractionDeferUpdateOptions
* @property {boolean} [fetchReply] Whether to fetch the reply
* @typedef {Object} InteractionDeferMessageUpdateOptions
* @property {boolean} [fetchResponse] Whether to fetch the reply
*/

/**
* Options for a reply to a {@link BaseInteraction}.
* @typedef {BaseMessageOptions} InteractionReplyOptions
* @property {boolean} [tts=false] Whether the message should be spoken aloud
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
* @property {boolean} [fetchReply] Whether to fetch the reply
* @property {boolean} [fetchResponse] Whether to fetch the reply
* @property {MessageFlags} [flags] Which flags to set for the message.
* <info>Only `MessageFlags.Ephemeral`, `MessageFlags.SuppressEmbeds`, and `MessageFlags.SuppressNotifications`
* can be set.</info>
*/

/**
* Options for updating the message received from a {@link MessageComponentInteraction}.
* @typedef {MessageEditOptions} InteractionUpdateOptions
* @property {boolean} [fetchReply] Whether to fetch the reply
* @typedef {MessageEditOptions} InteractionUpdateMessageOptions
* @property {boolean} [fetchResponse] Whether to fetch the reply
*/

/**
Expand Down Expand Up @@ -80,17 +80,17 @@ class InteractionResponses {
});
this.deferred = true;

return options.fetchReply ? this.fetchReply() : new InteractionResponse(this);
return options.fetchResponse ? this.fetchResponse() : new InteractionResponse(this);
}

/**
* Creates a reply to this interaction.
* <info>Use the `fetchReply` option to get the bot's reply message.</info>
* <info>Use the `fetchResponse` option to get the bot's reply message.</info>
* @param {string|MessagePayload|InteractionReplyOptions} options The options for the reply
* @returns {Promise<Message|InteractionResponse>}
* @example
* // Reply to the interaction and fetch the response
* interaction.reply({ content: 'Pong!', fetchReply: true })
* interaction.reply({ content: 'Pong!', fetchResponse: true })
* .then((message) => console.log(`Reply sent with content ${message.content}`))
* .catch(console.error);
* @example
Expand Down Expand Up @@ -122,7 +122,7 @@ class InteractionResponses {
});
this.replied = true;

return options.fetchReply ? this.fetchReply() : new InteractionResponse(this);
return options.fetchResponse ? this.fetchResponse() : new InteractionResponse(this);
}

/**
Expand All @@ -132,32 +132,32 @@ class InteractionResponses {
* @returns {Promise<Message>}
* @example
* // Fetch the initial reply to this interaction
* interaction.fetchReply()
* interaction.fetchResponse()
* .then(reply => console.log(`Replied with ${reply.content}`))
* .catch(console.error);
*/
fetchReply(message = '@original') {
fetchResponse(message = '@original') {
return this.webhook.fetchMessage(message);
}

/**
* Options that can be passed into {@link InteractionResponses#editReply}.
* @typedef {WebhookMessageEditOptions} InteractionEditReplyOptions
* Options that can be passed into {@link InteractionResponses#editResponse}.
* @typedef {WebhookMessageEditOptions} InteractionEditResponseOptions
* @property {MessageResolvable|'@original'} [message='@original'] The response to edit
*/

/**
* Edits a reply to this interaction.
* @see Webhook#editMessage
* @param {string|MessagePayload|InteractionEditReplyOptions} options The new options for the message
* @param {string|MessagePayload|InteractionEditResponseOptions} options The new options for the message
* @returns {Promise<Message>}
* @example
* // Edit the initial reply to this interaction
* interaction.editReply('New content')
* interaction.editResponse('New content')
* .then(console.log)
* .catch(console.error);
*/
async editReply(options) {
async editResponse(options) {
if (!this.deferred && !this.replied) throw new DiscordjsError(ErrorCodes.InteractionNotReplied);
const msg = await this.webhook.editMessage(options.message ?? '@original', options);
this.replied = true;
Expand All @@ -171,11 +171,11 @@ class InteractionResponses {
* @returns {Promise<void>}
* @example
* // Delete the initial reply to this interaction
* interaction.deleteReply()
* interaction.deleteResponse()
* .then(console.log)
* .catch(console.error);
*/
async deleteReply(message = '@original') {
async deleteResponse(message = '@original') {
await this.webhook.deleteMessage(message);
}

Expand All @@ -191,15 +191,15 @@ class InteractionResponses {

/**
* Defers an update to the message to which the component was attached.
* @param {InteractionDeferUpdateOptions} [options] Options for deferring the update to this interaction
* @param {InteractionDeferMessageUpdateOptions} [options] Options for deferring the update to this interaction
* @returns {Promise<Message|InteractionResponse>}
* @example
* // Defer updating and reset the component's loading state
* interaction.deferUpdate()
* interaction.deferMessageUpdate()
* .then(console.log)
* .catch(console.error);
*/
async deferUpdate(options = {}) {
async deferMessageUpdate(options = {}) {
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
body: {
Expand All @@ -209,23 +209,23 @@ class InteractionResponses {
});
this.deferred = true;

return options.fetchReply ? this.fetchReply() : new InteractionResponse(this, this.message?.interaction?.id);
return options.fetchResponse ? this.fetchResponse() : new InteractionResponse(this, this.message?.interaction?.id);
}

/**
* Updates the original message of the component on which the interaction was received on.
* @param {string|MessagePayload|InteractionUpdateOptions} options The options for the updated message
* @param {string|MessagePayload|InteractionUpdateMessageOptions} options The options for the updated message
* @returns {Promise<Message|void>}
* @example
* // Remove the components from the message
* interaction.update({
* interaction.updateMessage({
* content: "A component interaction was received",
* components: []
* })
* .then(console.log)
* .catch(console.error);
*/
async update(options) {
async updateMessage(options) {
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);

let messagePayload;
Expand All @@ -244,7 +244,7 @@ class InteractionResponses {
});
this.replied = true;

return options.fetchReply ? this.fetchReply() : new InteractionResponse(this, this.message.interaction?.id);
return options.fetchResponse ? this.fetchResponse() : new InteractionResponse(this, this.message.interaction?.id);
}

/**
Expand Down Expand Up @@ -317,12 +317,12 @@ class InteractionResponses {
const props = [
'deferReply',
'reply',
'fetchReply',
'editReply',
'deleteReply',
'fetchResponse',
'editResponse',
'deleteResponse',
'followUp',
'deferUpdate',
'update',
'deferMessageUpdate',
'updateMessage',
'showModal',
'sendPremiumRequired',
'awaitModalSubmit',
Expand Down
Loading
Loading