mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
feat(Interactions): improve error handling for ephemeral responses (#5892)
Co-authored-by: muchnameless <12682826+muchnameless@users.noreply.github.com>
This commit is contained in:
@@ -58,6 +58,12 @@ class CommandInteraction extends Interaction {
|
||||
*/
|
||||
this.replied = false;
|
||||
|
||||
/**
|
||||
* Whether the reply to this interaction is ephemeral
|
||||
* @type {?boolean}
|
||||
*/
|
||||
this.ephemeral = null;
|
||||
|
||||
/**
|
||||
* An associated interaction webhook, can be used to further interact with this interaction
|
||||
* @type {InteractionWebhook}
|
||||
|
||||
@@ -38,6 +38,12 @@ class MessageComponentInteraction extends Interaction {
|
||||
*/
|
||||
this.deferred = false;
|
||||
|
||||
/**
|
||||
* Whether the reply to this interaction is ephemeral
|
||||
* @type {?boolean}
|
||||
*/
|
||||
this.ephemeral = null;
|
||||
|
||||
/**
|
||||
* Whether this interaction has already been replied to
|
||||
* @type {boolean}
|
||||
|
||||
@@ -39,6 +39,7 @@ class InteractionResponses {
|
||||
*/
|
||||
async defer({ ephemeral } = {}) {
|
||||
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
|
||||
this.ephemeral = ephemeral ?? false;
|
||||
await this.client.api.interactions(this.id, this.token).callback.post({
|
||||
data: {
|
||||
type: InteractionResponseTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
|
||||
@@ -69,6 +70,7 @@ class InteractionResponses {
|
||||
*/
|
||||
async reply(options) {
|
||||
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
|
||||
this.ephemeral = options.ephemeral ?? false;
|
||||
|
||||
let apiMessage;
|
||||
if (options instanceof APIMessage) apiMessage = options;
|
||||
@@ -97,6 +99,7 @@ class InteractionResponses {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchReply() {
|
||||
if (this.ephemeral) throw new Error('INTERACTION_EPHEMERAL_REPLIED');
|
||||
return this.webhook.fetchMessage('@original');
|
||||
}
|
||||
|
||||
@@ -112,6 +115,7 @@ class InteractionResponses {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
editReply(options) {
|
||||
if (!this.deferred && !this.replied) throw new Error('INTERACTION_NOT_REPLIED');
|
||||
return this.webhook.editMessage('@original', options);
|
||||
}
|
||||
|
||||
@@ -126,6 +130,7 @@ class InteractionResponses {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async deleteReply() {
|
||||
if (this.ephemeral) throw new Error('INTERACTION_EPHEMERAL_REPLIED');
|
||||
await this.webhook.deleteMessage('@original');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user