Skip to content

Commit b0b30b9

Browse files
monbreyJiralite
authored andcommitted
feat(InteractionResponses): support with_response query parameter
1 parent ed00a10 commit b0b30b9

File tree

7 files changed

+414
-22
lines changed

7 files changed

+414
-22
lines changed

packages/discord.js/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ exports.GuildScheduledEvent = require('./structures/GuildScheduledEvent').GuildS
147147
exports.GuildTemplate = require('./structures/GuildTemplate');
148148
exports.Integration = require('./structures/Integration');
149149
exports.IntegrationApplication = require('./structures/IntegrationApplication');
150+
exports.InteractionCallback = require('./structures/InteractionCallback');
151+
exports.InteractionCallbackResource = require('./structures/InteractionCallbackResource');
152+
exports.InteractionCallbackResponse = require('./structures/InteractionCallbackResponse');
150153
exports.BaseInteraction = require('./structures/BaseInteraction');
151154
exports.InteractionCollector = require('./structures/InteractionCollector');
152155
exports.InteractionResponse = require('./structures/InteractionResponse');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'use strict';
2+
3+
const { DiscordSnowflake } = require('@sapphire/snowflake');
4+
5+
/**
6+
* Represents an interaction callback response from Discord
7+
*/
8+
class InteractionCallback {
9+
constructor(client, data) {
10+
/**
11+
* The client that instantiated this.
12+
* @name InteractionCallback#client
13+
* @type {Client}
14+
* @readonly
15+
*/
16+
Object.defineProperty(this, 'client', { value: client });
17+
18+
/**
19+
* The id of the original interaction response
20+
* @type {Snowflake}
21+
*/
22+
this.id = data.id;
23+
24+
/**
25+
* The type of the original interaction
26+
* @type {InteractionType}
27+
*/
28+
this.type = data.type;
29+
30+
/**
31+
* The instance id of the Activity if one was launched or joined
32+
* @type {?string}
33+
*/
34+
this.activityInstanceId = data.activity_instance_id ?? null;
35+
36+
/**
37+
* The id of the message that was created by the interaction
38+
* @type {?Snowflake}
39+
*/
40+
this.responseMessageId = data.response_message_id ?? null;
41+
42+
/**
43+
* Whether the message is in a loading state
44+
* @type {?boolean}
45+
*/
46+
this.responseMessageLoading = data.response_message_loading ?? null;
47+
48+
/**
49+
* Whether the response message was ephemeral
50+
* @type {?boolean}
51+
*/
52+
this.responseMessageEphemeral = data.response_message_ephemeral ?? null;
53+
}
54+
55+
/**
56+
* The timestamp the original interaction was created at
57+
* @type {number}
58+
* @readonly
59+
*/
60+
get createdTimestamp() {
61+
return DiscordSnowflake.timestampFrom(this.id);
62+
}
63+
64+
/**
65+
* The time the original interaction was created at
66+
* @type {Date}
67+
* @readonly
68+
*/
69+
get createdAt() {
70+
return new Date(this.createdTimestamp);
71+
}
72+
}
73+
74+
module.exports = InteractionCallback;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
const { lazy } = require('@discordjs/util');
4+
5+
const getMessage = lazy(() => require('./Message').Message);
6+
7+
/**
8+
* Represents the resource that was created by the interaction response.
9+
*/
10+
class InteractionCallbackResource {
11+
constructor(client, data) {
12+
/**
13+
* The client that instantiated this
14+
* @name InteractionCallbackResource#client
15+
* @type {Client}
16+
* @readonly
17+
*/
18+
Object.defineProperty(this, 'client', { value: client });
19+
20+
/**
21+
* The interaction callback type
22+
* @type {InteractionResponseType}
23+
*/
24+
this.type = data.type;
25+
26+
/**
27+
* The Activity launched by an interaction
28+
* @typedef {Object} ActivityInstance
29+
* @property {string} id The instance id of the Activity
30+
*/
31+
32+
/**
33+
* Represents the Activity launched by this interaction
34+
* @type {?ActivityInstance}
35+
*/
36+
this.activityInstance = data.activity_instance ?? null;
37+
38+
if ('message' in data) {
39+
/**
40+
* The message created by the interaction
41+
* @type {?Message}
42+
*/
43+
this.message =
44+
this.client.channels.cache.get(data.message.channel_id)?.messages._add(data.message) ??
45+
new (getMessage())(client, data.message);
46+
} else {
47+
this.message = null;
48+
}
49+
}
50+
}
51+
52+
module.exports = InteractionCallbackResource;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const InteractionCallback = require('./InteractionCallback');
4+
const InteractionCallbackResource = require('./InteractionCallbackResource');
5+
6+
/**
7+
* Represents an interaction's response
8+
*/
9+
class InteractionCallbackResponse {
10+
constructor(client, data) {
11+
/**
12+
* The client that instantiated this
13+
* @name InteractionCallbackResponse#client
14+
* @type {Client}
15+
* @readonly
16+
*/
17+
Object.defineProperty(this, 'client', { value: client });
18+
19+
/**
20+
* The interaction object associated with the interaction callback response
21+
* @type {InteractionCallback}
22+
*/
23+
this.interaction = new InteractionCallback(client, data.interaction);
24+
25+
/**
26+
* The resource that was created by the interaction response
27+
* @type {?InteractionCallbackResource}
28+
*/
29+
this.resource = data.resource ? new InteractionCallbackResource(client, data.resource) : null;
30+
}
31+
}
32+
33+
module.exports = InteractionCallbackResponse;

0 commit comments

Comments
 (0)