-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(InteractionResponses)!: support with_response query parameter #10499
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fb02e8a
feat(InteractionResponses): support with_response query parameter
monbrey a9a5872
fix: export new files from index
monbrey bd6d5b0
Apply suggestions from code review
monbrey dd642d7
fix: correct assignment of nullable property, types
monbrey c5a4696
fix: exports
monbrey 111b3dd
fix: suggestions from code review
monbrey 80986bc
fix: formatting
monbrey 1d82b3d
fix: more formatting
monbrey dac5a9d
fix: apply suggestions from code review
monbrey 93f4aa8
feat: remove fetchReply option completely
monbrey c23b3af
Merge branch 'main' into with_response
monbrey 2637c17
fix: apply suggestions from code review
monbrey 00bae08
fix: types and docs
monbrey c2bdd14
Merge branch 'with_response' of https://github.com/monbrey/discord.js…
monbrey d3b8266
Merge branch 'main' into with_response
monbrey 677d615
fix: apply suggestions from code review
monbrey 6c18aff
fix: commandinteraction#showModal types
monbrey 8775fbd
fix: swap overloads
monbrey d1e9bce
Merge branch 'main' into with_response
didinele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,92 @@ | ||
'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); | ||
} | ||
|
||
/** | ||
* The channel the original interaction was sent in | ||
* @type {?TextBasedChannels} | ||
* @readonly | ||
*/ | ||
get channel() { | ||
return this.client.channels.cache.get(this.channelId) ?? null; | ||
} | ||
|
||
/** | ||
* The guild the original interaction was sent in | ||
* @type {?Guild} | ||
* @readonly | ||
*/ | ||
get guild() { | ||
return this.client.guilds.cache.get(this.guildId) ?? null; | ||
} | ||
monbrey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
module.exports = InteractionCallback; |
52 changes: 52 additions & 0 deletions
52
packages/discord.js/src/structures/InteractionCallbackResource.js
This file contains hidden or 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'; | ||
monbrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 hidden or 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'); | ||
|
||
/** | ||
monbrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.