@discordjs/builders 2.0.0-dev.1741219959-e273afbb9 → 2.0.0-dev.1741953893-09beb8a6a
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/dist/index.d.mts +1335 -8
- package/dist/index.d.ts +1335 -8
- package/dist/index.js +866 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +858 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,12 +22,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
ActionRowBuilder: () => ActionRowBuilder,
|
|
25
|
+
AllowedMentionsBuilder: () => AllowedMentionsBuilder,
|
|
25
26
|
ApplicationCommandNumericOptionMinMaxValueMixin: () => ApplicationCommandNumericOptionMinMaxValueMixin,
|
|
26
27
|
ApplicationCommandOptionAllowedChannelTypes: () => ApplicationCommandOptionAllowedChannelTypes,
|
|
27
28
|
ApplicationCommandOptionBase: () => ApplicationCommandOptionBase,
|
|
28
29
|
ApplicationCommandOptionChannelTypesMixin: () => ApplicationCommandOptionChannelTypesMixin,
|
|
29
30
|
ApplicationCommandOptionWithAutocompleteMixin: () => ApplicationCommandOptionWithAutocompleteMixin,
|
|
30
31
|
ApplicationCommandOptionWithChoicesMixin: () => ApplicationCommandOptionWithChoicesMixin,
|
|
32
|
+
AttachmentBuilder: () => AttachmentBuilder,
|
|
31
33
|
BaseButtonBuilder: () => BaseButtonBuilder,
|
|
32
34
|
BaseSelectMenuBuilder: () => BaseSelectMenuBuilder,
|
|
33
35
|
ChannelSelectMenuBuilder: () => ChannelSelectMenuBuilder,
|
|
@@ -55,7 +57,9 @@ __export(index_exports, {
|
|
|
55
57
|
EmojiOrLabelButtonMixin: () => EmojiOrLabelButtonMixin,
|
|
56
58
|
LinkButtonBuilder: () => LinkButtonBuilder,
|
|
57
59
|
MentionableSelectMenuBuilder: () => MentionableSelectMenuBuilder,
|
|
60
|
+
MessageBuilder: () => MessageBuilder,
|
|
58
61
|
MessageContextCommandBuilder: () => MessageContextCommandBuilder,
|
|
62
|
+
MessageReferenceBuilder: () => MessageReferenceBuilder,
|
|
59
63
|
ModalBuilder: () => ModalBuilder,
|
|
60
64
|
PollAnswerBuilder: () => PollAnswerBuilder,
|
|
61
65
|
PollAnswerMediaBuilder: () => PollAnswerMediaBuilder,
|
|
@@ -77,6 +81,8 @@ __export(index_exports, {
|
|
|
77
81
|
UserContextCommandBuilder: () => UserContextCommandBuilder,
|
|
78
82
|
UserSelectMenuBuilder: () => UserSelectMenuBuilder,
|
|
79
83
|
actionRowPredicate: () => actionRowPredicate,
|
|
84
|
+
allowedMentionPredicate: () => allowedMentionPredicate,
|
|
85
|
+
attachmentPredicate: () => attachmentPredicate,
|
|
80
86
|
basicOptionPredicate: () => basicOptionPredicate,
|
|
81
87
|
buttonPredicate: () => buttonPredicate,
|
|
82
88
|
channelOptionPredicate: () => channelOptionPredicate,
|
|
@@ -98,6 +104,8 @@ __export(index_exports, {
|
|
|
98
104
|
localeMapPredicate: () => localeMapPredicate,
|
|
99
105
|
memberPermissionsPredicate: () => memberPermissionsPredicate,
|
|
100
106
|
messageCommandPredicate: () => messageCommandPredicate,
|
|
107
|
+
messagePredicate: () => messagePredicate,
|
|
108
|
+
messageReferencePredicate: () => messageReferencePredicate,
|
|
101
109
|
modalPredicate: () => modalPredicate,
|
|
102
110
|
normalizeArray: () => normalizeArray,
|
|
103
111
|
numberOptionPredicate: () => numberOptionPredicate,
|
|
@@ -980,7 +988,7 @@ var StringSelectMenuBuilder = class extends BaseSelectMenuBuilder {
|
|
|
980
988
|
*
|
|
981
989
|
* @remarks
|
|
982
990
|
* This method behaves similarly
|
|
983
|
-
* to {@link https://developer.mozilla.org/
|
|
991
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/slice | Array.prototype.splice()}.
|
|
984
992
|
* It's useful for modifying and adjusting the order of existing options.
|
|
985
993
|
* @example
|
|
986
994
|
* Remove the first option:
|
|
@@ -1492,7 +1500,7 @@ var ActionRowBuilder = class extends ComponentBuilder {
|
|
|
1492
1500
|
*
|
|
1493
1501
|
* @remarks
|
|
1494
1502
|
* This method behaves similarly
|
|
1495
|
-
* to {@link https://developer.mozilla.org/
|
|
1503
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
1496
1504
|
*
|
|
1497
1505
|
* It's useful for modifying and adjusting order of the already-existing components of an action row.
|
|
1498
1506
|
* @example
|
|
@@ -2143,7 +2151,7 @@ var SharedChatInputCommandOptions = class {
|
|
|
2143
2151
|
*
|
|
2144
2152
|
* @remarks
|
|
2145
2153
|
* This method behaves similarly
|
|
2146
|
-
* to {@link https://developer.mozilla.org/
|
|
2154
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
2147
2155
|
*
|
|
2148
2156
|
* It's useful for modifying and adjusting order of the already-existing options for this command.
|
|
2149
2157
|
* @example
|
|
@@ -2513,7 +2521,7 @@ var ModalBuilder = class {
|
|
|
2513
2521
|
*
|
|
2514
2522
|
* @remarks
|
|
2515
2523
|
* This method behaves similarly
|
|
2516
|
-
* to {@link https://developer.mozilla.org/
|
|
2524
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
2517
2525
|
* The maximum amount of action rows that can be added is 5.
|
|
2518
2526
|
*
|
|
2519
2527
|
* It's useful for modifying and adjusting order of the already-existing action rows of a modal.
|
|
@@ -2571,10 +2579,10 @@ __name(embedLength, "embedLength");
|
|
|
2571
2579
|
|
|
2572
2580
|
// src/messages/embed/Assertions.ts
|
|
2573
2581
|
var namePredicate3 = import_zod7.z.string().max(256);
|
|
2574
|
-
var iconURLPredicate = import_zod7.z.string().url().refine(refineURLPredicate(["http:", "https:", "attachment:"]), {
|
|
2575
|
-
message: "Invalid protocol for icon URL. Must be http:, https:, or attachment:"
|
|
2576
|
-
});
|
|
2577
2582
|
var URLPredicate = import_zod7.z.string().url().refine(refineURLPredicate(["http:", "https:"]), { message: "Invalid protocol for URL. Must be http: or https:" });
|
|
2583
|
+
var URLWithAttachmentProtocolPredicate = import_zod7.z.string().url().refine(refineURLPredicate(["http:", "https:", "attachment:"]), {
|
|
2584
|
+
message: "Invalid protocol for URL. Must be http:, https:, or attachment:"
|
|
2585
|
+
});
|
|
2578
2586
|
var embedFieldPredicate = import_zod7.z.object({
|
|
2579
2587
|
name: namePredicate3,
|
|
2580
2588
|
value: import_zod7.z.string().max(1024),
|
|
@@ -2582,12 +2590,12 @@ var embedFieldPredicate = import_zod7.z.object({
|
|
|
2582
2590
|
});
|
|
2583
2591
|
var embedAuthorPredicate = import_zod7.z.object({
|
|
2584
2592
|
name: namePredicate3.min(1),
|
|
2585
|
-
icon_url:
|
|
2593
|
+
icon_url: URLWithAttachmentProtocolPredicate.optional(),
|
|
2586
2594
|
url: URLPredicate.optional()
|
|
2587
2595
|
});
|
|
2588
2596
|
var embedFooterPredicate = import_zod7.z.object({
|
|
2589
2597
|
text: import_zod7.z.string().min(1).max(2048),
|
|
2590
|
-
icon_url:
|
|
2598
|
+
icon_url: URLWithAttachmentProtocolPredicate.optional()
|
|
2591
2599
|
});
|
|
2592
2600
|
var embedPredicate = import_zod7.z.object({
|
|
2593
2601
|
title: namePredicate3.min(1).optional(),
|
|
@@ -2596,8 +2604,8 @@ var embedPredicate = import_zod7.z.object({
|
|
|
2596
2604
|
timestamp: import_zod7.z.string().optional(),
|
|
2597
2605
|
color: import_zod7.z.number().int().min(0).max(16777215).optional(),
|
|
2598
2606
|
footer: embedFooterPredicate.optional(),
|
|
2599
|
-
image: import_zod7.z.object({ url:
|
|
2600
|
-
thumbnail: import_zod7.z.object({ url:
|
|
2607
|
+
image: import_zod7.z.object({ url: URLWithAttachmentProtocolPredicate }).optional(),
|
|
2608
|
+
thumbnail: import_zod7.z.object({ url: URLWithAttachmentProtocolPredicate }).optional(),
|
|
2601
2609
|
author: embedAuthorPredicate.optional(),
|
|
2602
2610
|
fields: import_zod7.z.array(embedFieldPredicate).max(25).optional()
|
|
2603
2611
|
}).refine(
|
|
@@ -2854,7 +2862,7 @@ var EmbedBuilder = class {
|
|
|
2854
2862
|
*
|
|
2855
2863
|
* @remarks
|
|
2856
2864
|
* This method behaves similarly
|
|
2857
|
-
* to {@link https://developer.mozilla.org/
|
|
2865
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
2858
2866
|
* The maximum amount of fields that can be added is 25.
|
|
2859
2867
|
*
|
|
2860
2868
|
* It's useful for modifying and adjusting order of the already-existing fields of an embed.
|
|
@@ -3290,7 +3298,7 @@ var PollBuilder = class {
|
|
|
3290
3298
|
*
|
|
3291
3299
|
* @remarks
|
|
3292
3300
|
* This method behaves similarly
|
|
3293
|
-
* to {@link https://developer.mozilla.org/
|
|
3301
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
3294
3302
|
* The maximum amount of answers that can be added is 10.
|
|
3295
3303
|
*
|
|
3296
3304
|
* It's useful for modifying and adjusting order of the already-existing answers of a poll.
|
|
@@ -3418,17 +3426,855 @@ var PollBuilder = class {
|
|
|
3418
3426
|
}
|
|
3419
3427
|
};
|
|
3420
3428
|
|
|
3429
|
+
// src/messages/Assertions.ts
|
|
3430
|
+
var import_v1033 = require("discord-api-types/v10");
|
|
3431
|
+
var import_zod9 = require("zod");
|
|
3432
|
+
var attachmentPredicate = import_zod9.z.object({
|
|
3433
|
+
id: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number()]),
|
|
3434
|
+
description: import_zod9.z.string().optional(),
|
|
3435
|
+
duration_secs: import_zod9.z.number().optional(),
|
|
3436
|
+
filename: import_zod9.z.string().optional(),
|
|
3437
|
+
title: import_zod9.z.string().optional(),
|
|
3438
|
+
waveform: import_zod9.z.string().optional()
|
|
3439
|
+
});
|
|
3440
|
+
var allowedMentionPredicate = import_zod9.z.object({
|
|
3441
|
+
parse: import_zod9.z.nativeEnum(import_v1033.AllowedMentionsTypes).array().optional(),
|
|
3442
|
+
roles: import_zod9.z.string().array().optional(),
|
|
3443
|
+
users: import_zod9.z.string().array().optional(),
|
|
3444
|
+
replied_user: import_zod9.z.boolean().optional()
|
|
3445
|
+
});
|
|
3446
|
+
var messageReferencePredicate = import_zod9.z.object({
|
|
3447
|
+
channel_id: import_zod9.z.string().optional(),
|
|
3448
|
+
fail_if_not_exists: import_zod9.z.boolean().optional(),
|
|
3449
|
+
guild_id: import_zod9.z.string().optional(),
|
|
3450
|
+
message_id: import_zod9.z.string(),
|
|
3451
|
+
type: import_zod9.z.nativeEnum(import_v1033.MessageReferenceType).optional()
|
|
3452
|
+
});
|
|
3453
|
+
var messagePredicate = import_zod9.z.object({
|
|
3454
|
+
content: import_zod9.z.string().optional(),
|
|
3455
|
+
nonce: import_zod9.z.union([import_zod9.z.string().max(25), import_zod9.z.number()]).optional(),
|
|
3456
|
+
tts: import_zod9.z.boolean().optional(),
|
|
3457
|
+
embeds: embedPredicate.array().max(10).optional(),
|
|
3458
|
+
allowed_mentions: allowedMentionPredicate.optional(),
|
|
3459
|
+
message_reference: messageReferencePredicate.optional(),
|
|
3460
|
+
// Partial validation here to ensure the components are valid,
|
|
3461
|
+
// rest of the validation is done in the action row predicate
|
|
3462
|
+
components: import_zod9.z.object({
|
|
3463
|
+
type: import_zod9.z.literal(import_v1033.ComponentType.ActionRow),
|
|
3464
|
+
components: import_zod9.z.object({
|
|
3465
|
+
type: import_zod9.z.union([
|
|
3466
|
+
import_zod9.z.literal(import_v1033.ComponentType.Button),
|
|
3467
|
+
import_zod9.z.literal(import_v1033.ComponentType.ChannelSelect),
|
|
3468
|
+
import_zod9.z.literal(import_v1033.ComponentType.MentionableSelect),
|
|
3469
|
+
import_zod9.z.literal(import_v1033.ComponentType.RoleSelect),
|
|
3470
|
+
import_zod9.z.literal(import_v1033.ComponentType.StringSelect),
|
|
3471
|
+
import_zod9.z.literal(import_v1033.ComponentType.UserSelect)
|
|
3472
|
+
])
|
|
3473
|
+
}).array()
|
|
3474
|
+
}).array().max(5).optional(),
|
|
3475
|
+
sticker_ids: import_zod9.z.array(import_zod9.z.string()).min(0).max(3).optional(),
|
|
3476
|
+
attachments: attachmentPredicate.array().max(10).optional(),
|
|
3477
|
+
flags: import_zod9.z.number().optional(),
|
|
3478
|
+
enforce_nonce: import_zod9.z.boolean().optional(),
|
|
3479
|
+
poll: pollPredicate.optional()
|
|
3480
|
+
}).refine(
|
|
3481
|
+
(data) => {
|
|
3482
|
+
return data.content !== void 0 || data.embeds !== void 0 && data.embeds.length > 0 || data.poll !== void 0 || data.attachments !== void 0 && data.attachments.length > 0 || data.components !== void 0 && data.components.length > 0 || data.sticker_ids !== void 0 && data.sticker_ids.length > 0;
|
|
3483
|
+
},
|
|
3484
|
+
{ message: "Messages must have content, embeds, a poll, attachments, components, or stickers" }
|
|
3485
|
+
);
|
|
3486
|
+
|
|
3487
|
+
// src/messages/AllowedMentions.ts
|
|
3488
|
+
var AllowedMentionsBuilder = class {
|
|
3489
|
+
static {
|
|
3490
|
+
__name(this, "AllowedMentionsBuilder");
|
|
3491
|
+
}
|
|
3492
|
+
data;
|
|
3493
|
+
/**
|
|
3494
|
+
* Creates new allowed mention builder from API data.
|
|
3495
|
+
*
|
|
3496
|
+
* @param data - The API data to create this attachment with
|
|
3497
|
+
*/
|
|
3498
|
+
constructor(data = {}) {
|
|
3499
|
+
this.data = structuredClone(data);
|
|
3500
|
+
}
|
|
3501
|
+
/**
|
|
3502
|
+
* Sets the types of mentions to parse from the content.
|
|
3503
|
+
*
|
|
3504
|
+
* @param parse - The types of mentions to parse from the content
|
|
3505
|
+
*/
|
|
3506
|
+
setParse(...parse) {
|
|
3507
|
+
this.data.parse = normalizeArray(parse);
|
|
3508
|
+
return this;
|
|
3509
|
+
}
|
|
3510
|
+
/**
|
|
3511
|
+
* Sets the roles to mention.
|
|
3512
|
+
*
|
|
3513
|
+
* @param roles - The roles to mention
|
|
3514
|
+
*/
|
|
3515
|
+
setRoles(...roles) {
|
|
3516
|
+
this.data.roles = normalizeArray(roles);
|
|
3517
|
+
return this;
|
|
3518
|
+
}
|
|
3519
|
+
/**
|
|
3520
|
+
* Adds roles to mention.
|
|
3521
|
+
*
|
|
3522
|
+
* @param roles - The roles to mention
|
|
3523
|
+
*/
|
|
3524
|
+
addRoles(...roles) {
|
|
3525
|
+
this.data.roles ??= [];
|
|
3526
|
+
this.data.roles.push(...normalizeArray(roles));
|
|
3527
|
+
return this;
|
|
3528
|
+
}
|
|
3529
|
+
/**
|
|
3530
|
+
* Removes, replaces, or inserts roles.
|
|
3531
|
+
*
|
|
3532
|
+
* @remarks
|
|
3533
|
+
* This method behaves similarly
|
|
3534
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
3535
|
+
*
|
|
3536
|
+
* It's useful for modifying and adjusting order of the already-existing roles.
|
|
3537
|
+
* @example
|
|
3538
|
+
* Remove the first role:
|
|
3539
|
+
* ```ts
|
|
3540
|
+
* allowedMentions.spliceRoles(0, 1);
|
|
3541
|
+
* ```
|
|
3542
|
+
* @example
|
|
3543
|
+
* Remove the first n role:
|
|
3544
|
+
* ```ts
|
|
3545
|
+
* const n = 4;
|
|
3546
|
+
* allowedMentions.spliceRoles(0, n);
|
|
3547
|
+
* ```
|
|
3548
|
+
* @example
|
|
3549
|
+
* Remove the last role:
|
|
3550
|
+
* ```ts
|
|
3551
|
+
* allowedMentions.spliceRoles(-1, 1);
|
|
3552
|
+
* ```
|
|
3553
|
+
* @param index - The index to start at
|
|
3554
|
+
* @param deleteCount - The number of roles to remove
|
|
3555
|
+
* @param roles - The replacing role ids
|
|
3556
|
+
*/
|
|
3557
|
+
spliceRoles(index, deleteCount, ...roles) {
|
|
3558
|
+
this.data.roles ??= [];
|
|
3559
|
+
this.data.roles.splice(index, deleteCount, ...normalizeArray(roles));
|
|
3560
|
+
return this;
|
|
3561
|
+
}
|
|
3562
|
+
/**
|
|
3563
|
+
* Sets the users to mention.
|
|
3564
|
+
*
|
|
3565
|
+
* @param users - The users to mention
|
|
3566
|
+
*/
|
|
3567
|
+
setUsers(...users) {
|
|
3568
|
+
this.data.users = normalizeArray(users);
|
|
3569
|
+
return this;
|
|
3570
|
+
}
|
|
3571
|
+
/**
|
|
3572
|
+
* Adds users to mention.
|
|
3573
|
+
*
|
|
3574
|
+
* @param users - The users to mention
|
|
3575
|
+
*/
|
|
3576
|
+
addUsers(...users) {
|
|
3577
|
+
this.data.users ??= [];
|
|
3578
|
+
this.data.users.push(...normalizeArray(users));
|
|
3579
|
+
return this;
|
|
3580
|
+
}
|
|
3581
|
+
/**
|
|
3582
|
+
* Removes, replaces, or inserts users.
|
|
3583
|
+
*
|
|
3584
|
+
* @remarks
|
|
3585
|
+
* This method behaves similarly
|
|
3586
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
3587
|
+
*
|
|
3588
|
+
* It's useful for modifying and adjusting order of the already-existing users.
|
|
3589
|
+
* @example
|
|
3590
|
+
* Remove the first user:
|
|
3591
|
+
* ```ts
|
|
3592
|
+
* allowedMentions.spliceUsers(0, 1);
|
|
3593
|
+
* ```
|
|
3594
|
+
* @example
|
|
3595
|
+
* Remove the first n user:
|
|
3596
|
+
* ```ts
|
|
3597
|
+
* const n = 4;
|
|
3598
|
+
* allowedMentions.spliceUsers(0, n);
|
|
3599
|
+
* ```
|
|
3600
|
+
* @example
|
|
3601
|
+
* Remove the last user:
|
|
3602
|
+
* ```ts
|
|
3603
|
+
* allowedMentions.spliceUsers(-1, 1);
|
|
3604
|
+
* ```
|
|
3605
|
+
* @param index - The index to start at
|
|
3606
|
+
* @param deleteCount - The number of users to remove
|
|
3607
|
+
* @param users - The replacing user ids
|
|
3608
|
+
*/
|
|
3609
|
+
spliceUsers(index, deleteCount, ...users) {
|
|
3610
|
+
this.data.users ??= [];
|
|
3611
|
+
this.data.users.splice(index, deleteCount, ...normalizeArray(users));
|
|
3612
|
+
return this;
|
|
3613
|
+
}
|
|
3614
|
+
/**
|
|
3615
|
+
* For replies, sets whether to mention the author of the message being replied to
|
|
3616
|
+
*/
|
|
3617
|
+
setRepliedUser(repliedUser = true) {
|
|
3618
|
+
this.data.replied_user = repliedUser;
|
|
3619
|
+
return this;
|
|
3620
|
+
}
|
|
3621
|
+
/**
|
|
3622
|
+
* Serializes this builder to API-compatible JSON data.
|
|
3623
|
+
*
|
|
3624
|
+
* Note that by disabling validation, there is no guarantee that the resulting object will be valid.
|
|
3625
|
+
*
|
|
3626
|
+
* @param validationOverride - Force validation to run/not run regardless of your global preference
|
|
3627
|
+
*/
|
|
3628
|
+
toJSON(validationOverride) {
|
|
3629
|
+
const clone = structuredClone(this.data);
|
|
3630
|
+
validate(allowedMentionPredicate, clone, validationOverride);
|
|
3631
|
+
return clone;
|
|
3632
|
+
}
|
|
3633
|
+
};
|
|
3634
|
+
|
|
3635
|
+
// src/messages/Attachment.ts
|
|
3636
|
+
var AttachmentBuilder = class {
|
|
3637
|
+
static {
|
|
3638
|
+
__name(this, "AttachmentBuilder");
|
|
3639
|
+
}
|
|
3640
|
+
data;
|
|
3641
|
+
/**
|
|
3642
|
+
* Creates new attachment builder from API data.
|
|
3643
|
+
*
|
|
3644
|
+
* @param data - The API data to create this attachment with
|
|
3645
|
+
*/
|
|
3646
|
+
constructor(data = {}) {
|
|
3647
|
+
this.data = structuredClone(data);
|
|
3648
|
+
}
|
|
3649
|
+
/**
|
|
3650
|
+
* @param id - The id of the attachment
|
|
3651
|
+
*/
|
|
3652
|
+
setId(id) {
|
|
3653
|
+
this.data.id = id;
|
|
3654
|
+
return this;
|
|
3655
|
+
}
|
|
3656
|
+
/**
|
|
3657
|
+
* Clears the id of this attachment.
|
|
3658
|
+
*/
|
|
3659
|
+
clearId() {
|
|
3660
|
+
this.data.id = void 0;
|
|
3661
|
+
return this;
|
|
3662
|
+
}
|
|
3663
|
+
/**
|
|
3664
|
+
* Sets the description of this attachment.
|
|
3665
|
+
*/
|
|
3666
|
+
setDescription(description) {
|
|
3667
|
+
this.data.description = description;
|
|
3668
|
+
return this;
|
|
3669
|
+
}
|
|
3670
|
+
/**
|
|
3671
|
+
* Clears the description of this attachment.
|
|
3672
|
+
*/
|
|
3673
|
+
clearDescription() {
|
|
3674
|
+
this.data.description = void 0;
|
|
3675
|
+
return this;
|
|
3676
|
+
}
|
|
3677
|
+
/**
|
|
3678
|
+
* Sets the duration of this attachment (audio clips).
|
|
3679
|
+
*
|
|
3680
|
+
* @param duration - The duration of the attachment in seconds
|
|
3681
|
+
*/
|
|
3682
|
+
setDuration(duration) {
|
|
3683
|
+
this.data.duration_secs = duration;
|
|
3684
|
+
return this;
|
|
3685
|
+
}
|
|
3686
|
+
/**
|
|
3687
|
+
* Clears the duration of this attachment.
|
|
3688
|
+
*/
|
|
3689
|
+
clearDuration() {
|
|
3690
|
+
this.data.duration_secs = void 0;
|
|
3691
|
+
return this;
|
|
3692
|
+
}
|
|
3693
|
+
/**
|
|
3694
|
+
* Sets the filename of this attachment.
|
|
3695
|
+
*
|
|
3696
|
+
* @param filename - The filename of the attachment
|
|
3697
|
+
*/
|
|
3698
|
+
setFilename(filename) {
|
|
3699
|
+
this.data.filename = filename;
|
|
3700
|
+
return this;
|
|
3701
|
+
}
|
|
3702
|
+
/**
|
|
3703
|
+
* Clears the filename of this attachment.
|
|
3704
|
+
*/
|
|
3705
|
+
clearFilename() {
|
|
3706
|
+
this.data.filename = void 0;
|
|
3707
|
+
return this;
|
|
3708
|
+
}
|
|
3709
|
+
/**
|
|
3710
|
+
* Sets the title of this attachment.
|
|
3711
|
+
*
|
|
3712
|
+
* @param title - The title of the attachment
|
|
3713
|
+
*/
|
|
3714
|
+
setTitle(title) {
|
|
3715
|
+
this.data.title = title;
|
|
3716
|
+
return this;
|
|
3717
|
+
}
|
|
3718
|
+
/**
|
|
3719
|
+
* Clears the title of this attachment.
|
|
3720
|
+
*/
|
|
3721
|
+
clearTitle() {
|
|
3722
|
+
this.data.title = void 0;
|
|
3723
|
+
return this;
|
|
3724
|
+
}
|
|
3725
|
+
/**
|
|
3726
|
+
* Sets the waveform of this attachment.
|
|
3727
|
+
*
|
|
3728
|
+
* @param waveform - The waveform of the attachment
|
|
3729
|
+
*/
|
|
3730
|
+
setWaveform(waveform) {
|
|
3731
|
+
this.data.waveform = waveform;
|
|
3732
|
+
return this;
|
|
3733
|
+
}
|
|
3734
|
+
/**
|
|
3735
|
+
* Clears the waveform of this attachment.
|
|
3736
|
+
*/
|
|
3737
|
+
clearWaveform() {
|
|
3738
|
+
this.data.waveform = void 0;
|
|
3739
|
+
return this;
|
|
3740
|
+
}
|
|
3741
|
+
/**
|
|
3742
|
+
* Serializes this builder to API-compatible JSON data.
|
|
3743
|
+
*
|
|
3744
|
+
* Note that by disabling validation, there is no guarantee that the resulting object will be valid.
|
|
3745
|
+
*
|
|
3746
|
+
* @param validationOverride - Force validation to run/not run regardless of your global preference
|
|
3747
|
+
*/
|
|
3748
|
+
toJSON(validationOverride) {
|
|
3749
|
+
const clone = structuredClone(this.data);
|
|
3750
|
+
validate(attachmentPredicate, clone, validationOverride);
|
|
3751
|
+
return clone;
|
|
3752
|
+
}
|
|
3753
|
+
};
|
|
3754
|
+
|
|
3755
|
+
// src/messages/MessageReference.ts
|
|
3756
|
+
var MessageReferenceBuilder = class {
|
|
3757
|
+
static {
|
|
3758
|
+
__name(this, "MessageReferenceBuilder");
|
|
3759
|
+
}
|
|
3760
|
+
data;
|
|
3761
|
+
/**
|
|
3762
|
+
* Creates new allowed mention builder from API data.
|
|
3763
|
+
*
|
|
3764
|
+
* @param data - The API data to create this attachment with
|
|
3765
|
+
*/
|
|
3766
|
+
constructor(data = {}) {
|
|
3767
|
+
this.data = structuredClone(data);
|
|
3768
|
+
}
|
|
3769
|
+
/**
|
|
3770
|
+
* Sets the types of message reference this represents
|
|
3771
|
+
*
|
|
3772
|
+
* @param type - The type of message reference
|
|
3773
|
+
*/
|
|
3774
|
+
setType(type) {
|
|
3775
|
+
this.data.type = type;
|
|
3776
|
+
return this;
|
|
3777
|
+
}
|
|
3778
|
+
/**
|
|
3779
|
+
* Clear the type of message reference this represents
|
|
3780
|
+
*/
|
|
3781
|
+
clearType() {
|
|
3782
|
+
this.data.type = void 0;
|
|
3783
|
+
return this;
|
|
3784
|
+
}
|
|
3785
|
+
/**
|
|
3786
|
+
* Sets the id of the message being referenced
|
|
3787
|
+
*
|
|
3788
|
+
* @param messageId - The id of the message being referenced
|
|
3789
|
+
*/
|
|
3790
|
+
setMessageId(messageId) {
|
|
3791
|
+
this.data.message_id = messageId;
|
|
3792
|
+
return this;
|
|
3793
|
+
}
|
|
3794
|
+
/**
|
|
3795
|
+
* Sets the id of the channel being referenced
|
|
3796
|
+
*
|
|
3797
|
+
* @param channelId - The id of the channel being referenced
|
|
3798
|
+
*/
|
|
3799
|
+
setChannelId(channelId) {
|
|
3800
|
+
this.data.channel_id = channelId;
|
|
3801
|
+
return this;
|
|
3802
|
+
}
|
|
3803
|
+
/**
|
|
3804
|
+
* Clear the id of the channel being referenced
|
|
3805
|
+
*/
|
|
3806
|
+
clearChannelId() {
|
|
3807
|
+
this.data.channel_id = void 0;
|
|
3808
|
+
return this;
|
|
3809
|
+
}
|
|
3810
|
+
/**
|
|
3811
|
+
* Sets the id of the guild being referenced
|
|
3812
|
+
*
|
|
3813
|
+
* @param guildId - The id of the guild being referenced
|
|
3814
|
+
*/
|
|
3815
|
+
setGuildId(guildId) {
|
|
3816
|
+
this.data.guild_id = guildId;
|
|
3817
|
+
return this;
|
|
3818
|
+
}
|
|
3819
|
+
/**
|
|
3820
|
+
* Clear the id of the guild being referenced
|
|
3821
|
+
*/
|
|
3822
|
+
clearGuildId() {
|
|
3823
|
+
this.data.guild_id = void 0;
|
|
3824
|
+
return this;
|
|
3825
|
+
}
|
|
3826
|
+
/**
|
|
3827
|
+
* Serializes this builder to API-compatible JSON data.
|
|
3828
|
+
*
|
|
3829
|
+
* Note that by disabling validation, there is no guarantee that the resulting object will be valid.
|
|
3830
|
+
*
|
|
3831
|
+
* @param validationOverride - Force validation to run/not run regardless of your global preference
|
|
3832
|
+
*/
|
|
3833
|
+
toJSON(validationOverride) {
|
|
3834
|
+
const clone = structuredClone(this.data);
|
|
3835
|
+
validate(messageReferencePredicate, clone, validationOverride);
|
|
3836
|
+
return clone;
|
|
3837
|
+
}
|
|
3838
|
+
};
|
|
3839
|
+
|
|
3840
|
+
// src/messages/Message.ts
|
|
3841
|
+
var MessageBuilder = class {
|
|
3842
|
+
static {
|
|
3843
|
+
__name(this, "MessageBuilder");
|
|
3844
|
+
}
|
|
3845
|
+
/**
|
|
3846
|
+
* The API data associated with this message.
|
|
3847
|
+
*/
|
|
3848
|
+
data;
|
|
3849
|
+
/**
|
|
3850
|
+
* Gets the attachments of this message.
|
|
3851
|
+
*/
|
|
3852
|
+
get attachments() {
|
|
3853
|
+
return this.data.attachments;
|
|
3854
|
+
}
|
|
3855
|
+
/**
|
|
3856
|
+
* Gets the components of this message.
|
|
3857
|
+
*/
|
|
3858
|
+
get components() {
|
|
3859
|
+
return this.data.components;
|
|
3860
|
+
}
|
|
3861
|
+
/**
|
|
3862
|
+
* Gets the embeds of this message.
|
|
3863
|
+
*/
|
|
3864
|
+
get embeds() {
|
|
3865
|
+
return this.data.embeds;
|
|
3866
|
+
}
|
|
3867
|
+
/**
|
|
3868
|
+
* Creates new attachment builder from API data.
|
|
3869
|
+
*
|
|
3870
|
+
* @param data - The API data to create this attachment with
|
|
3871
|
+
*/
|
|
3872
|
+
constructor(data = {}) {
|
|
3873
|
+
this.data = {
|
|
3874
|
+
...structuredClone(data),
|
|
3875
|
+
allowed_mentions: data.allowed_mentions ? new AllowedMentionsBuilder(data.allowed_mentions) : void 0,
|
|
3876
|
+
attachments: data.attachments?.map((attachment) => new AttachmentBuilder(attachment)) ?? [],
|
|
3877
|
+
embeds: data.embeds?.map((embed) => new EmbedBuilder(embed)) ?? [],
|
|
3878
|
+
poll: data.poll ? new PollBuilder(data.poll) : void 0,
|
|
3879
|
+
components: data.components?.map((component) => new ActionRowBuilder(component)) ?? [],
|
|
3880
|
+
message_reference: data.message_reference ? new MessageReferenceBuilder(data.message_reference) : void 0
|
|
3881
|
+
};
|
|
3882
|
+
}
|
|
3883
|
+
/**
|
|
3884
|
+
* Sets the content of the message.
|
|
3885
|
+
*
|
|
3886
|
+
* @param content - The content to set
|
|
3887
|
+
*/
|
|
3888
|
+
setContent(content) {
|
|
3889
|
+
this.data.content = content;
|
|
3890
|
+
return this;
|
|
3891
|
+
}
|
|
3892
|
+
/**
|
|
3893
|
+
* Clears the content of the message.
|
|
3894
|
+
*/
|
|
3895
|
+
clearContent() {
|
|
3896
|
+
this.data.content = void 0;
|
|
3897
|
+
return this;
|
|
3898
|
+
}
|
|
3899
|
+
/**
|
|
3900
|
+
* Sets the nonce of the message.
|
|
3901
|
+
*
|
|
3902
|
+
* @param nonce - The nonce to set
|
|
3903
|
+
*/
|
|
3904
|
+
setNonce(nonce) {
|
|
3905
|
+
this.data.nonce = nonce;
|
|
3906
|
+
return this;
|
|
3907
|
+
}
|
|
3908
|
+
/**
|
|
3909
|
+
* Clears the nonce of the message.
|
|
3910
|
+
*/
|
|
3911
|
+
clearNonce() {
|
|
3912
|
+
this.data.nonce = void 0;
|
|
3913
|
+
return this;
|
|
3914
|
+
}
|
|
3915
|
+
/**
|
|
3916
|
+
* Sets whether the message is TTS.
|
|
3917
|
+
*/
|
|
3918
|
+
setTTS(tts = true) {
|
|
3919
|
+
this.data.tts = tts;
|
|
3920
|
+
return this;
|
|
3921
|
+
}
|
|
3922
|
+
/**
|
|
3923
|
+
* Appends embeds to this message.
|
|
3924
|
+
*
|
|
3925
|
+
* @remarks
|
|
3926
|
+
* The maximum amount of embeds that can be added is 10.
|
|
3927
|
+
* @example
|
|
3928
|
+
* Using an array:
|
|
3929
|
+
* ```ts
|
|
3930
|
+
* const embeds: APIEmbed[] = ...;
|
|
3931
|
+
* const message = new MessageBuilder()
|
|
3932
|
+
* .addEmbeds(embeds);
|
|
3933
|
+
* ```
|
|
3934
|
+
* @example
|
|
3935
|
+
* Using rest parameters (variadic):
|
|
3936
|
+
* ```ts
|
|
3937
|
+
* const message = new MessageBuilder()
|
|
3938
|
+
* .addEmbeds(
|
|
3939
|
+
* { title: 'Embed 1' },
|
|
3940
|
+
* { title: 'Embed 2' },
|
|
3941
|
+
* );
|
|
3942
|
+
* ```
|
|
3943
|
+
* @param embeds - The embeds to add
|
|
3944
|
+
*/
|
|
3945
|
+
addEmbeds(...embeds) {
|
|
3946
|
+
this.data.embeds ??= [];
|
|
3947
|
+
const resolved = normalizeArray(embeds).map((embed) => resolveBuilder(embed, EmbedBuilder));
|
|
3948
|
+
this.data.embeds.push(...resolved);
|
|
3949
|
+
return this;
|
|
3950
|
+
}
|
|
3951
|
+
/**
|
|
3952
|
+
* Removes, replaces, or inserts embeds for this message.
|
|
3953
|
+
*
|
|
3954
|
+
* @remarks
|
|
3955
|
+
* This method behaves similarly
|
|
3956
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
3957
|
+
*
|
|
3958
|
+
* It's useful for modifying and adjusting order of the already-existing embeds of a message.
|
|
3959
|
+
* @example
|
|
3960
|
+
* Remove the first embed:
|
|
3961
|
+
* ```ts
|
|
3962
|
+
* message.spliceEmbeds(0, 1);
|
|
3963
|
+
* ```
|
|
3964
|
+
* @example
|
|
3965
|
+
* Remove the first n embeds:
|
|
3966
|
+
* ```ts
|
|
3967
|
+
* const n = 4;
|
|
3968
|
+
* message.spliceEmbeds(0, n);
|
|
3969
|
+
* ```
|
|
3970
|
+
* @example
|
|
3971
|
+
* Remove the last embed:
|
|
3972
|
+
* ```ts
|
|
3973
|
+
* message.spliceEmbeds(-1, 1);
|
|
3974
|
+
* ```
|
|
3975
|
+
* @param start - The index to start at
|
|
3976
|
+
* @param deleteCount - The amount of embeds to remove
|
|
3977
|
+
* @param embeds - The embeds to insert
|
|
3978
|
+
*/
|
|
3979
|
+
spliceEmbeds(start, deleteCount, ...embeds) {
|
|
3980
|
+
this.data.embeds ??= [];
|
|
3981
|
+
const resolved = normalizeArray(embeds).map((embed) => resolveBuilder(embed, EmbedBuilder));
|
|
3982
|
+
this.data.embeds.splice(start, deleteCount, ...resolved);
|
|
3983
|
+
return this;
|
|
3984
|
+
}
|
|
3985
|
+
/**
|
|
3986
|
+
* Sets the allowed mentions for this message.
|
|
3987
|
+
*
|
|
3988
|
+
* @param allowedMentions - The allowed mentions to set
|
|
3989
|
+
*/
|
|
3990
|
+
setAllowedMentions(allowedMentions) {
|
|
3991
|
+
this.data.allowed_mentions = resolveBuilder(allowedMentions, AllowedMentionsBuilder);
|
|
3992
|
+
return this;
|
|
3993
|
+
}
|
|
3994
|
+
/**
|
|
3995
|
+
* Updates the allowed mentions for this message (and creates it if it doesn't exist)
|
|
3996
|
+
*
|
|
3997
|
+
* @param updater - The function to update the allowed mentions with
|
|
3998
|
+
*/
|
|
3999
|
+
updateAllowedMentions(updater) {
|
|
4000
|
+
this.data.allowed_mentions = updater(this.data.allowed_mentions ?? new AllowedMentionsBuilder());
|
|
4001
|
+
return this;
|
|
4002
|
+
}
|
|
4003
|
+
/**
|
|
4004
|
+
* Clears the allowed mentions for this message.
|
|
4005
|
+
*/
|
|
4006
|
+
clearAllowedMentions() {
|
|
4007
|
+
this.data.allowed_mentions = void 0;
|
|
4008
|
+
return this;
|
|
4009
|
+
}
|
|
4010
|
+
/**
|
|
4011
|
+
* Sets the message reference for this message.
|
|
4012
|
+
*
|
|
4013
|
+
* @param reference - The reference to set
|
|
4014
|
+
*/
|
|
4015
|
+
setMessageReference(reference) {
|
|
4016
|
+
this.data.message_reference = resolveBuilder(reference, MessageReferenceBuilder);
|
|
4017
|
+
return this;
|
|
4018
|
+
}
|
|
4019
|
+
/**
|
|
4020
|
+
* Updates the message reference for this message (and creates it if it doesn't exist)
|
|
4021
|
+
*
|
|
4022
|
+
* @param updater - The function to update the message reference with
|
|
4023
|
+
*/
|
|
4024
|
+
updateMessageReference(updater) {
|
|
4025
|
+
this.data.message_reference = updater(this.data.message_reference ?? new MessageReferenceBuilder());
|
|
4026
|
+
return this;
|
|
4027
|
+
}
|
|
4028
|
+
/**
|
|
4029
|
+
* Clears the message reference for this message.
|
|
4030
|
+
*/
|
|
4031
|
+
clearMessageReference() {
|
|
4032
|
+
this.data.message_reference = void 0;
|
|
4033
|
+
return this;
|
|
4034
|
+
}
|
|
4035
|
+
/**
|
|
4036
|
+
* Adds components to this message.
|
|
4037
|
+
*
|
|
4038
|
+
* @param components - The components to add
|
|
4039
|
+
*/
|
|
4040
|
+
addComponents(...components) {
|
|
4041
|
+
this.data.components ??= [];
|
|
4042
|
+
const resolved = normalizeArray(components).map((component) => resolveBuilder(component, ActionRowBuilder));
|
|
4043
|
+
this.data.components.push(...resolved);
|
|
4044
|
+
return this;
|
|
4045
|
+
}
|
|
4046
|
+
/**
|
|
4047
|
+
* Removes, replaces, or inserts components for this message.
|
|
4048
|
+
*
|
|
4049
|
+
* @remarks
|
|
4050
|
+
* This method behaves similarly
|
|
4051
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
4052
|
+
*
|
|
4053
|
+
* It's useful for modifying and adjusting order of the already-existing components of a message.
|
|
4054
|
+
* @example
|
|
4055
|
+
* Remove the first component:
|
|
4056
|
+
* ```ts
|
|
4057
|
+
* message.spliceComponents(0, 1);
|
|
4058
|
+
* ```
|
|
4059
|
+
* @example
|
|
4060
|
+
* Remove the first n components:
|
|
4061
|
+
* ```ts
|
|
4062
|
+
* const n = 4;
|
|
4063
|
+
* message.spliceComponents(0, n);
|
|
4064
|
+
* ```
|
|
4065
|
+
* @example
|
|
4066
|
+
* Remove the last component:
|
|
4067
|
+
* ```ts
|
|
4068
|
+
* message.spliceComponents(-1, 1);
|
|
4069
|
+
* ```
|
|
4070
|
+
* @param start - The index to start at
|
|
4071
|
+
* @param deleteCount - The amount of components to remove
|
|
4072
|
+
* @param components - The components to insert
|
|
4073
|
+
*/
|
|
4074
|
+
spliceComponents(start, deleteCount, ...components) {
|
|
4075
|
+
this.data.components ??= [];
|
|
4076
|
+
const resolved = normalizeArray(components).map((component) => resolveBuilder(component, ActionRowBuilder));
|
|
4077
|
+
this.data.components.splice(start, deleteCount, ...resolved);
|
|
4078
|
+
return this;
|
|
4079
|
+
}
|
|
4080
|
+
/**
|
|
4081
|
+
* Sets the components of this message.
|
|
4082
|
+
*
|
|
4083
|
+
* @param components - The components to set
|
|
4084
|
+
*/
|
|
4085
|
+
setComponents(...components) {
|
|
4086
|
+
this.data.components = normalizeArray(components).map((component) => resolveBuilder(component, ActionRowBuilder));
|
|
4087
|
+
return this;
|
|
4088
|
+
}
|
|
4089
|
+
/**
|
|
4090
|
+
* Sets the sticker ids of this message.
|
|
4091
|
+
*
|
|
4092
|
+
* @param stickerIds - The ids of the stickers to set
|
|
4093
|
+
*/
|
|
4094
|
+
setStickerIds(...stickerIds) {
|
|
4095
|
+
this.data.sticker_ids = normalizeArray(stickerIds);
|
|
4096
|
+
return this;
|
|
4097
|
+
}
|
|
4098
|
+
/**
|
|
4099
|
+
* Adds sticker ids to this message.
|
|
4100
|
+
*
|
|
4101
|
+
* @param stickerIds - The ids of the stickers to add
|
|
4102
|
+
*/
|
|
4103
|
+
addStickerIds(...stickerIds) {
|
|
4104
|
+
this.data.sticker_ids ??= [];
|
|
4105
|
+
this.data.sticker_ids.push(...normalizeArray(stickerIds));
|
|
4106
|
+
return this;
|
|
4107
|
+
}
|
|
4108
|
+
/**
|
|
4109
|
+
* Removes, replaces, or inserts sticker ids for this message.
|
|
4110
|
+
*
|
|
4111
|
+
* @remarks
|
|
4112
|
+
* This method behaves similarly
|
|
4113
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
4114
|
+
*
|
|
4115
|
+
* It's useful for modifying and adjusting order of the already-existing sticker ids of a message.
|
|
4116
|
+
* @example
|
|
4117
|
+
* Remove the first sticker id:
|
|
4118
|
+
* ```ts
|
|
4119
|
+
* message.spliceStickerIds(0, 1);
|
|
4120
|
+
* ```
|
|
4121
|
+
* @example
|
|
4122
|
+
* Remove the first n sticker ids:
|
|
4123
|
+
* ```ts
|
|
4124
|
+
* const n = 4;
|
|
4125
|
+
* message.spliceStickerIds(0, n);
|
|
4126
|
+
* ```
|
|
4127
|
+
* @example
|
|
4128
|
+
* Remove the last sticker id:
|
|
4129
|
+
* ```ts
|
|
4130
|
+
* message.spliceStickerIds(-1, 1);
|
|
4131
|
+
* ```
|
|
4132
|
+
* @param index - The index to start at
|
|
4133
|
+
* @param deleteCount - The amount of sticker ids to remove
|
|
4134
|
+
* @param stickerIds - The sticker ids to insert
|
|
4135
|
+
*/
|
|
4136
|
+
spliceStickerIds(index, deleteCount, ...stickerIds) {
|
|
4137
|
+
this.data.sticker_ids ??= [];
|
|
4138
|
+
this.data.sticker_ids.splice(index, deleteCount, ...normalizeArray(stickerIds));
|
|
4139
|
+
return this;
|
|
4140
|
+
}
|
|
4141
|
+
/**
|
|
4142
|
+
* Sets attachments for this message.
|
|
4143
|
+
*
|
|
4144
|
+
* @param attachments - The attachments to set
|
|
4145
|
+
*/
|
|
4146
|
+
setAttachments(...attachments) {
|
|
4147
|
+
const resolved = normalizeArray(attachments).map((attachment) => resolveBuilder(attachment, AttachmentBuilder));
|
|
4148
|
+
this.data.attachments = resolved;
|
|
4149
|
+
return this;
|
|
4150
|
+
}
|
|
4151
|
+
/**
|
|
4152
|
+
* Adds attachments to this message.
|
|
4153
|
+
*
|
|
4154
|
+
* @param attachments - The attachments to add
|
|
4155
|
+
*/
|
|
4156
|
+
addAttachments(...attachments) {
|
|
4157
|
+
const resolved = normalizeArray(attachments).map((attachment) => resolveBuilder(attachment, AttachmentBuilder));
|
|
4158
|
+
this.data.attachments.push(...resolved);
|
|
4159
|
+
return this;
|
|
4160
|
+
}
|
|
4161
|
+
/**
|
|
4162
|
+
* Removes, replaces, or inserts attachments for this message.
|
|
4163
|
+
*
|
|
4164
|
+
* @remarks
|
|
4165
|
+
* This method behaves similarly
|
|
4166
|
+
* to {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
|
|
4167
|
+
*
|
|
4168
|
+
* It's useful for modifying and adjusting order of the already-existing attachments of a message.
|
|
4169
|
+
* @example
|
|
4170
|
+
* Remove the first attachment:
|
|
4171
|
+
* ```ts
|
|
4172
|
+
* message.spliceAttachments(0, 1);
|
|
4173
|
+
* ```
|
|
4174
|
+
* @example
|
|
4175
|
+
* Remove the first n attachments:
|
|
4176
|
+
* ```ts
|
|
4177
|
+
* const n = 4;
|
|
4178
|
+
* message.spliceAttachments(0, n);
|
|
4179
|
+
* ```
|
|
4180
|
+
* @example
|
|
4181
|
+
* Remove the last attachment:
|
|
4182
|
+
* ```ts
|
|
4183
|
+
* message.spliceAttachments(-1, 1);
|
|
4184
|
+
* ```
|
|
4185
|
+
* @param start - The index to start at
|
|
4186
|
+
* @param deleteCount - The amount of attachments to remove
|
|
4187
|
+
* @param attachments - The attachments to insert
|
|
4188
|
+
*/
|
|
4189
|
+
spliceAttachments(start, deleteCount, ...attachments) {
|
|
4190
|
+
const resolved = normalizeArray(attachments).map((attachment) => resolveBuilder(attachment, AttachmentBuilder));
|
|
4191
|
+
this.data.attachments.splice(start, deleteCount, ...resolved);
|
|
4192
|
+
return this;
|
|
4193
|
+
}
|
|
4194
|
+
/**
|
|
4195
|
+
* Sets the flags for this message.
|
|
4196
|
+
*/
|
|
4197
|
+
setFlags(flags) {
|
|
4198
|
+
this.data.flags = flags;
|
|
4199
|
+
return this;
|
|
4200
|
+
}
|
|
4201
|
+
/**
|
|
4202
|
+
* Clears the flags for this message.
|
|
4203
|
+
*/
|
|
4204
|
+
clearFlags() {
|
|
4205
|
+
this.data.flags = void 0;
|
|
4206
|
+
return this;
|
|
4207
|
+
}
|
|
4208
|
+
/**
|
|
4209
|
+
* Sets `enforce_nonce` for this message.
|
|
4210
|
+
*/
|
|
4211
|
+
setEnforceNonce(enforceNonce = true) {
|
|
4212
|
+
this.data.enforce_nonce = enforceNonce;
|
|
4213
|
+
return this;
|
|
4214
|
+
}
|
|
4215
|
+
/**
|
|
4216
|
+
* Sets the poll for this message.
|
|
4217
|
+
*
|
|
4218
|
+
* @param poll - The poll to set
|
|
4219
|
+
*/
|
|
4220
|
+
setPoll(poll) {
|
|
4221
|
+
this.data.poll = resolveBuilder(poll, PollBuilder);
|
|
4222
|
+
return this;
|
|
4223
|
+
}
|
|
4224
|
+
/**
|
|
4225
|
+
* Updates the poll for this message (and creates it if it doesn't exist)
|
|
4226
|
+
*
|
|
4227
|
+
* @param updater - The function to update the poll with
|
|
4228
|
+
*/
|
|
4229
|
+
updatePoll(updater) {
|
|
4230
|
+
this.data.poll = updater(this.data.poll ?? new PollBuilder());
|
|
4231
|
+
return this;
|
|
4232
|
+
}
|
|
4233
|
+
/**
|
|
4234
|
+
* Clears the poll for this message.
|
|
4235
|
+
*/
|
|
4236
|
+
clearPoll() {
|
|
4237
|
+
this.data.poll = void 0;
|
|
4238
|
+
return this;
|
|
4239
|
+
}
|
|
4240
|
+
/**
|
|
4241
|
+
* Serializes this builder to API-compatible JSON data.
|
|
4242
|
+
*
|
|
4243
|
+
* Note that by disabling validation, there is no guarantee that the resulting object will be valid.
|
|
4244
|
+
*
|
|
4245
|
+
* @param validationOverride - Force validation to run/not run regardless of your global preference
|
|
4246
|
+
*/
|
|
4247
|
+
toJSON(validationOverride) {
|
|
4248
|
+
const { poll, allowed_mentions, attachments, embeds, components, message_reference, ...rest } = this.data;
|
|
4249
|
+
const data = {
|
|
4250
|
+
...structuredClone(rest),
|
|
4251
|
+
// Wherever we pass false, it's covered by the messagePredicate already
|
|
4252
|
+
poll: this.data.poll?.toJSON(false),
|
|
4253
|
+
allowed_mentions: allowed_mentions?.toJSON(false),
|
|
4254
|
+
attachments: attachments.map((attachment) => attachment.toJSON(false)),
|
|
4255
|
+
embeds: this.data.embeds.map((embed) => embed.toJSON(false)),
|
|
4256
|
+
// Here, the messagePredicate does specific constraints rather than using the componentPredicate
|
|
4257
|
+
components: this.data.components?.map((component) => component.toJSON(validationOverride)),
|
|
4258
|
+
message_reference: message_reference?.toJSON(false)
|
|
4259
|
+
};
|
|
4260
|
+
validate(messagePredicate, data, validationOverride);
|
|
4261
|
+
return data;
|
|
4262
|
+
}
|
|
4263
|
+
};
|
|
4264
|
+
|
|
3421
4265
|
// src/index.ts
|
|
3422
|
-
var version = "2.0.0-dev.
|
|
4266
|
+
var version = "2.0.0-dev.1741953893-09beb8a6a";
|
|
3423
4267
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3424
4268
|
0 && (module.exports = {
|
|
3425
4269
|
ActionRowBuilder,
|
|
4270
|
+
AllowedMentionsBuilder,
|
|
3426
4271
|
ApplicationCommandNumericOptionMinMaxValueMixin,
|
|
3427
4272
|
ApplicationCommandOptionAllowedChannelTypes,
|
|
3428
4273
|
ApplicationCommandOptionBase,
|
|
3429
4274
|
ApplicationCommandOptionChannelTypesMixin,
|
|
3430
4275
|
ApplicationCommandOptionWithAutocompleteMixin,
|
|
3431
4276
|
ApplicationCommandOptionWithChoicesMixin,
|
|
4277
|
+
AttachmentBuilder,
|
|
3432
4278
|
BaseButtonBuilder,
|
|
3433
4279
|
BaseSelectMenuBuilder,
|
|
3434
4280
|
ChannelSelectMenuBuilder,
|
|
@@ -3456,7 +4302,9 @@ var version = "2.0.0-dev.1741219959-e273afbb9";
|
|
|
3456
4302
|
EmojiOrLabelButtonMixin,
|
|
3457
4303
|
LinkButtonBuilder,
|
|
3458
4304
|
MentionableSelectMenuBuilder,
|
|
4305
|
+
MessageBuilder,
|
|
3459
4306
|
MessageContextCommandBuilder,
|
|
4307
|
+
MessageReferenceBuilder,
|
|
3460
4308
|
ModalBuilder,
|
|
3461
4309
|
PollAnswerBuilder,
|
|
3462
4310
|
PollAnswerMediaBuilder,
|
|
@@ -3478,6 +4326,8 @@ var version = "2.0.0-dev.1741219959-e273afbb9";
|
|
|
3478
4326
|
UserContextCommandBuilder,
|
|
3479
4327
|
UserSelectMenuBuilder,
|
|
3480
4328
|
actionRowPredicate,
|
|
4329
|
+
allowedMentionPredicate,
|
|
4330
|
+
attachmentPredicate,
|
|
3481
4331
|
basicOptionPredicate,
|
|
3482
4332
|
buttonPredicate,
|
|
3483
4333
|
channelOptionPredicate,
|
|
@@ -3499,6 +4349,8 @@ var version = "2.0.0-dev.1741219959-e273afbb9";
|
|
|
3499
4349
|
localeMapPredicate,
|
|
3500
4350
|
memberPermissionsPredicate,
|
|
3501
4351
|
messageCommandPredicate,
|
|
4352
|
+
messagePredicate,
|
|
4353
|
+
messageReferencePredicate,
|
|
3502
4354
|
modalPredicate,
|
|
3503
4355
|
normalizeArray,
|
|
3504
4356
|
numberOptionPredicate,
|