discord.js 14.19.3 → 14.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -5
- package/src/client/Client.js +0 -1
- package/src/client/actions/InteractionCreate.js +4 -0
- package/src/index.js +1 -0
- package/src/managers/ApplicationCommandManager.js +1 -0
- package/src/managers/ChannelManager.js +7 -0
- package/src/structures/ApplicationCommand.js +21 -3
- package/src/structures/BaseInteraction.js +16 -0
- package/src/structures/ClientApplication.js +11 -0
- package/src/structures/ClientUser.js +0 -2
- package/src/structures/CommandInteraction.js +1 -0
- package/src/structures/GuildMember.js +38 -1
- package/src/structures/MessageComponentInteraction.js +1 -0
- package/src/structures/ModalSubmitInteraction.js +1 -0
- package/src/structures/PartialGroupDMChannel.js +2 -2
- package/src/structures/PrimaryEntryPointCommandInteraction.js +11 -0
- package/src/structures/interfaces/InteractionResponses.js +26 -0
- package/src/util/APITypes.js +5 -0
- package/src/util/Components.js +31 -62
- package/src/util/Transformers.js +9 -1
- package/typings/index.d.mts +65 -22
- package/typings/index.d.ts +65 -22
- package/typings/index.test-d.ts +0 -2846
- package/typings/tsdoc-metadata.json +0 -11
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "discord.js",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.21.0",
|
|
5
5
|
"description": "A powerful library for interacting with the Discord API",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./typings/index.d.ts",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"src",
|
|
26
|
-
"typings"
|
|
26
|
+
"typings/*.d.ts",
|
|
27
|
+
"typings/*.d.mts"
|
|
27
28
|
],
|
|
28
29
|
"contributors": [
|
|
29
30
|
"Crawl <icrawltogo@gmail.com>",
|
|
@@ -55,15 +56,15 @@
|
|
|
55
56
|
"@discordjs/builders": "^1.11.2",
|
|
56
57
|
"@discordjs/collection": "1.5.3",
|
|
57
58
|
"@discordjs/formatters": "^0.6.1",
|
|
58
|
-
"@discordjs/ws": "^1.2.
|
|
59
|
+
"@discordjs/ws": "^1.2.3",
|
|
59
60
|
"@sapphire/snowflake": "3.5.3",
|
|
60
61
|
"discord-api-types": "^0.38.1",
|
|
61
62
|
"fast-deep-equal": "3.1.3",
|
|
62
63
|
"lodash.snakecase": "4.1.1",
|
|
63
64
|
"magic-bytes.js": "^1.10.0",
|
|
64
65
|
"tslib": "^2.6.3",
|
|
65
|
-
"undici": "6.21.
|
|
66
|
-
"@discordjs/rest": "^2.5.
|
|
66
|
+
"undici": "6.21.3",
|
|
67
|
+
"@discordjs/rest": "^2.5.1",
|
|
67
68
|
"@discordjs/util": "^1.1.1"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
package/src/client/Client.js
CHANGED
|
@@ -277,7 +277,6 @@ class Client extends BaseClient {
|
|
|
277
277
|
const code = resolveInviteCode(invite);
|
|
278
278
|
const query = makeURLSearchParams({
|
|
279
279
|
with_counts: true,
|
|
280
|
-
with_expiration: true,
|
|
281
280
|
guild_scheduled_event_id: options?.guildScheduledEventId,
|
|
282
281
|
});
|
|
283
282
|
const data = await this.rest.get(Routes.invite(code), { query });
|
|
@@ -9,6 +9,7 @@ const ChatInputCommandInteraction = require('../../structures/ChatInputCommandIn
|
|
|
9
9
|
const MentionableSelectMenuInteraction = require('../../structures/MentionableSelectMenuInteraction');
|
|
10
10
|
const MessageContextMenuCommandInteraction = require('../../structures/MessageContextMenuCommandInteraction');
|
|
11
11
|
const ModalSubmitInteraction = require('../../structures/ModalSubmitInteraction');
|
|
12
|
+
const PrimaryEntryPointCommandInteraction = require('../../structures/PrimaryEntryPointCommandInteraction');
|
|
12
13
|
const RoleSelectMenuInteraction = require('../../structures/RoleSelectMenuInteraction');
|
|
13
14
|
const StringSelectMenuInteraction = require('../../structures/StringSelectMenuInteraction');
|
|
14
15
|
const UserContextMenuCommandInteraction = require('../../structures/UserContextMenuCommandInteraction');
|
|
@@ -38,6 +39,9 @@ class InteractionCreateAction extends Action {
|
|
|
38
39
|
if (channel && !channel.isTextBased()) return;
|
|
39
40
|
InteractionClass = MessageContextMenuCommandInteraction;
|
|
40
41
|
break;
|
|
42
|
+
case ApplicationCommandType.PrimaryEntryPoint:
|
|
43
|
+
InteractionClass = PrimaryEntryPointCommandInteraction;
|
|
44
|
+
break;
|
|
41
45
|
default:
|
|
42
46
|
client.emit(
|
|
43
47
|
Events.Debug,
|
package/src/index.js
CHANGED
|
@@ -180,6 +180,7 @@ exports.PartialGroupDMChannel = require('./structures/PartialGroupDMChannel');
|
|
|
180
180
|
exports.PermissionOverwrites = require('./structures/PermissionOverwrites');
|
|
181
181
|
exports.Poll = require('./structures/Poll').Poll;
|
|
182
182
|
exports.PollAnswer = require('./structures/PollAnswer').PollAnswer;
|
|
183
|
+
exports.PrimaryEntryPointCommandInteraction = require('./structures/PrimaryEntryPointCommandInteraction');
|
|
183
184
|
exports.Presence = require('./structures/Presence').Presence;
|
|
184
185
|
exports.ReactionCollector = require('./structures/ReactionCollector');
|
|
185
186
|
exports.ReactionEmoji = require('./structures/ReactionEmoji');
|
|
@@ -261,6 +261,7 @@ class ApplicationCommandManager extends CachedManager {
|
|
|
261
261
|
dm_permission: command.dmPermission ?? command.dm_permission,
|
|
262
262
|
integration_types: command.integrationTypes ?? command.integration_types,
|
|
263
263
|
contexts: command.contexts,
|
|
264
|
+
handler: command.handler,
|
|
264
265
|
};
|
|
265
266
|
}
|
|
266
267
|
}
|
|
@@ -69,6 +69,13 @@ class ChannelManager extends CachedManager {
|
|
|
69
69
|
|
|
70
70
|
channel?.parent?.threads?.cache.delete(id);
|
|
71
71
|
this.cache.delete(id);
|
|
72
|
+
|
|
73
|
+
if (channel?.threads) {
|
|
74
|
+
for (const threadId of channel.threads.cache.keys()) {
|
|
75
|
+
this.cache.delete(threadId);
|
|
76
|
+
channel.guild?.channels.cache.delete(threadId);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
/**
|
|
@@ -174,6 +174,18 @@ class ApplicationCommand extends Base {
|
|
|
174
174
|
this.contexts ??= null;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
if ('handler' in data) {
|
|
178
|
+
/**
|
|
179
|
+
* Determines whether the interaction is handled by the app's interactions handler or by Discord.
|
|
180
|
+
* <info>Only available for {@link ApplicationCommandType.PrimaryEntryPoint} commands on
|
|
181
|
+
* applications with the {@link ApplicationFlags.Embedded} flag (i.e, those that have an Activity)</info>
|
|
182
|
+
* @type {?EntryPointCommandHandlerType}
|
|
183
|
+
*/
|
|
184
|
+
this.handler = data.handler;
|
|
185
|
+
} else {
|
|
186
|
+
this.handler ??= null;
|
|
187
|
+
}
|
|
188
|
+
|
|
177
189
|
if ('version' in data) {
|
|
178
190
|
/**
|
|
179
191
|
* Autoincrementing version identifier updated during substantial record changes
|
|
@@ -216,15 +228,20 @@ class ApplicationCommand extends Base {
|
|
|
216
228
|
* @property {string} name The name of the command, must be in all lowercase if type is
|
|
217
229
|
* {@link ApplicationCommandType.ChatInput}
|
|
218
230
|
* @property {Object<Locale, string>} [nameLocalizations] The localizations for the command name
|
|
219
|
-
* @property {string} description The description of the command,
|
|
231
|
+
* @property {string} description The description of the command,
|
|
232
|
+
* if type is {@link ApplicationCommandType.ChatInput} or {@link ApplicationCommandType.PrimaryEntryPoint}
|
|
220
233
|
* @property {boolean} [nsfw] Whether the command is age-restricted
|
|
221
234
|
* @property {Object<Locale, string>} [descriptionLocalizations] The localizations for the command description,
|
|
222
|
-
* if type is {@link ApplicationCommandType.ChatInput}
|
|
235
|
+
* if type is {@link ApplicationCommandType.ChatInput} or {@link ApplicationCommandType.PrimaryEntryPoint}
|
|
223
236
|
* @property {ApplicationCommandType} [type=ApplicationCommandType.ChatInput] The type of the command
|
|
224
237
|
* @property {ApplicationCommandOptionData[]} [options] Options for the command
|
|
225
238
|
* @property {?PermissionResolvable} [defaultMemberPermissions] The bitfield used to determine the default permissions
|
|
226
239
|
* a member needs in order to run the command
|
|
227
240
|
* @property {boolean} [dmPermission] Whether the command is enabled in DMs
|
|
241
|
+
* @property {ApplicationIntegrationType[]} [integrationTypes] Installation contexts where the command is available
|
|
242
|
+
* @property {InteractionContextType[]} [contexts] Interaction contexts where the command can be used
|
|
243
|
+
* @property {EntryPointCommandHandlerType} [handler] Whether the interaction is handled by the app's
|
|
244
|
+
* interactions handler or by Discord.
|
|
228
245
|
*/
|
|
229
246
|
|
|
230
247
|
/**
|
|
@@ -419,7 +436,8 @@ class ApplicationCommand extends Base {
|
|
|
419
436
|
this.descriptionLocalizations ?? {},
|
|
420
437
|
) ||
|
|
421
438
|
!isEqual(command.integrationTypes ?? command.integration_types ?? [], this.integrationTypes ?? []) ||
|
|
422
|
-
!isEqual(command.contexts ?? [], this.contexts ?? [])
|
|
439
|
+
!isEqual(command.contexts ?? [], this.contexts ?? []) ||
|
|
440
|
+
('handler' in command && command.handler !== this.handler)
|
|
423
441
|
) {
|
|
424
442
|
return false;
|
|
425
443
|
}
|
|
@@ -122,6 +122,12 @@ class BaseInteraction extends Base {
|
|
|
122
122
|
* @type {?InteractionContextType}
|
|
123
123
|
*/
|
|
124
124
|
this.context = data.context ?? null;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Attachment size limit in bytes
|
|
128
|
+
* @type {number}
|
|
129
|
+
*/
|
|
130
|
+
this.attachmentSizeLimit = data.attachment_size_limit;
|
|
125
131
|
}
|
|
126
132
|
|
|
127
133
|
/**
|
|
@@ -219,6 +225,16 @@ class BaseInteraction extends Base {
|
|
|
219
225
|
);
|
|
220
226
|
}
|
|
221
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Indicates whether this interaction is a {@link PrimaryEntryPointCommandInteraction}
|
|
230
|
+
* @returns {boolean}
|
|
231
|
+
*/
|
|
232
|
+
isPrimaryEntryPointCommand() {
|
|
233
|
+
return (
|
|
234
|
+
this.type === InteractionType.ApplicationCommand && this.commandType === ApplicationCommandType.PrimaryEntryPoint
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
222
238
|
/**
|
|
223
239
|
* Indicates whether this interaction is a {@link MessageComponentInteraction}
|
|
224
240
|
* @returns {boolean}
|
|
@@ -163,6 +163,17 @@ class ClientApplication extends Application {
|
|
|
163
163
|
this.approximateUserInstallCount ??= null;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
if ('approximate_user_authorization_count' in data) {
|
|
167
|
+
/**
|
|
168
|
+
* An approximate amount of users that have OAuth2 authorizations for this application.
|
|
169
|
+
*
|
|
170
|
+
* @type {?number}
|
|
171
|
+
*/
|
|
172
|
+
this.approximateUserAuthorizationCount = data.approximate_user_authorization_count;
|
|
173
|
+
} else {
|
|
174
|
+
this.approximateUserAuthorizationCount ??= null;
|
|
175
|
+
}
|
|
176
|
+
|
|
166
177
|
if ('guild_id' in data) {
|
|
167
178
|
/**
|
|
168
179
|
* The id of the guild associated with this application.
|
|
@@ -122,6 +122,20 @@ class GuildMember extends Base {
|
|
|
122
122
|
} else {
|
|
123
123
|
this.flags ??= new GuildMemberFlagsBitField().freeze();
|
|
124
124
|
}
|
|
125
|
+
|
|
126
|
+
if (data.avatar_decoration_data) {
|
|
127
|
+
/**
|
|
128
|
+
* The member avatar decoration's data
|
|
129
|
+
*
|
|
130
|
+
* @type {?AvatarDecorationData}
|
|
131
|
+
*/
|
|
132
|
+
this.avatarDecorationData = {
|
|
133
|
+
asset: data.avatar_decoration_data.asset,
|
|
134
|
+
skuId: data.avatar_decoration_data.sku_id,
|
|
135
|
+
};
|
|
136
|
+
} else {
|
|
137
|
+
this.avatarDecorationData = null;
|
|
138
|
+
}
|
|
125
139
|
}
|
|
126
140
|
|
|
127
141
|
_clone() {
|
|
@@ -166,6 +180,15 @@ class GuildMember extends Base {
|
|
|
166
180
|
return this.avatar && this.client.rest.cdn.guildMemberAvatar(this.guild.id, this.id, this.avatar, options);
|
|
167
181
|
}
|
|
168
182
|
|
|
183
|
+
/**
|
|
184
|
+
* A link to the member's avatar decoration.
|
|
185
|
+
*
|
|
186
|
+
* @returns {?string}
|
|
187
|
+
*/
|
|
188
|
+
avatarDecorationURL() {
|
|
189
|
+
return this.avatarDecorationData ? this.client.rest.cdn.avatarDecoration(this.avatarDecorationData.asset) : null;
|
|
190
|
+
}
|
|
191
|
+
|
|
169
192
|
/**
|
|
170
193
|
* A link to the member's banner.
|
|
171
194
|
* @param {ImageURLOptions} [options={}] Options for the banner URL
|
|
@@ -195,6 +218,16 @@ class GuildMember extends Base {
|
|
|
195
218
|
return this.bannerURL(options) ?? this.user.bannerURL(options);
|
|
196
219
|
}
|
|
197
220
|
|
|
221
|
+
/**
|
|
222
|
+
* A link to the member's guild avatar decoration if they have one.
|
|
223
|
+
* Otherwise, a link to their {@link User#avatarDecorationURL} will be returned.
|
|
224
|
+
*
|
|
225
|
+
* @returns {?string}
|
|
226
|
+
*/
|
|
227
|
+
displayAvatarDecorationURL() {
|
|
228
|
+
return this.avatarDecorationURL() ?? this.user.avatarDecorationURL();
|
|
229
|
+
}
|
|
230
|
+
|
|
198
231
|
/**
|
|
199
232
|
* The time this member joined the guild
|
|
200
233
|
* @type {?Date}
|
|
@@ -499,7 +532,10 @@ class GuildMember extends Base {
|
|
|
499
532
|
this.communicationDisabledUntilTimestamp === member.communicationDisabledUntilTimestamp &&
|
|
500
533
|
this.flags.bitfield === member.flags.bitfield &&
|
|
501
534
|
(this._roles === member._roles ||
|
|
502
|
-
(this._roles.length === member._roles.length &&
|
|
535
|
+
(this._roles.length === member._roles.length &&
|
|
536
|
+
this._roles.every((role, index) => role === member._roles[index]))) &&
|
|
537
|
+
this.avatarDecorationData?.asset === member.avatarDecorationData?.asset &&
|
|
538
|
+
this.avatarDecorationData?.skuId === member.avatarDecorationData?.skuId
|
|
503
539
|
);
|
|
504
540
|
}
|
|
505
541
|
|
|
@@ -525,6 +561,7 @@ class GuildMember extends Base {
|
|
|
525
561
|
json.bannerURL = this.bannerURL();
|
|
526
562
|
json.displayAvatarURL = this.displayAvatarURL();
|
|
527
563
|
json.displayBannerURL = this.displayBannerURL();
|
|
564
|
+
json.avatarDecorationURL = this.avatarDecorationURL();
|
|
528
565
|
return json;
|
|
529
566
|
}
|
|
530
567
|
}
|
|
@@ -27,7 +27,7 @@ class PartialGroupDMChannel extends BaseChannel {
|
|
|
27
27
|
* The hash of the channel icon
|
|
28
28
|
* @type {?string}
|
|
29
29
|
*/
|
|
30
|
-
this.icon = data.icon;
|
|
30
|
+
this.icon = data.icon ?? null;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Recipient data received in a {@link PartialGroupDMChannel}.
|
|
@@ -39,7 +39,7 @@ class PartialGroupDMChannel extends BaseChannel {
|
|
|
39
39
|
* The recipients of this Group DM Channel.
|
|
40
40
|
* @type {PartialRecipient[]}
|
|
41
41
|
*/
|
|
42
|
-
this.recipients = data.recipients;
|
|
42
|
+
this.recipients = data.recipients ?? [];
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* A manager of the messages belonging to this channel
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const CommandInteraction = require('./CommandInteraction.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents a primary entry point command interaction.
|
|
7
|
+
* @extends {CommandInteraction}
|
|
8
|
+
*/
|
|
9
|
+
class PrimaryEntryPointCommandInteraction extends CommandInteraction {}
|
|
10
|
+
|
|
11
|
+
module.exports = PrimaryEntryPointCommandInteraction;
|
|
@@ -69,6 +69,12 @@ class InteractionResponses {
|
|
|
69
69
|
* <warn>This option is deprecated. Use `withResponse` or fetch the response instead.</warn>
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Options for launching activity in response to a {@link BaseInteraction}
|
|
74
|
+
* @typedef {Object} LaunchActivityOptions
|
|
75
|
+
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
|
|
76
|
+
*/
|
|
77
|
+
|
|
72
78
|
/**
|
|
73
79
|
* Options for showing a modal in response to a {@link BaseInteraction}
|
|
74
80
|
* @typedef {Object} ShowModalOptions
|
|
@@ -370,6 +376,25 @@ class InteractionResponses {
|
|
|
370
376
|
: new InteractionResponse(this, this.message.interactionMetadata?.id);
|
|
371
377
|
}
|
|
372
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Launches this application's activity, if enabled
|
|
381
|
+
* @param {LaunchActivityOptions} [options={}] Options for launching the activity
|
|
382
|
+
* @returns {Promise<InteractionCallbackResponse|undefined>}
|
|
383
|
+
*/
|
|
384
|
+
async launchActivity({ withResponse } = {}) {
|
|
385
|
+
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
|
|
386
|
+
const response = await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
|
|
387
|
+
query: makeURLSearchParams({ with_response: withResponse ?? false }),
|
|
388
|
+
body: {
|
|
389
|
+
type: InteractionResponseType.LaunchActivity,
|
|
390
|
+
},
|
|
391
|
+
auth: false,
|
|
392
|
+
});
|
|
393
|
+
this.replied = true;
|
|
394
|
+
|
|
395
|
+
return withResponse ? new InteractionCallbackResponse(this.client, response) : undefined;
|
|
396
|
+
}
|
|
397
|
+
|
|
373
398
|
/**
|
|
374
399
|
* Shows a modal component
|
|
375
400
|
* @param {ModalBuilder|ModalComponentData|APIModalInteractionResponseCallbackData} modal The modal to show
|
|
@@ -450,6 +475,7 @@ class InteractionResponses {
|
|
|
450
475
|
'followUp',
|
|
451
476
|
'deferUpdate',
|
|
452
477
|
'update',
|
|
478
|
+
'launchActivity',
|
|
453
479
|
'showModal',
|
|
454
480
|
'sendPremiumRequired',
|
|
455
481
|
'awaitModalSubmit',
|
package/src/util/APITypes.js
CHANGED
|
@@ -370,6 +370,11 @@
|
|
|
370
370
|
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/EntitlementType}
|
|
371
371
|
*/
|
|
372
372
|
|
|
373
|
+
/**
|
|
374
|
+
* @external EntryPointCommandHandlerType
|
|
375
|
+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/EntryPointCommandHandlerType}
|
|
376
|
+
*/
|
|
377
|
+
|
|
373
378
|
/**
|
|
374
379
|
* @external ForumLayoutType
|
|
375
380
|
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ForumLayoutType}
|
package/src/util/Components.js
CHANGED
|
@@ -141,44 +141,7 @@ const { ComponentType } = require('discord-api-types/v10');
|
|
|
141
141
|
* @ignore
|
|
142
142
|
*/
|
|
143
143
|
function createComponent(data) {
|
|
144
|
-
|
|
145
|
-
return data;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
switch (data.type) {
|
|
149
|
-
case ComponentType.ActionRow:
|
|
150
|
-
return new ActionRow(data);
|
|
151
|
-
case ComponentType.Button:
|
|
152
|
-
return new ButtonComponent(data);
|
|
153
|
-
case ComponentType.StringSelect:
|
|
154
|
-
return new StringSelectMenuComponent(data);
|
|
155
|
-
case ComponentType.TextInput:
|
|
156
|
-
return new TextInputComponent(data);
|
|
157
|
-
case ComponentType.UserSelect:
|
|
158
|
-
return new UserSelectMenuComponent(data);
|
|
159
|
-
case ComponentType.RoleSelect:
|
|
160
|
-
return new RoleSelectMenuComponent(data);
|
|
161
|
-
case ComponentType.MentionableSelect:
|
|
162
|
-
return new MentionableSelectMenuComponent(data);
|
|
163
|
-
case ComponentType.ChannelSelect:
|
|
164
|
-
return new ChannelSelectMenuComponent(data);
|
|
165
|
-
case ComponentType.Container:
|
|
166
|
-
return new ContainerComponent(data);
|
|
167
|
-
case ComponentType.TextDisplay:
|
|
168
|
-
return new TextDisplayComponent(data);
|
|
169
|
-
case ComponentType.File:
|
|
170
|
-
return new FileComponent(data);
|
|
171
|
-
case ComponentType.MediaGallery:
|
|
172
|
-
return new MediaGalleryComponent(data);
|
|
173
|
-
case ComponentType.Section:
|
|
174
|
-
return new SectionComponent(data);
|
|
175
|
-
case ComponentType.Separator:
|
|
176
|
-
return new SeparatorComponent(data);
|
|
177
|
-
case ComponentType.Thumbnail:
|
|
178
|
-
return new ThumbnailComponent(data);
|
|
179
|
-
default:
|
|
180
|
-
return new Component(data);
|
|
181
|
-
}
|
|
144
|
+
return data instanceof Component ? data : new (ComponentTypeToComponent[data.type] ?? Component)(data);
|
|
182
145
|
}
|
|
183
146
|
|
|
184
147
|
/**
|
|
@@ -188,30 +151,7 @@ function createComponent(data) {
|
|
|
188
151
|
* @ignore
|
|
189
152
|
*/
|
|
190
153
|
function createComponentBuilder(data) {
|
|
191
|
-
|
|
192
|
-
return data;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
switch (data.type) {
|
|
196
|
-
case ComponentType.ActionRow:
|
|
197
|
-
return new ActionRowBuilder(data);
|
|
198
|
-
case ComponentType.Button:
|
|
199
|
-
return new ButtonBuilder(data);
|
|
200
|
-
case ComponentType.StringSelect:
|
|
201
|
-
return new StringSelectMenuBuilder(data);
|
|
202
|
-
case ComponentType.TextInput:
|
|
203
|
-
return new TextInputBuilder(data);
|
|
204
|
-
case ComponentType.UserSelect:
|
|
205
|
-
return new UserSelectMenuBuilder(data);
|
|
206
|
-
case ComponentType.RoleSelect:
|
|
207
|
-
return new RoleSelectMenuBuilder(data);
|
|
208
|
-
case ComponentType.MentionableSelect:
|
|
209
|
-
return new MentionableSelectMenuBuilder(data);
|
|
210
|
-
case ComponentType.ChannelSelect:
|
|
211
|
-
return new ChannelSelectMenuBuilder(data);
|
|
212
|
-
default:
|
|
213
|
-
return new ComponentBuilder(data);
|
|
214
|
-
}
|
|
154
|
+
return data instanceof ComponentBuilder ? data : new (ComponentTypeToBuilder[data.type] ?? ComponentBuilder)(data);
|
|
215
155
|
}
|
|
216
156
|
|
|
217
157
|
/**
|
|
@@ -274,3 +214,32 @@ const TextInputComponent = require('../structures/TextInputComponent');
|
|
|
274
214
|
const ThumbnailComponent = require('../structures/ThumbnailComponent');
|
|
275
215
|
const UserSelectMenuBuilder = require('../structures/UserSelectMenuBuilder');
|
|
276
216
|
const UserSelectMenuComponent = require('../structures/UserSelectMenuComponent');
|
|
217
|
+
|
|
218
|
+
const ComponentTypeToComponent = {
|
|
219
|
+
[ComponentType.ActionRow]: ActionRow,
|
|
220
|
+
[ComponentType.Button]: ButtonComponent,
|
|
221
|
+
[ComponentType.StringSelect]: StringSelectMenuComponent,
|
|
222
|
+
[ComponentType.TextInput]: TextInputComponent,
|
|
223
|
+
[ComponentType.UserSelect]: UserSelectMenuComponent,
|
|
224
|
+
[ComponentType.RoleSelect]: RoleSelectMenuComponent,
|
|
225
|
+
[ComponentType.MentionableSelect]: MentionableSelectMenuComponent,
|
|
226
|
+
[ComponentType.ChannelSelect]: ChannelSelectMenuComponent,
|
|
227
|
+
[ComponentType.Container]: ContainerComponent,
|
|
228
|
+
[ComponentType.TextDisplay]: TextDisplayComponent,
|
|
229
|
+
[ComponentType.File]: FileComponent,
|
|
230
|
+
[ComponentType.MediaGallery]: MediaGalleryComponent,
|
|
231
|
+
[ComponentType.Section]: SectionComponent,
|
|
232
|
+
[ComponentType.Separator]: SeparatorComponent,
|
|
233
|
+
[ComponentType.Thumbnail]: ThumbnailComponent,
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const ComponentTypeToBuilder = {
|
|
237
|
+
[ComponentType.ActionRow]: ActionRowBuilder,
|
|
238
|
+
[ComponentType.Button]: ButtonBuilder,
|
|
239
|
+
[ComponentType.StringSelect]: StringSelectMenuBuilder,
|
|
240
|
+
[ComponentType.TextInput]: TextInputBuilder,
|
|
241
|
+
[ComponentType.UserSelect]: UserSelectMenuBuilder,
|
|
242
|
+
[ComponentType.RoleSelect]: RoleSelectMenuBuilder,
|
|
243
|
+
[ComponentType.MentionableSelect]: MentionableSelectMenuBuilder,
|
|
244
|
+
[ComponentType.ChannelSelect]: ChannelSelectMenuBuilder,
|
|
245
|
+
};
|
package/src/util/Transformers.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { isJSONEncodable } = require('@discordjs/util');
|
|
4
4
|
const snakeCase = require('lodash.snakecase');
|
|
5
|
+
const { resolvePartialEmoji } = require('./Util');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Transforms camel-cased keys into snake cased keys
|
|
@@ -13,7 +14,14 @@ function toSnakeCase(obj) {
|
|
|
13
14
|
if (obj instanceof Date) return obj;
|
|
14
15
|
if (isJSONEncodable(obj)) return toSnakeCase(obj.toJSON());
|
|
15
16
|
if (Array.isArray(obj)) return obj.map(toSnakeCase);
|
|
16
|
-
return Object.fromEntries(
|
|
17
|
+
return Object.fromEntries(
|
|
18
|
+
Object.entries(obj).map(([key, value]) => [
|
|
19
|
+
snakeCase(key),
|
|
20
|
+
// TODO: The special handling of 'emoji' is just a temporary fix for v14, will be dropped in v15.
|
|
21
|
+
// See https://github.com/discordjs/discord.js/issues/10909
|
|
22
|
+
key === 'emoji' && typeof value === 'string' ? resolvePartialEmoji(value) : toSnakeCase(value),
|
|
23
|
+
]),
|
|
24
|
+
);
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
/**
|