-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(InteractionResponses)!: support with_response query parameter (#…
…10499) BREAKING CHANGE: `InteractionDeferUpdateOptions#fetchReply` was removed, use `InteractionDeferUpdateOptions#withResponse` instead --------- Co-authored-by: Jiralite <[email protected]>
- Loading branch information
Showing
7 changed files
with
320 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
|
||
const { DiscordSnowflake } = require('@sapphire/snowflake'); | ||
|
||
/** | ||
* Represents an interaction callback response from Discord | ||
*/ | ||
class InteractionCallback { | ||
constructor(client, data) { | ||
/** | ||
* The client that instantiated this. | ||
* @name InteractionCallback#client | ||
* @type {Client} | ||
* @readonly | ||
*/ | ||
Object.defineProperty(this, 'client', { value: client }); | ||
|
||
/** | ||
* The id of the original interaction response | ||
* @type {Snowflake} | ||
*/ | ||
this.id = data.id; | ||
|
||
/** | ||
* The type of the original interaction | ||
* @type {InteractionType} | ||
*/ | ||
this.type = data.type; | ||
|
||
/** | ||
* The instance id of the Activity if one was launched or joined | ||
* @type {?string} | ||
*/ | ||
this.activityInstanceId = data.activity_instance_id ?? null; | ||
|
||
/** | ||
* The id of the message that was created by the interaction | ||
* @type {?Snowflake} | ||
*/ | ||
this.responseMessageId = data.response_message_id ?? null; | ||
|
||
/** | ||
* Whether the message is in a loading state | ||
* @type {?boolean} | ||
*/ | ||
this.responseMessageLoading = data.response_message_loading ?? null; | ||
|
||
/** | ||
* Whether the response message was ephemeral | ||
* @type {?boolean} | ||
*/ | ||
this.responseMessageEphemeral = data.response_message_ephemeral ?? null; | ||
} | ||
|
||
/** | ||
* The timestamp the original interaction was created at | ||
* @type {number} | ||
* @readonly | ||
*/ | ||
get createdTimestamp() { | ||
return DiscordSnowflake.timestampFrom(this.id); | ||
} | ||
|
||
/** | ||
* The time the original interaction was created at | ||
* @type {Date} | ||
* @readonly | ||
*/ | ||
get createdAt() { | ||
return new Date(this.createdTimestamp); | ||
} | ||
} | ||
|
||
module.exports = InteractionCallback; |
52 changes: 52 additions & 0 deletions
52
packages/discord.js/src/structures/InteractionCallbackResource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const { lazy } = require('@discordjs/util'); | ||
|
||
const getMessage = lazy(() => require('./Message').Message); | ||
|
||
/** | ||
* Represents the resource that was created by the interaction response. | ||
*/ | ||
class InteractionCallbackResource { | ||
constructor(client, data) { | ||
/** | ||
* The client that instantiated this | ||
* @name InteractionCallbackResource#client | ||
* @type {Client} | ||
* @readonly | ||
*/ | ||
Object.defineProperty(this, 'client', { value: client }); | ||
|
||
/** | ||
* The interaction callback type | ||
* @type {InteractionResponseType} | ||
*/ | ||
this.type = data.type; | ||
|
||
/** | ||
* The Activity launched by an interaction | ||
* @typedef {Object} ActivityInstance | ||
* @property {string} id The instance id of the Activity | ||
*/ | ||
|
||
/** | ||
* Represents the Activity launched by this interaction | ||
* @type {?ActivityInstance} | ||
*/ | ||
this.activityInstance = data.activity_instance ?? null; | ||
|
||
if ('message' in data) { | ||
/** | ||
* The message created by the interaction | ||
* @type {?Message} | ||
*/ | ||
this.message = | ||
this.client.channels.cache.get(data.message.channel_id)?.messages._add(data.message) ?? | ||
new (getMessage())(client, data.message); | ||
} else { | ||
this.message = null; | ||
} | ||
} | ||
} | ||
|
||
module.exports = InteractionCallbackResource; |
33 changes: 33 additions & 0 deletions
33
packages/discord.js/src/structures/InteractionCallbackResponse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const InteractionCallback = require('./InteractionCallback'); | ||
const InteractionCallbackResource = require('./InteractionCallbackResource'); | ||
|
||
/** | ||
* Represents an interaction's response | ||
*/ | ||
class InteractionCallbackResponse { | ||
constructor(client, data) { | ||
/** | ||
* The client that instantiated this | ||
* @name InteractionCallbackResponse#client | ||
* @type {Client} | ||
* @readonly | ||
*/ | ||
Object.defineProperty(this, 'client', { value: client }); | ||
|
||
/** | ||
* The interaction object associated with the interaction callback response | ||
* @type {InteractionCallback} | ||
*/ | ||
this.interaction = new InteractionCallback(client, data.interaction); | ||
|
||
/** | ||
* The resource that was created by the interaction response | ||
* @type {?InteractionCallbackResource} | ||
*/ | ||
this.resource = data.resource ? new InteractionCallbackResource(client, data.resource) : null; | ||
} | ||
} | ||
|
||
module.exports = InteractionCallbackResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.