@discordjs/builders 2.0.0-dev.1745453588-abc5d99ce → 2.0.0-dev.1745626390-8f375275c

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.js CHANGED
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  ChatInputCommandUserOption: () => ChatInputCommandUserOption,
48
48
  CommandBuilder: () => CommandBuilder,
49
49
  ComponentBuilder: () => ComponentBuilder,
50
+ ContainerBuilder: () => ContainerBuilder,
50
51
  ContextMenuCommandBuilder: () => ContextMenuCommandBuilder,
51
52
  CustomIdButtonBuilder: () => CustomIdButtonBuilder,
52
53
  DangerButtonBuilder: () => DangerButtonBuilder,
@@ -4315,18 +4316,23 @@ var import_v1041 = require("discord-api-types/v10");
4315
4316
  var import_zod10 = require("zod");
4316
4317
  var attachmentPredicate = import_zod10.z.object({
4317
4318
  id: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]),
4318
- description: import_zod10.z.string().optional(),
4319
- duration_secs: import_zod10.z.number().optional(),
4320
- filename: import_zod10.z.string().optional(),
4321
- title: import_zod10.z.string().optional(),
4322
- waveform: import_zod10.z.string().optional()
4319
+ description: import_zod10.z.string().max(1024).optional(),
4320
+ duration_secs: import_zod10.z.number().max(2 ** 31 - 1).optional(),
4321
+ filename: import_zod10.z.string().max(1024).optional(),
4322
+ title: import_zod10.z.string().max(1024).optional(),
4323
+ waveform: import_zod10.z.string().max(400).optional()
4323
4324
  });
4324
4325
  var allowedMentionPredicate = import_zod10.z.object({
4325
4326
  parse: import_zod10.z.nativeEnum(import_v1041.AllowedMentionsTypes).array().optional(),
4326
- roles: import_zod10.z.string().array().optional(),
4327
- users: import_zod10.z.string().array().optional(),
4327
+ roles: import_zod10.z.string().array().max(100).optional(),
4328
+ users: import_zod10.z.string().array().max(100).optional(),
4328
4329
  replied_user: import_zod10.z.boolean().optional()
4329
- });
4330
+ }).refine(
4331
+ (data) => !(data.parse?.includes(import_v1041.AllowedMentionsTypes.User) && data.users?.length || data.parse?.includes(import_v1041.AllowedMentionsTypes.Role) && data.roles?.length),
4332
+ {
4333
+ message: 'Cannot specify both parse: ["users"] and non-empty users array, or parse: ["roles"] and non-empty roles array. These are mutually exclusive'
4334
+ }
4335
+ );
4330
4336
  var messageReferencePredicate = import_zod10.z.object({
4331
4337
  channel_id: import_zod10.z.string().optional(),
4332
4338
  fail_if_not_exists: import_zod10.z.boolean().optional(),
@@ -4356,9 +4362,9 @@ var basicActionRowPredicate = import_zod10.z.object({
4356
4362
  }).array()
4357
4363
  });
4358
4364
  var messageNoComponentsV2Predicate = baseMessagePredicate.extend({
4359
- content: import_zod10.z.string().optional(),
4365
+ content: import_zod10.z.string().max(2e3).optional(),
4360
4366
  embeds: embedPredicate.array().max(10).optional(),
4361
- sticker_ids: import_zod10.z.array(import_zod10.z.string()).min(0).max(3).optional(),
4367
+ sticker_ids: import_zod10.z.array(import_zod10.z.string()).max(3).optional(),
4362
4368
  poll: pollPredicate.optional(),
4363
4369
  components: basicActionRowPredicate.array().max(5).optional(),
4364
4370
  flags: import_zod10.z.number().optional().refine((flags) => {
@@ -4404,9 +4410,9 @@ var AllowedMentionsBuilder = class {
4404
4410
  }
4405
4411
  data;
4406
4412
  /**
4407
- * Creates new allowed mention builder from API data.
4413
+ * Creates a new allowed mentions builder from API data.
4408
4414
  *
4409
- * @param data - The API data to create this attachment with
4415
+ * @param data - The API data to create this allowed mentions builder with
4410
4416
  */
4411
4417
  constructor(data = {}) {
4412
4418
  this.data = structuredClone(data);
@@ -4420,6 +4426,13 @@ var AllowedMentionsBuilder = class {
4420
4426
  this.data.parse = normalizeArray(parse);
4421
4427
  return this;
4422
4428
  }
4429
+ /**
4430
+ * Clears the parse mention types.
4431
+ */
4432
+ clearParse() {
4433
+ this.data.parse = void 0;
4434
+ return this;
4435
+ }
4423
4436
  /**
4424
4437
  * Sets the roles to mention.
4425
4438
  *
@@ -4453,7 +4466,7 @@ var AllowedMentionsBuilder = class {
4453
4466
  * allowedMentions.spliceRoles(0, 1);
4454
4467
  * ```
4455
4468
  * @example
4456
- * Remove the first n role:
4469
+ * Remove the first n roles:
4457
4470
  * ```ts
4458
4471
  * const n = 4;
4459
4472
  * allowedMentions.spliceRoles(0, n);
@@ -4472,6 +4485,13 @@ var AllowedMentionsBuilder = class {
4472
4485
  this.data.roles.splice(index, deleteCount, ...normalizeArray(roles));
4473
4486
  return this;
4474
4487
  }
4488
+ /**
4489
+ * Clears the roles to mention.
4490
+ */
4491
+ clearRoles() {
4492
+ this.data.roles = void 0;
4493
+ return this;
4494
+ }
4475
4495
  /**
4476
4496
  * Sets the users to mention.
4477
4497
  *
@@ -4505,7 +4525,7 @@ var AllowedMentionsBuilder = class {
4505
4525
  * allowedMentions.spliceUsers(0, 1);
4506
4526
  * ```
4507
4527
  * @example
4508
- * Remove the first n user:
4528
+ * Remove the first n users:
4509
4529
  * ```ts
4510
4530
  * const n = 4;
4511
4531
  * allowedMentions.spliceUsers(0, n);
@@ -4525,7 +4545,16 @@ var AllowedMentionsBuilder = class {
4525
4545
  return this;
4526
4546
  }
4527
4547
  /**
4528
- * For replies, sets whether to mention the author of the message being replied to
4548
+ * Clears the users to mention.
4549
+ */
4550
+ clearUsers() {
4551
+ this.data.users = void 0;
4552
+ return this;
4553
+ }
4554
+ /**
4555
+ * For replies, sets whether to mention the author of the message being replied to.
4556
+ *
4557
+ * @param repliedUser - Whether to mention the author of the message being replied to
4529
4558
  */
4530
4559
  setRepliedUser(repliedUser = true) {
4531
4560
  this.data.replied_user = repliedUser;
@@ -4552,29 +4581,26 @@ var AttachmentBuilder = class {
4552
4581
  }
4553
4582
  data;
4554
4583
  /**
4555
- * Creates new attachment builder from API data.
4584
+ * Creates a new attachment builder from API data.
4556
4585
  *
4557
- * @param data - The API data to create this attachment with
4586
+ * @param data - The API data to create this attachment builder with
4558
4587
  */
4559
4588
  constructor(data = {}) {
4560
4589
  this.data = structuredClone(data);
4561
4590
  }
4562
4591
  /**
4592
+ * Sets the id of the attachment.
4593
+ *
4563
4594
  * @param id - The id of the attachment
4564
4595
  */
4565
4596
  setId(id) {
4566
4597
  this.data.id = id;
4567
4598
  return this;
4568
4599
  }
4569
- /**
4570
- * Clears the id of this attachment.
4571
- */
4572
- clearId() {
4573
- this.data.id = void 0;
4574
- return this;
4575
- }
4576
4600
  /**
4577
4601
  * Sets the description of this attachment.
4602
+ *
4603
+ * @param description - The description of the attachment
4578
4604
  */
4579
4605
  setDescription(description) {
4580
4606
  this.data.description = description;
@@ -4636,7 +4662,7 @@ var AttachmentBuilder = class {
4636
4662
  return this;
4637
4663
  }
4638
4664
  /**
4639
- * Sets the waveform of this attachment.
4665
+ * Sets the waveform of this attachment (audio clips).
4640
4666
  *
4641
4667
  * @param waveform - The waveform of the attachment
4642
4668
  */
@@ -4672,15 +4698,15 @@ var MessageReferenceBuilder = class {
4672
4698
  }
4673
4699
  data;
4674
4700
  /**
4675
- * Creates new allowed mention builder from API data.
4701
+ * Creates a new message reference builder from API data.
4676
4702
  *
4677
- * @param data - The API data to create this attachment with
4703
+ * @param data - The API data to create this message reference builder with
4678
4704
  */
4679
4705
  constructor(data = {}) {
4680
4706
  this.data = structuredClone(data);
4681
4707
  }
4682
4708
  /**
4683
- * Sets the types of message reference this represents
4709
+ * Sets the type of message reference this represents
4684
4710
  *
4685
4711
  * @param type - The type of message reference
4686
4712
  */
@@ -4736,6 +4762,15 @@ var MessageReferenceBuilder = class {
4736
4762
  this.data.guild_id = void 0;
4737
4763
  return this;
4738
4764
  }
4765
+ /**
4766
+ * Sets whether to fail the message creation if the referenced message does not exist
4767
+ *
4768
+ * @param failIfNotExists - Whether to fail the message creation if the referenced message does not exist
4769
+ */
4770
+ setFailIfNotExists(failIfNotExists = true) {
4771
+ this.data.fail_if_not_exists = failIfNotExists;
4772
+ return this;
4773
+ }
4739
4774
  /**
4740
4775
  * Serializes this builder to API-compatible JSON data.
4741
4776
  *
@@ -4778,19 +4813,27 @@ var MessageBuilder = class {
4778
4813
  return this.data.embeds;
4779
4814
  }
4780
4815
  /**
4781
- * Creates new attachment builder from API data.
4816
+ * Creates a new message builder from API data.
4782
4817
  *
4783
- * @param data - The API data to create this attachment with
4818
+ * @param data - The API data to create this message builder with
4784
4819
  */
4785
- constructor(data = {}) {
4820
+ constructor({
4821
+ attachments = [],
4822
+ embeds = [],
4823
+ components = [],
4824
+ message_reference,
4825
+ poll,
4826
+ allowed_mentions,
4827
+ ...data
4828
+ } = {}) {
4786
4829
  this.data = {
4787
4830
  ...structuredClone(data),
4788
- allowed_mentions: data.allowed_mentions ? new AllowedMentionsBuilder(data.allowed_mentions) : void 0,
4789
- attachments: data.attachments?.map((attachment) => new AttachmentBuilder(attachment)) ?? [],
4790
- embeds: data.embeds?.map((embed) => new EmbedBuilder(embed)) ?? [],
4791
- poll: data.poll ? new PollBuilder(data.poll) : void 0,
4792
- components: data.components?.map((component) => createComponentBuilder(component)) ?? [],
4793
- message_reference: data.message_reference ? new MessageReferenceBuilder(data.message_reference) : void 0
4831
+ allowed_mentions: allowed_mentions && new AllowedMentionsBuilder(allowed_mentions),
4832
+ attachments: attachments.map((attachment) => new AttachmentBuilder(attachment)),
4833
+ embeds: embeds.map((embed) => new EmbedBuilder(embed)),
4834
+ poll: poll && new PollBuilder(poll),
4835
+ components: components.map((component) => createComponentBuilder(component)),
4836
+ message_reference: message_reference && new MessageReferenceBuilder(message_reference)
4794
4837
  };
4795
4838
  }
4796
4839
  /**
@@ -4827,6 +4870,8 @@ var MessageBuilder = class {
4827
4870
  }
4828
4871
  /**
4829
4872
  * Sets whether the message is TTS.
4873
+ *
4874
+ * @param tts - Whether the message is TTS
4830
4875
  */
4831
4876
  setTTS(tts = true) {
4832
4877
  this.data.tts = tts;
@@ -4895,6 +4940,14 @@ var MessageBuilder = class {
4895
4940
  this.data.embeds.splice(start, deleteCount, ...resolved);
4896
4941
  return this;
4897
4942
  }
4943
+ /**
4944
+ * Sets the embeds for this message.
4945
+ *
4946
+ * @param embeds - The embeds to set
4947
+ */
4948
+ setEmbeds(...embeds) {
4949
+ return this.spliceEmbeds(0, this.embeds.length, ...normalizeArray(embeds));
4950
+ }
4898
4951
  /**
4899
4952
  * Sets the allowed mentions for this message.
4900
4953
  *
@@ -4910,7 +4963,7 @@ var MessageBuilder = class {
4910
4963
  * @param updater - The function to update the allowed mentions with
4911
4964
  */
4912
4965
  updateAllowedMentions(updater) {
4913
- this.data.allowed_mentions = updater(this.data.allowed_mentions ?? new AllowedMentionsBuilder());
4966
+ updater(this.data.allowed_mentions ??= new AllowedMentionsBuilder());
4914
4967
  return this;
4915
4968
  }
4916
4969
  /**
@@ -4935,7 +4988,7 @@ var MessageBuilder = class {
4935
4988
  * @param updater - The function to update the message reference with
4936
4989
  */
4937
4990
  updateMessageReference(updater) {
4938
- this.data.message_reference = updater(this.data.message_reference ?? new MessageReferenceBuilder());
4991
+ updater(this.data.message_reference ??= new MessageReferenceBuilder());
4939
4992
  return this;
4940
4993
  }
4941
4994
  /**
@@ -5064,8 +5117,7 @@ var MessageBuilder = class {
5064
5117
  * @param stickerIds - The ids of the stickers to set
5065
5118
  */
5066
5119
  setStickerIds(...stickerIds) {
5067
- this.data.sticker_ids = normalizeArray(stickerIds);
5068
- return this;
5120
+ return this.spliceStickerIds(0, this.data.sticker_ids?.length ?? 0, ...normalizeArray(stickerIds));
5069
5121
  }
5070
5122
  /**
5071
5123
  * Adds sticker ids to this message.
@@ -5116,9 +5168,7 @@ var MessageBuilder = class {
5116
5168
  * @param attachments - The attachments to set
5117
5169
  */
5118
5170
  setAttachments(...attachments) {
5119
- const resolved = normalizeArray(attachments).map((attachment) => resolveBuilder(attachment, AttachmentBuilder));
5120
- this.data.attachments = resolved;
5121
- return this;
5171
+ return this.spliceAttachments(0, this.data.attachments.length, ...normalizeArray(attachments));
5122
5172
  }
5123
5173
  /**
5124
5174
  * Adds attachments to this message.
@@ -5165,6 +5215,8 @@ var MessageBuilder = class {
5165
5215
  }
5166
5216
  /**
5167
5217
  * Sets the flags for this message.
5218
+ *
5219
+ * @param flags - The flags to set
5168
5220
  */
5169
5221
  setFlags(flags) {
5170
5222
  this.data.flags = flags;
@@ -5178,7 +5230,9 @@ var MessageBuilder = class {
5178
5230
  return this;
5179
5231
  }
5180
5232
  /**
5181
- * Sets `enforce_nonce` for this message.
5233
+ * Sets whether to enforce recent uniqueness of the nonce of this message.
5234
+ *
5235
+ * @param enforceNonce - Whether to enforce recent uniqueness of the nonce of this message
5182
5236
  */
5183
5237
  setEnforceNonce(enforceNonce = true) {
5184
5238
  this.data.enforce_nonce = enforceNonce;
@@ -5199,7 +5253,7 @@ var MessageBuilder = class {
5199
5253
  * @param updater - The function to update the poll with
5200
5254
  */
5201
5255
  updatePoll(updater) {
5202
- this.data.poll = updater(this.data.poll ?? new PollBuilder());
5256
+ updater(this.data.poll ??= new PollBuilder());
5203
5257
  return this;
5204
5258
  }
5205
5259
  /**
@@ -5221,12 +5275,12 @@ var MessageBuilder = class {
5221
5275
  const data = {
5222
5276
  ...structuredClone(rest),
5223
5277
  // Wherever we pass false, it's covered by the messagePredicate already
5224
- poll: this.data.poll?.toJSON(false),
5278
+ poll: poll?.toJSON(false),
5225
5279
  allowed_mentions: allowed_mentions?.toJSON(false),
5226
5280
  attachments: attachments.map((attachment) => attachment.toJSON(false)),
5227
- embeds: this.data.embeds.map((embed) => embed.toJSON(false)),
5281
+ embeds: embeds.map((embed) => embed.toJSON(false)),
5228
5282
  // Here, the messagePredicate does specific constraints rather than using the componentPredicate
5229
- components: this.data.components?.map((component) => component.toJSON(validationOverride)),
5283
+ components: components.map((component) => component.toJSON(validationOverride)),
5230
5284
  message_reference: message_reference?.toJSON(false)
5231
5285
  };
5232
5286
  validate(messagePredicate, data, validationOverride);
@@ -5235,7 +5289,7 @@ var MessageBuilder = class {
5235
5289
  };
5236
5290
 
5237
5291
  // src/index.ts
5238
- var version = "2.0.0-dev.1745453588-abc5d99ce";
5292
+ var version = "2.0.0-dev.1745626390-8f375275c";
5239
5293
  // Annotate the CommonJS export names for ESM import in node:
5240
5294
  0 && (module.exports = {
5241
5295
  ActionRowBuilder,
@@ -5264,6 +5318,7 @@ var version = "2.0.0-dev.1745453588-abc5d99ce";
5264
5318
  ChatInputCommandUserOption,
5265
5319
  CommandBuilder,
5266
5320
  ComponentBuilder,
5321
+ ContainerBuilder,
5267
5322
  ContextMenuCommandBuilder,
5268
5323
  CustomIdButtonBuilder,
5269
5324
  DangerButtonBuilder,