@fluxerjs/core 2.2.0 → 3.0.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/dist/index.mjs CHANGED
@@ -1,5 +1,10 @@
1
1
  // src/index.ts
2
- import { AttachmentBuilder, EmbedBuilder as EmbedBuilder4, MessagePayload as MessagePayload2 } from "@fluxerjs/builders";
2
+ import {
3
+ AttachmentBuilder as AttachmentBuilder2,
4
+ AttachmentMeta,
5
+ EmbedBuilder as EmbedBuilder4,
6
+ MessagePayload as MessagePayload2
7
+ } from "@fluxerjs/builders";
3
8
  import {
4
9
  AuditLogActionType,
5
10
  ChannelType as ChannelType5,
@@ -9,7 +14,7 @@ import {
9
14
  GuildNSFWLevel as GuildNSFWLevel2,
10
15
  GuildOperations,
11
16
  InviteType as InviteType3,
12
- MessageAttachmentFlags,
17
+ MessageAttachmentFlags as MessageAttachmentFlags2,
13
18
  MessageFlags,
14
19
  MessageReferenceType as MessageReferenceType2,
15
20
  MessageType as MessageType2,
@@ -22,14 +27,14 @@ import {
22
27
  } from "@fluxerjs/types";
23
28
  import {
24
29
  createLogger as createLogger2,
25
- MessageFlagsBitField,
30
+ MessageFlagsBitField as MessageFlagsBitField2,
26
31
  MessageFlagsBits,
27
- PermissionFlags as PermissionFlags4,
28
- PermissionsBitField as PermissionsBitField3,
32
+ PermissionFlags as PermissionFlags5,
33
+ PermissionsBitField as PermissionsBitField4,
29
34
  parsePrefixCommand,
30
35
  parseUserMention,
31
36
  resolveKlipyToImageUrl,
32
- resolvePermissionsToBitfield as resolvePermissionsToBitfield2,
37
+ resolvePermissionsToBitfield as resolvePermissionsToBitfield4,
33
38
  serializeError,
34
39
  UserFlagsBitField,
35
40
  UserFlagsBits
@@ -74,6 +79,9 @@ var CacheController = class {
74
79
  stickers
75
80
  };
76
81
  }
82
+ /**
83
+ * Sweep cached messages. Filter receives a hydrated {@link Message} (`createdAt`).
84
+ */
77
85
  sweepMessages(filter, channelId) {
78
86
  return this.client.sweepMessages(filter, channelId);
79
87
  }
@@ -142,7 +150,7 @@ var CacheController = class {
142
150
  * @internal
143
151
  */
144
152
  cascadeChannel(channel, from = "both") {
145
- const guildId = "guildId" in channel && typeof channel.guildId === "string" ? channel.guildId : void 0;
153
+ const guildId = typeof channel.isGuild === "function" && channel.isGuild() ? channel.guildId : void 0;
146
154
  const dropFromGuild = () => {
147
155
  if (!guildId) return;
148
156
  const guildChannels = this.client.guilds.get(guildId)?.channels;
@@ -173,23 +181,24 @@ var CacheController = class {
173
181
 
174
182
  // src/ClientCore/ChannelManager.ts
175
183
  import { LimitedCollection } from "@fluxerjs/collection";
176
- import { Routes as Routes18 } from "@fluxerjs/types";
184
+ import { Routes as Routes19 } from "@fluxerjs/types";
177
185
 
178
186
  // src/Domain/Channel/Base.ts
179
187
  import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
180
- import { SnowflakeUtil } from "@fluxerjs/util";
188
+ import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
181
189
 
182
190
  // src/ClientCore/MessageManager.ts
183
- import { Collection as Collection3 } from "@fluxerjs/collection";
191
+ import { Collection as Collection4 } from "@fluxerjs/collection";
184
192
  import { Routes as Routes5 } from "@fluxerjs/types";
185
193
 
186
194
  // src/Domain/Message/Message.ts
187
195
  import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
188
- import { Collection as Collection2 } from "@fluxerjs/collection";
196
+ import { Collection as Collection3 } from "@fluxerjs/collection";
189
197
  import {
190
198
  MessageType,
191
199
  Routes as Routes4
192
200
  } from "@fluxerjs/types";
201
+ import { MessageFlagsBitField } from "@fluxerjs/util";
193
202
 
194
203
  // src/ClientCore/SdkOptions/Attachments.ts
195
204
  function toMessageAttachmentEditWire(attachments) {
@@ -256,21 +265,66 @@ function toAttachmentUploadPlanResponse(data) {
256
265
  }
257
266
 
258
267
  // src/ClientCore/SdkOptions/Channels.ts
268
+ import { resolvePermissionsToBitfield } from "@fluxerjs/util";
269
+ function toOverwriteWire(overwrite) {
270
+ return {
271
+ id: overwrite.id,
272
+ type: overwrite.type,
273
+ allow: overwrite.allow !== void 0 ? resolvePermissionsToBitfield(overwrite.allow) : "0",
274
+ deny: overwrite.deny !== void 0 ? resolvePermissionsToBitfield(overwrite.deny) : "0"
275
+ };
276
+ }
259
277
  function toChannelEditBody(options) {
260
278
  const body = {};
261
279
  if (options.name !== void 0) body.name = options.name;
262
280
  if (options.topic !== void 0) body.topic = options.topic;
281
+ if (options.url !== void 0) body.url = options.url;
263
282
  if (options.parentId !== void 0) body.parent_id = options.parentId;
264
283
  if (options.bitrate !== void 0) body.bitrate = options.bitrate;
265
284
  if (options.userLimit !== void 0) body.user_limit = options.userLimit;
285
+ if (options.voiceConnectionLimit !== void 0) {
286
+ body.voice_connection_limit = options.voiceConnectionLimit;
287
+ }
266
288
  if (options.nsfw !== void 0) body.nsfw = options.nsfw;
289
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
290
+ if (options.contentWarningLevel !== void 0) {
291
+ body.content_warning_level = options.contentWarningLevel;
292
+ }
293
+ if (options.contentWarningText !== void 0) {
294
+ body.content_warning_text = options.contentWarningText;
295
+ }
267
296
  if (options.rateLimitPerUser !== void 0) {
268
297
  body.rate_limit_per_user = options.rateLimitPerUser;
269
298
  }
270
299
  if (options.rtcRegion !== void 0) body.rtc_region = options.rtcRegion;
300
+ if (options.icon !== void 0) body.icon = options.icon;
301
+ if (options.permissionOverwrites !== void 0) {
302
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
303
+ }
304
+ return body;
305
+ }
306
+ function toChannelCreateBody(options) {
307
+ const body = { name: options.name, type: options.type };
308
+ if (options.topic !== void 0) body.topic = options.topic;
309
+ if (options.url !== void 0) body.url = options.url;
310
+ if (options.parentId !== void 0) body.parent_id = options.parentId;
311
+ if (options.bitrate !== void 0) body.bitrate = options.bitrate;
312
+ if (options.userLimit !== void 0) body.user_limit = options.userLimit;
313
+ if (options.voiceConnectionLimit !== void 0) {
314
+ body.voice_connection_limit = options.voiceConnectionLimit;
315
+ }
271
316
  if (options.permissionOverwrites !== void 0) {
272
- body.permission_overwrites = options.permissionOverwrites;
317
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
318
+ }
319
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
320
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
321
+ if (options.contentWarningLevel !== void 0) {
322
+ body.content_warning_level = options.contentWarningLevel;
273
323
  }
324
+ if (options.contentWarningText !== void 0) {
325
+ body.content_warning_text = options.contentWarningText;
326
+ }
327
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
274
328
  return body;
275
329
  }
276
330
  function toChannelInviteBody(options) {
@@ -281,6 +335,13 @@ function toChannelInviteBody(options) {
281
335
  if (options.temporary !== void 0) body.temporary = options.temporary;
282
336
  return body;
283
337
  }
338
+ function toGroupDmEditBody(options) {
339
+ const body = { type: 3 };
340
+ if (options.name !== void 0) body.name = options.name;
341
+ if (options.icon !== void 0) body.icon = options.icon;
342
+ if (options.nicks !== void 0) body.nicks = options.nicks;
343
+ return body;
344
+ }
284
345
 
285
346
  // src/ClientCore/SdkOptions/Discovery.ts
286
347
  function toDiscoveryBody(options) {
@@ -316,32 +377,8 @@ function toDiscoveryStatusPayload(data) {
316
377
  };
317
378
  }
318
379
 
319
- // src/ClientCore/SdkOptions/Expressions.ts
320
- function toEmojiCreateBody(options) {
321
- return { name: options.name, image: options.image };
322
- }
323
- function toEmojiEditBody(options) {
324
- return { name: options.name };
325
- }
326
- function toStickerCreateBody(options) {
327
- const body = {
328
- name: options.name,
329
- image: options.file
330
- };
331
- if (options.description !== void 0) body.description = options.description;
332
- if (options.tags !== void 0) body.tags = options.tags;
333
- return body;
334
- }
335
- function toStickerEditBody(options) {
336
- const body = {};
337
- if (options.name !== void 0) body.name = options.name;
338
- if (options.description !== void 0) body.description = options.description;
339
- if (options.tags !== void 0) body.tags = options.tags;
340
- return body;
341
- }
342
-
343
380
  // src/ClientCore/SdkOptions/Guild.ts
344
- import { resolvePermissionsToBitfield } from "@fluxerjs/util";
381
+ import { resolvePermissionsToBitfield as resolvePermissionsToBitfield2 } from "@fluxerjs/util";
345
382
  function toGuildEditBody(options) {
346
383
  const body = {};
347
384
  if (options.name !== void 0) body.name = options.name;
@@ -369,6 +406,16 @@ function toGuildEditBody(options) {
369
406
  body.splash_card_alignment = options.splashCardAlignment;
370
407
  }
371
408
  if (options.nsfwLevel !== void 0) body.nsfw_level = options.nsfwLevel;
409
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
410
+ if (options.contentWarningLevel !== void 0) {
411
+ body.content_warning_level = options.contentWarningLevel;
412
+ }
413
+ if (options.contentWarningText !== void 0) {
414
+ body.content_warning_text = options.contentWarningText;
415
+ }
416
+ if (options.messageHistoryCutoff !== void 0) {
417
+ body.message_history_cutoff = options.messageHistoryCutoff;
418
+ }
372
419
  if (options.features !== void 0) body.features = options.features;
373
420
  return body;
374
421
  }
@@ -378,6 +425,9 @@ function toGuildBanBody(options) {
378
425
  if (options.deleteMessageDays !== void 0) {
379
426
  body.delete_message_days = options.deleteMessageDays;
380
427
  }
428
+ if (options.deleteMessageSeconds !== void 0) {
429
+ body.delete_message_seconds = options.deleteMessageSeconds;
430
+ }
381
431
  if (options.banDurationSeconds !== void 0) {
382
432
  body.ban_duration_seconds = options.banDurationSeconds;
383
433
  }
@@ -392,18 +442,26 @@ function toChannelPositionBody(updates) {
392
442
  return row;
393
443
  });
394
444
  }
395
- function toRoleRequestBody(options) {
445
+ function toRolePermissionsBody(options) {
396
446
  const body = {};
447
+ if (options.permissions !== void 0) {
448
+ body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield2(options.permissions);
449
+ }
450
+ return body;
451
+ }
452
+ function toRoleCreateBody(options) {
453
+ const body = { ...toRolePermissionsBody(options) };
454
+ if (options.name !== void 0) body.name = options.name;
455
+ if (options.color !== void 0) body.color = options.color;
456
+ return body;
457
+ }
458
+ function toRoleEditBody(options) {
459
+ const body = { ...toRolePermissionsBody(options) };
397
460
  if (options.name !== void 0) body.name = options.name;
398
461
  if (options.color !== void 0) body.color = options.color;
399
462
  if (options.hoist !== void 0) body.hoist = options.hoist;
400
463
  if (options.mentionable !== void 0) body.mentionable = options.mentionable;
401
- if (options.unicodeEmoji !== void 0) body.unicode_emoji = options.unicodeEmoji;
402
- if (options.position !== void 0) body.position = options.position;
403
464
  if (options.hoistPosition !== void 0) body.hoist_position = options.hoistPosition;
404
- if (options.permissions !== void 0) {
405
- body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield(options.permissions);
406
- }
407
465
  return body;
408
466
  }
409
467
 
@@ -421,6 +479,8 @@ function toMemberSearchBody(options) {
421
479
  if (options.userCreatedAtLte !== void 0) body.user_created_at_lte = options.userCreatedAtLte;
422
480
  if (options.sortBy !== void 0) body.sort_by = options.sortBy;
423
481
  if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
482
+ if (options.joinSourceType !== void 0) body.join_source_type = options.joinSourceType;
483
+ if (options.sourceInviteCode !== void 0) body.source_invite_code = options.sourceInviteCode;
424
484
  return body;
425
485
  }
426
486
  function toMemberEditBody(options) {
@@ -433,6 +493,7 @@ function toMemberEditBody(options) {
433
493
  if (options.pronouns !== void 0) body.pronouns = options.pronouns;
434
494
  if (options.accentColor !== void 0) body.accent_color = options.accentColor;
435
495
  if (options.profileFlags !== void 0) body.profile_flags = options.profileFlags;
496
+ if (options.mentionFlags !== void 0) body.mention_flags = options.mentionFlags;
436
497
  if (options.mute !== void 0) body.mute = options.mute;
437
498
  if (options.deaf !== void 0) body.deaf = options.deaf;
438
499
  if (options.communicationDisabledUntil !== void 0) {
@@ -454,15 +515,54 @@ function toBulkFetchWire(requests) {
454
515
  ...r.around !== void 0 ? { around: r.around } : {}
455
516
  }));
456
517
  }
457
-
458
- // src/ClientCore/SdkOptions/Packs.ts
459
- function toPackInviteBody(options) {
460
- const body = {};
461
- if (options.maxUses !== void 0) body.max_uses = options.maxUses;
462
- if (options.maxAge !== void 0) body.max_age = options.maxAge;
463
- if (options.unique !== void 0) body.unique = options.unique;
518
+ function toMessageSearchBody(options = {}) {
519
+ const body = { scope: "current" };
520
+ if (options.content !== void 0) body.content = options.content;
521
+ if (options.contents !== void 0) body.contents = options.contents;
522
+ if (options.exactPhrases !== void 0) body.exact_phrases = options.exactPhrases;
523
+ if (options.channelIds !== void 0) {
524
+ body.channel_id = options.channelIds;
525
+ body.channel_ids = options.channelIds;
526
+ }
527
+ if (options.excludeChannelIds !== void 0) body.exclude_channel_id = options.excludeChannelIds;
528
+ if (options.contextGuildId !== void 0) body.context_guild_id = options.contextGuildId;
529
+ if (options.contextChannelId !== void 0) body.context_channel_id = options.contextChannelId;
530
+ if (options.hitsPerPage !== void 0) body.hits_per_page = options.hitsPerPage;
531
+ if (options.page !== void 0) body.page = options.page;
532
+ if (options.cursor !== void 0) body.cursor = options.cursor;
533
+ if (options.minId !== void 0) body.min_id = options.minId;
534
+ if (options.maxId !== void 0) body.max_id = options.maxId;
535
+ if (options.authorIds !== void 0) body.author_id = options.authorIds;
536
+ if (options.excludeAuthorIds !== void 0) body.exclude_author_id = options.excludeAuthorIds;
537
+ if (options.authorType !== void 0) body.author_type = options.authorType;
538
+ if (options.excludeAuthorType !== void 0) body.exclude_author_type = options.excludeAuthorType;
539
+ if (options.mentions !== void 0) body.mentions = options.mentions;
540
+ if (options.excludeMentions !== void 0) body.exclude_mentions = options.excludeMentions;
541
+ if (options.mentionEveryone !== void 0) body.mention_everyone = options.mentionEveryone;
542
+ if (options.pinned !== void 0) body.pinned = options.pinned;
543
+ if (options.includeNsfw !== void 0) body.include_nsfw = options.includeNsfw;
544
+ if (options.has !== void 0) body.has = options.has;
545
+ if (options.excludeHas !== void 0) body.exclude_has = options.excludeHas;
546
+ if (options.sortBy !== void 0) body.sort_by = options.sortBy;
547
+ if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
464
548
  return body;
465
549
  }
550
+ function isMessageSearchIndexing(data) {
551
+ return "indexing" in data && data.indexing === true;
552
+ }
553
+ function toMessageSearchResponse(data) {
554
+ if (isMessageSearchIndexing(data)) {
555
+ return { indexing: true };
556
+ }
557
+ return {
558
+ messages: data.messages,
559
+ channels: data.channels,
560
+ total: data.total,
561
+ hitsPerPage: data.hits_per_page,
562
+ page: data.page,
563
+ ...data.cursor !== void 0 ? { cursor: data.cursor } : {}
564
+ };
565
+ }
466
566
 
467
567
  // src/ClientCore/SdkOptions/Presence.ts
468
568
  function toPresenceWire(options) {
@@ -512,8 +612,8 @@ function toSudoBody(options) {
512
612
  }
513
613
 
514
614
  // src/Helpers/MessageUtils/Body.ts
515
- import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
516
- import { MessageReferenceType } from "@fluxerjs/types";
615
+ import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
616
+ import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
517
617
 
518
618
  // src/LibErrors/ErrorCodes.ts
519
619
  import { ErrorCodes } from "@fluxerjs/util";
@@ -582,6 +682,37 @@ function applyReplyPingSuppression(body) {
582
682
  function assignIfDefined(target, key, value) {
583
683
  if (value !== void 0) target[key] = value;
584
684
  }
685
+ function normalizeSendFiles(files) {
686
+ if (!files?.length) return void 0;
687
+ const normalized = [];
688
+ const metaFromBuilders = [];
689
+ let anyBuilderMeta = false;
690
+ for (let i = 0; i < files.length; i++) {
691
+ const file = files[i];
692
+ if (!file) continue;
693
+ if (file instanceof AttachmentBuilder) {
694
+ normalized.push(file.toFileData());
695
+ const meta = {
696
+ id: i,
697
+ filename: file.filename,
698
+ ...file.description != null ? { description: file.description } : {},
699
+ ...file.spoiler ? { flags: MessageAttachmentFlags.IS_SPOILER } : {}
700
+ };
701
+ if (file.description != null || file.spoiler) anyBuilderMeta = true;
702
+ metaFromBuilders.push(meta);
703
+ } else {
704
+ normalized.push(file);
705
+ metaFromBuilders.push({
706
+ id: i,
707
+ filename: file.filename ?? file.name
708
+ });
709
+ }
710
+ }
711
+ return {
712
+ files: normalized,
713
+ metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
714
+ };
715
+ }
585
716
  function buildSendBody(options) {
586
717
  const body = typeof options === "string" ? { content: options } : options;
587
718
  const result = {};
@@ -589,16 +720,17 @@ function buildSendBody(options) {
589
720
  if (body.embeds?.length) {
590
721
  result.embeds = body.embeds.map((e) => e instanceof EmbedBuilder ? e.toJSON() : e);
591
722
  }
723
+ const normalizedFiles = normalizeSendFiles(body.files);
592
724
  if (body.uploadedAttachments?.length) {
593
725
  result.attachments = body.uploadedAttachments;
594
- } else if (body.files?.length) {
726
+ } else if (normalizedFiles?.files.length) {
595
727
  result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
596
728
  id: a.id,
597
729
  filename: a.filename,
598
730
  ...a.title != null && { title: a.title },
599
731
  ...a.description != null && { description: a.description },
600
732
  ...a.flags != null && { flags: a.flags }
601
- })) : body.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
733
+ })) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
602
734
  }
603
735
  if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
604
736
  if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
@@ -692,9 +824,10 @@ async function prepareMessagePostPayload(options, defaults) {
692
824
  } else if (allowedMentions?.repliedUser === false) {
693
825
  applyReplyPingSuppression(body);
694
826
  }
827
+ const resolvedFiles = normalizeSendFiles(files);
695
828
  return {
696
829
  body,
697
- files: !uploadedAttachments?.length && files?.length ? await resolveMessageFiles(files) : void 0
830
+ files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
698
831
  };
699
832
  }
700
833
 
@@ -755,13 +888,17 @@ var Base = class {
755
888
  };
756
889
 
757
890
  // src/Domain/Message/MessageReaction.ts
758
- var MessageReaction = class extends Base {
891
+ var MessageReaction = class _MessageReaction extends Base {
759
892
  client;
760
893
  messageId;
761
894
  channelId;
762
895
  guildId;
763
896
  emoji;
764
- /** Raw gateway payload for low-level access. */
897
+ /** Total count when hydrated from a message payload; `1` for gateway add events. */
898
+ count;
899
+ /** Whether the current user reacted (message payload); false for gateway remove. */
900
+ me;
901
+ /** Raw gateway payload for low-level access (null when built from a message aggregate). */
765
902
  _data;
766
903
  constructor(client, data) {
767
904
  super();
@@ -775,6 +912,26 @@ var MessageReaction = class extends Base {
775
912
  ...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
776
913
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
777
914
  };
915
+ this.count = 1;
916
+ this.me = false;
917
+ }
918
+ /** Build a reaction aggregate from a message's `reactions` array entry. */
919
+ static fromMessage(message, data) {
920
+ const reaction = new _MessageReaction(message.client, {
921
+ user_id: message.client.user?.id ?? "0",
922
+ message_id: message.id,
923
+ channel_id: message.channelId,
924
+ guild_id: message.guildId ?? void 0,
925
+ emoji: {
926
+ name: data.emoji.name,
927
+ id: data.emoji.id ?? void 0,
928
+ animated: data.emoji.animated ?? void 0
929
+ }
930
+ });
931
+ Object.defineProperty(reaction, "_data", { value: null });
932
+ reaction.count = data.count;
933
+ reaction.me = data.me ?? false;
934
+ return reaction;
778
935
  }
779
936
  /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
780
937
  get emojiIdentifier() {
@@ -784,12 +941,23 @@ var MessageReaction = class extends Base {
784
941
  get guild() {
785
942
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
786
943
  }
944
+ /** Cached message this reaction belongs to, or null if the message was not cached. */
945
+ get message() {
946
+ const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
947
+ return cached ? new Message(this.client, cached) : null;
948
+ }
949
+ /** Cached text-capable channel, or null if uncached / not text-based. */
950
+ get channel() {
951
+ const channel = this.client.channels.get(this.channelId);
952
+ return channel?.isTextBased() ? channel : null;
953
+ }
787
954
  /**
788
- * Fetch the message this reaction belongs to.
789
- * Use when you need to edit, delete, or otherwise interact with the message.
955
+ * Fetch the message this reaction belongs to (cache first, then REST).
790
956
  * @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
791
957
  */
792
958
  async fetchMessage() {
959
+ const cached = this.message;
960
+ if (cached) return cached;
793
961
  try {
794
962
  const data = await this.client.rest.get(
795
963
  Routes.channelMessage(this.channelId, this.messageId)
@@ -860,11 +1028,17 @@ var Events = {
860
1028
  WebhooksUpdate: "webhooksUpdate",
861
1029
  Resumed: "resumed",
862
1030
  Error: "error",
863
- Debug: "debug"
1031
+ Debug: "debug",
1032
+ ShardReady: "shardReady",
1033
+ ShardResumed: "shardResumed",
1034
+ ShardDisconnect: "shardDisconnect",
1035
+ ShardReconnecting: "shardReconnecting",
1036
+ ShardError: "shardError",
1037
+ ShardingRequired: "shardingRequired"
864
1038
  };
865
1039
 
866
1040
  // src/Helpers/ReactionCollector.ts
867
- var ReactionCollector = class extends EventEmitter {
1041
+ var ReactionCollector = class _ReactionCollector extends EventEmitter {
868
1042
  client;
869
1043
  messageId;
870
1044
  channelId;
@@ -907,15 +1081,17 @@ var ReactionCollector = class extends EventEmitter {
907
1081
  ...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
908
1082
  }
909
1083
  });
910
- const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
1084
+ const cached = this.client.users.get(entry.userId);
1085
+ const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
1086
+ {
911
1087
  id: entry.userId,
912
1088
  username: "Unknown",
913
1089
  discriminator: "0",
914
- global_name: null,
1090
+ globalName: null,
915
1091
  avatar: null,
916
- avatar_color: null,
917
- flags: 0
918
- });
1092
+ bot: false,
1093
+ system: false
1094
+ };
919
1095
  this._collect(reaction, user, entry.userId);
920
1096
  }
921
1097
  };
@@ -947,6 +1123,21 @@ var ReactionCollector = class extends EventEmitter {
947
1123
  }
948
1124
  this.emit("end", this.collected, reason);
949
1125
  }
1126
+ /**
1127
+ * One-shot helper used by {@link Message.awaitReactions}.
1128
+ * Resolves with the collected reactions when the collector ends.
1129
+ * Rejects if `options.errors` includes the end reason.
1130
+ */
1131
+ static awaitReactions(client, messageId, channelId, options) {
1132
+ const errors = options?.errors ?? [];
1133
+ return new Promise((resolve, reject) => {
1134
+ const collector = new _ReactionCollector(client, messageId, channelId, options);
1135
+ collector.on("end", (collected, reason) => {
1136
+ if (errors.includes(reason)) reject(collected);
1137
+ else resolve(collected);
1138
+ });
1139
+ });
1140
+ }
950
1141
  on(event, listener) {
951
1142
  return super.on(event, listener);
952
1143
  }
@@ -955,70 +1146,227 @@ var ReactionCollector = class extends EventEmitter {
955
1146
  }
956
1147
  };
957
1148
 
958
- // src/Domain/Message/Reactions.ts
959
- import { Routes as Routes2 } from "@fluxerjs/types";
960
- import { parseEmoji } from "@fluxerjs/util";
961
- async function emojiPath(message, emoji) {
962
- return message.client.resolveEmoji(emoji, message.guildId);
1149
+ // src/Domain/Message/Attachment.ts
1150
+ function toMessageAttachment(data) {
1151
+ return {
1152
+ id: data.id,
1153
+ filename: data.filename,
1154
+ title: data.title ?? null,
1155
+ description: data.description ?? null,
1156
+ contentType: data.content_type ?? null,
1157
+ contentHash: data.content_hash ?? null,
1158
+ size: data.size,
1159
+ url: data.url ?? null,
1160
+ proxyUrl: data.proxy_url ?? null,
1161
+ width: data.width ?? null,
1162
+ height: data.height ?? null,
1163
+ placeholder: data.placeholder ?? null,
1164
+ flags: data.flags ?? 0,
1165
+ nsfw: data.nsfw ?? false,
1166
+ duration: data.duration ?? null,
1167
+ waveform: data.waveform ?? null,
1168
+ expiresAt: data.expires_at ? new Date(data.expires_at) : null,
1169
+ expired: data.expired ?? false
1170
+ };
963
1171
  }
964
- function toReactionEmoji(emoji) {
965
- if (typeof emoji !== "string") {
966
- return {
967
- name: emoji.name,
968
- ...emoji.id !== void 0 ? { id: emoji.id } : {},
969
- ...emoji.animated !== void 0 ? { animated: emoji.animated } : {}
970
- };
1172
+
1173
+ // src/Domain/Message/Embed.ts
1174
+ function toMessageEmbedAuthor(data) {
1175
+ return {
1176
+ name: data.name ?? null,
1177
+ url: data.url ?? null,
1178
+ iconUrl: data.icon_url ?? null,
1179
+ proxyIconUrl: data.proxy_icon_url ?? null
1180
+ };
1181
+ }
1182
+ function toMessageEmbedFooter(data) {
1183
+ return {
1184
+ text: data.text,
1185
+ iconUrl: data.icon_url ?? null,
1186
+ proxyIconUrl: data.proxy_icon_url ?? null
1187
+ };
1188
+ }
1189
+ function toMessageEmbedMedia(data) {
1190
+ return {
1191
+ url: data.url,
1192
+ proxyUrl: data.proxy_url ?? null,
1193
+ contentType: data.content_type ?? null,
1194
+ contentHash: data.content_hash ?? null,
1195
+ width: data.width ?? null,
1196
+ height: data.height ?? null,
1197
+ description: data.description ?? null,
1198
+ placeholder: data.placeholder ?? null,
1199
+ duration: data.duration ?? null,
1200
+ flags: data.flags ?? null
1201
+ };
1202
+ }
1203
+ function toMessageEmbed(data) {
1204
+ const full = data;
1205
+ return {
1206
+ type: data.type ?? "rich",
1207
+ url: data.url ?? null,
1208
+ title: data.title ?? null,
1209
+ color: data.color ?? null,
1210
+ timestamp: data.timestamp ? new Date(data.timestamp) : null,
1211
+ description: data.description ?? null,
1212
+ author: data.author ? toMessageEmbedAuthor(data.author) : null,
1213
+ image: data.image ? toMessageEmbedMedia(data.image) : null,
1214
+ thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
1215
+ footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
1216
+ fields: (data.fields ?? []).map((f) => ({
1217
+ name: f.name,
1218
+ value: f.value,
1219
+ inline: f.inline ?? false
1220
+ })),
1221
+ provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
1222
+ video: data.video ? toMessageEmbedMedia(data.video) : null,
1223
+ audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
1224
+ nsfw: data.nsfw ?? false,
1225
+ children: (full.children ?? []).map(toMessageEmbed),
1226
+ html: full.html ?? null,
1227
+ htmlWidth: full.html_width ?? null,
1228
+ htmlHeight: full.html_height ?? null
1229
+ };
1230
+ }
1231
+
1232
+ // src/Domain/Message/MessageReactionManager.ts
1233
+ import { Collection as Collection2 } from "@fluxerjs/collection";
1234
+ var MessageReactionManager = class {
1235
+ constructor(message) {
1236
+ this.message = message;
971
1237
  }
972
- const animatedWire = /^a:(\w+):(\d+)$/.exec(emoji);
973
- if (animatedWire) {
974
- return { name: animatedWire[1], id: animatedWire[2], animated: true };
1238
+ _cache = new Collection2();
1239
+ /** Reactions keyed by unicode name or `name:id`. */
1240
+ get cache() {
1241
+ return this._cache;
975
1242
  }
976
- const parsed = parseEmoji(emoji);
977
- if (parsed?.id) {
978
- return {
979
- name: parsed.name,
980
- id: parsed.id,
981
- ...parsed.animated ? { animated: true } : {}
982
- };
1243
+ get size() {
1244
+ return this._cache.size;
983
1245
  }
984
- let name = emoji;
985
- try {
986
- name = decodeURIComponent(emoji);
987
- } catch {
988
- }
989
- return { name: parsed?.name ?? name };
990
- }
991
- function emitOwnReactionAdd(message, wireOrInput) {
992
- const user = message.client.user;
993
- if (!user) return;
994
- const emojiPayload = toReactionEmoji(wireOrInput);
995
- const reaction = new MessageReaction(message.client, {
996
- user_id: user.id,
997
- channel_id: message.channelId,
998
- message_id: message.id,
999
- guild_id: message.guildId ?? void 0,
1000
- emoji: {
1001
- name: emojiPayload.name,
1002
- ...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
1003
- ...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
1246
+ [Symbol.iterator]() {
1247
+ return this._cache.values();
1248
+ }
1249
+ /** @internal Sync from an API message payload. */
1250
+ _patch(reactions) {
1251
+ this._cache.clear();
1252
+ for (const data of reactions ?? []) {
1253
+ const reaction = MessageReaction.fromMessage(this.message, data);
1254
+ this._cache.set(reaction.emojiIdentifier, reaction);
1004
1255
  }
1005
- });
1006
- const payload = {
1007
- reaction,
1008
- user,
1009
- messageId: message.id,
1010
- channelId: message.channelId,
1011
- emoji: emojiPayload,
1012
- userId: user.id
1013
- };
1014
- message.client.emit(Events.MessageReactionAdd, payload);
1256
+ }
1257
+ };
1258
+
1259
+ // src/Domain/Message/MessageSticker.ts
1260
+ import { SnowflakeUtil } from "@fluxerjs/util";
1261
+
1262
+ // src/Helpers/Constants.ts
1263
+ import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
1264
+ var CDN_URL = "https://fluxerusercontent.com";
1265
+ var STATIC_CDN_URL = "https://fluxerstatic.com";
1266
+
1267
+ // src/Helpers/Cdn.ts
1268
+ function mediaBase(options) {
1269
+ return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1270
+ }
1271
+ function staticBase(options) {
1272
+ return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
1273
+ }
1274
+ function getExtension(hash, options) {
1275
+ const ext = options?.extension ?? "png";
1276
+ if (hash?.startsWith("a_")) return "gif";
1277
+ return ext;
1278
+ }
1279
+ function appendSize(options) {
1280
+ return options?.size ? `?size=${options.size}` : "";
1281
+ }
1282
+ function cdnAvatarURL(userId, avatarHash, options) {
1283
+ if (!avatarHash) return null;
1284
+ const ext = getExtension(avatarHash, options);
1285
+ const size = appendSize(options);
1286
+ return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1287
+ }
1288
+ function cdnDisplayAvatarURL(userId, avatarHash, options) {
1289
+ return cdnAvatarURL(userId, avatarHash, options) ?? cdnDefaultAvatarURL(userId, options);
1290
+ }
1291
+ function cdnBannerURL(resourceId, bannerHash, options) {
1292
+ if (!bannerHash) return null;
1293
+ const ext = getExtension(bannerHash, options);
1294
+ const size = appendSize(options);
1295
+ return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1296
+ }
1297
+ function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1298
+ if (!avatarHash) return null;
1299
+ const ext = getExtension(avatarHash, options);
1300
+ const size = appendSize(options);
1301
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1302
+ }
1303
+ function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1304
+ if (!bannerHash) return null;
1305
+ const ext = getExtension(bannerHash, options);
1306
+ const size = appendSize(options);
1307
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1308
+ }
1309
+ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1310
+ const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
1311
+ return `${staticBase(options)}/avatars/${index}.png`;
1312
+ }
1313
+ function cdnGuildAssetURL(kind, id, hash, options) {
1314
+ if (!hash) return null;
1315
+ const size = options?.size ? `?size=${options.size}` : "";
1316
+ return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1317
+ }
1318
+ function cdnEmojiURL(emojiId, animated, options) {
1319
+ const ext = animated ? "gif" : "png";
1320
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1321
+ }
1322
+ function cdnStickerURL(stickerId, animated, options) {
1323
+ const ext = animated ? "gif" : "png";
1324
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1325
+ }
1326
+
1327
+ // src/Domain/Message/MessageSticker.ts
1328
+ var MessageSticker = class extends Base {
1329
+ client;
1330
+ id;
1331
+ name;
1332
+ description;
1333
+ tags;
1334
+ animated;
1335
+ constructor(client, data) {
1336
+ super();
1337
+ this.client = client;
1338
+ this.id = data.id;
1339
+ this.name = data.name;
1340
+ this.description = data.description ?? "";
1341
+ this.tags = data.tags ?? [];
1342
+ this.animated = data.animated ?? false;
1343
+ }
1344
+ /** CDN URL for this sticker image. */
1345
+ get url() {
1346
+ return cdnStickerURL(this.id, this.animated, {
1347
+ mediaBase: this.client.instance.endpoints.media
1348
+ });
1349
+ }
1350
+ /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
1351
+ get createdTimestamp() {
1352
+ return SnowflakeUtil.timestampFromSnowflake(this.id);
1353
+ }
1354
+ /** Date when this sticker was created, derived from its snowflake ID. */
1355
+ get createdAt() {
1356
+ return SnowflakeUtil.dateFromSnowflake(this.id);
1357
+ }
1358
+ };
1359
+
1360
+ // src/Domain/Message/Reactions.ts
1361
+ import { Routes as Routes2 } from "@fluxerjs/types";
1362
+ async function emojiPath(message, emoji) {
1363
+ return message.client.resolveEmoji(emoji, message.guildId);
1015
1364
  }
1016
1365
  async function reactToMessage(message, emoji) {
1017
1366
  const wire = await emojiPath(message, emoji);
1018
1367
  await message.client.rest.put(
1019
1368
  Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
1020
1369
  );
1021
- emitOwnReactionAdd(message, wire);
1022
1370
  }
1023
1371
  async function removeMessageReaction(message, emoji, userId) {
1024
1372
  const e = await emojiPath(message, emoji);
@@ -1124,7 +1472,33 @@ async function replyToMessage(message, options, replyOptions) {
1124
1472
  }
1125
1473
 
1126
1474
  // src/Domain/Message/Message.ts
1475
+ function toMessageCall(data) {
1476
+ return {
1477
+ participants: data.participants,
1478
+ endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
1479
+ };
1480
+ }
1481
+ function toMessageSnapshot(client, data) {
1482
+ return {
1483
+ content: data.content ?? null,
1484
+ createdAt: new Date(data.timestamp),
1485
+ editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
1486
+ mentionUserIds: data.mentions ?? [],
1487
+ mentionRoles: data.mention_roles ?? [],
1488
+ embeds: (data.embeds ?? []).map(toMessageEmbed),
1489
+ attachments: (data.attachments ?? []).map(toMessageAttachment),
1490
+ stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
1491
+ ...data.type !== void 0 ? { type: data.type } : {}
1492
+ };
1493
+ }
1494
+ function resolveMessageFlags(flags) {
1495
+ if (flags === void 0) return void 0;
1496
+ if (typeof flags === "number") return flags;
1497
+ return Number(MessageFlagsBitField.resolve(flags));
1498
+ }
1127
1499
  var Message = class _Message extends Base {
1500
+ /** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
1501
+ partial = false;
1128
1502
  /** The {@link Client} that instantiated this message. */
1129
1503
  client;
1130
1504
  /** Snowflake ID of this message. */
@@ -1153,7 +1527,7 @@ var Message = class _Message extends Base {
1153
1527
  mentionEveryone;
1154
1528
  /** Whether this is a text-to-speech message. */
1155
1529
  tts;
1156
- /** Embedded content (rich previews, etc.). */
1530
+ /** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
1157
1531
  embeds;
1158
1532
  /** Stickers sent with the message. */
1159
1533
  stickers;
@@ -1175,26 +1549,41 @@ var Message = class _Message extends Base {
1175
1549
  mentionRoles;
1176
1550
  /** Client-side nonce for deduplication. */
1177
1551
  nonce;
1178
- /** Cached text/DM/guild channel, or null if uncached. */
1552
+ /**
1553
+ * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1554
+ * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
1555
+ */
1179
1556
  get channel() {
1180
- return this.client.channels.get(this.channelId) ?? null;
1557
+ const channel = this.client.channels.get(this.channelId) ?? null;
1558
+ return channel?.isTextBased() ? channel : null;
1181
1559
  }
1182
1560
  /** Cached guild, or null for DMs / uncached. */
1183
1561
  get guild() {
1184
1562
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
1185
1563
  }
1186
- /** Fetch and resolve the channel this message is in. */
1564
+ /** Cached guild member for the author, or null in DMs / if uncached. */
1565
+ get member() {
1566
+ return this.guild?.members.get(this.author.id) ?? null;
1567
+ }
1568
+ /**
1569
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1570
+ * has {@link Channel.delete} and {@link Channel.send}.
1571
+ * @example
1572
+ * const channel = await message.resolveChannel();
1573
+ * await channel.delete();
1574
+ */
1187
1575
  async resolveChannel() {
1188
1576
  return this.client.channels.resolve(this.channelId);
1189
1577
  }
1190
- /** Fetch and resolve the guild, or null if a DM. */
1578
+ /**
1579
+ * Fetch and resolve the guild, or null if a DM.
1580
+ * Propagates network/auth errors; only returns null when there is no guildId.
1581
+ * @example
1582
+ * const guild = await message.resolveGuild();
1583
+ */
1191
1584
  async resolveGuild() {
1192
1585
  if (!this.guildId) return null;
1193
- try {
1194
- return await this.client.guilds.resolve(this.guildId);
1195
- } catch {
1196
- return null;
1197
- }
1586
+ return this.client.guilds.resolve(this.guildId);
1198
1587
  }
1199
1588
  /**
1200
1589
  * Construct a message from API data.
@@ -1211,29 +1600,73 @@ var Message = class _Message extends Base {
1211
1600
  this.createdAt = new Date(data.timestamp);
1212
1601
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1213
1602
  this.pinned = data.pinned;
1214
- this.attachments = new Collection2();
1215
- for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
1603
+ this.attachments = new Collection3();
1604
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1216
1605
  this.type = data.type ?? MessageType.Default;
1217
- this.flags = data.flags ?? 0;
1606
+ this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
1218
1607
  this.mentionEveryone = data.mention_everyone ?? false;
1219
1608
  this.tts = data.tts ?? false;
1220
- this.embeds = data.embeds ?? [];
1221
- this.stickers = data.stickers ?? [];
1222
- this.reactions = data.reactions ?? [];
1223
- this.messageReference = data.message_reference ?? null;
1224
- this.messageSnapshots = data.message_snapshots ?? [];
1225
- this.call = data.call ?? null;
1609
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1610
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
1611
+ this.reactions = new MessageReactionManager(this);
1612
+ this.reactions._patch(data.reactions);
1613
+ this.messageReference = data.message_reference ? {
1614
+ channelId: data.message_reference.channel_id,
1615
+ messageId: data.message_reference.message_id,
1616
+ guildId: data.message_reference.guild_id ?? null,
1617
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1618
+ } : null;
1619
+ this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
1620
+ this.call = data.call ? toMessageCall(data.call) : null;
1226
1621
  this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
1227
1622
  this.webhookId = data.webhook_id ?? null;
1228
1623
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1229
1624
  this.mentionRoles = data.mention_roles ?? [];
1230
1625
  this.nonce = data.nonce ?? null;
1231
1626
  }
1232
- /** Send a message in this channel without replying. */
1627
+ /**
1628
+ * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
1629
+ * @internal
1630
+ */
1631
+ _patch(data) {
1632
+ this.content = data.content;
1633
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1634
+ this.pinned = data.pinned;
1635
+ this.attachments.clear();
1636
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1637
+ this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
1638
+ this.mentionEveryone = data.mention_everyone ?? false;
1639
+ this.tts = data.tts ?? false;
1640
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1641
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1642
+ this.reactions._patch(data.reactions);
1643
+ this.messageReference = data.message_reference ? {
1644
+ channelId: data.message_reference.channel_id,
1645
+ messageId: data.message_reference.message_id,
1646
+ guildId: data.message_reference.guild_id ?? null,
1647
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1648
+ } : null;
1649
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
1650
+ (s) => toMessageSnapshot(this.client, s)
1651
+ );
1652
+ this.call = data.call ? toMessageCall(data.call) : null;
1653
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
1654
+ this.webhookId = data.webhook_id ?? null;
1655
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1656
+ this.mentionRoles = data.mention_roles ?? [];
1657
+ this.nonce = data.nonce ?? null;
1658
+ }
1659
+ /**
1660
+ * Send a standalone message in this channel (not a reply).
1661
+ * Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
1662
+ */
1233
1663
  async send(options) {
1234
1664
  return sendMessage(this, options);
1235
1665
  }
1236
- /** Send a message to another channel by ID. */
1666
+ /**
1667
+ * Send a message to another channel by ID.
1668
+ * Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
1669
+ */
1237
1670
  async sendTo(channelId, options) {
1238
1671
  return sendMessageTo(this, channelId, options);
1239
1672
  }
@@ -1247,6 +1680,16 @@ var Message = class _Message extends Base {
1247
1680
  async reply(options, replyOptions) {
1248
1681
  return replyToMessage(this, options, replyOptions);
1249
1682
  }
1683
+ /**
1684
+ * Hydrate a partial message, or return the message as-is.
1685
+ * @example
1686
+ * client.on(Events.MessageUpdate, async (_old, msg) => {
1687
+ * const message = await Message.resolve(msg);
1688
+ * });
1689
+ */
1690
+ static async resolve(message) {
1691
+ return message.partial ? message.fetch() : message;
1692
+ }
1250
1693
  /** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
1251
1694
  static async _createMessageBody(content, referenced_message, ping) {
1252
1695
  return createMessageBody(content, referenced_message, ping);
@@ -1259,7 +1702,7 @@ var Message = class _Message extends Base {
1259
1702
  async edit(options) {
1260
1703
  const body = {};
1261
1704
  if (options.content !== void 0) body.content = options.content;
1262
- if (options.embeds?.length) {
1705
+ if (options.embeds !== void 0) {
1263
1706
  body.embeds = options.embeds.map(
1264
1707
  (e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
1265
1708
  );
@@ -1267,7 +1710,8 @@ var Message = class _Message extends Base {
1267
1710
  if (options.allowedMentions) {
1268
1711
  body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
1269
1712
  }
1270
- if (options.flags !== void 0) body.flags = options.flags;
1713
+ const flags = resolveMessageFlags(options.flags);
1714
+ if (flags !== void 0) body.flags = flags;
1271
1715
  if (options.attachments !== void 0) {
1272
1716
  body.attachments = toMessageAttachmentEditWire(options.attachments);
1273
1717
  }
@@ -1282,6 +1726,13 @@ var Message = class _Message extends Base {
1282
1726
  createReactionCollector(options) {
1283
1727
  return new ReactionCollector(this.client, this.id, this.channelId, options);
1284
1728
  }
1729
+ /**
1730
+ * Wait for reactions matching the filter, then resolve the collected set.
1731
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
1732
+ */
1733
+ awaitReactions(options) {
1734
+ return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
1735
+ }
1285
1736
  /** Fetch the latest version of this message from the API. */
1286
1737
  async fetch() {
1287
1738
  return this.client.channels.fetchMessage(this.channelId, this.id);
@@ -1335,6 +1786,57 @@ var Message = class _Message extends Base {
1335
1786
  }
1336
1787
  };
1337
1788
 
1789
+ // src/Domain/Message/PartialMessage.ts
1790
+ import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
1791
+ var PartialMessage = class {
1792
+ partial = true;
1793
+ client;
1794
+ id;
1795
+ channelId;
1796
+ guildId;
1797
+ content;
1798
+ authorId;
1799
+ author;
1800
+ createdAt;
1801
+ constructor(client, data) {
1802
+ this.client = client;
1803
+ this.id = data.id;
1804
+ this.channelId = data.channelId;
1805
+ this.guildId = data.guildId ?? null;
1806
+ this.content = data.content ?? null;
1807
+ this.authorId = data.authorId ?? null;
1808
+ this.author = data.author ?? null;
1809
+ this.createdAt = data.createdAt ?? (SnowflakeUtil2.isValid(data.id) ? SnowflakeUtil2.dateFromSnowflake(data.id) : null);
1810
+ }
1811
+ /**
1812
+ * Live text-capable channel from cache, or null if uncached / not text-based.
1813
+ * Same contract as {@link Message.channel}.
1814
+ */
1815
+ get channel() {
1816
+ const channel = this.client.channels.get(this.channelId) ?? null;
1817
+ return channel?.isTextBased() ? channel : null;
1818
+ }
1819
+ /**
1820
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1821
+ * has {@link Channel.delete} and {@link Channel.send}.
1822
+ * @example
1823
+ * const channel = await message.resolveChannel();
1824
+ * await channel.delete();
1825
+ */
1826
+ async resolveChannel() {
1827
+ return this.client.channels.resolve(this.channelId);
1828
+ }
1829
+ /**
1830
+ * Fetch the full message from the API.
1831
+ * @example
1832
+ * const message = await partial.fetch();
1833
+ * await message.reply('Pong!');
1834
+ */
1835
+ async fetch() {
1836
+ return this.client.channels.fetchMessage(this.channelId, this.id);
1837
+ }
1838
+ };
1839
+
1338
1840
  // src/ClientCore/MessageManager.ts
1339
1841
  var BULK = {
1340
1842
  requests: { min: 1, max: 25 },
@@ -1369,19 +1871,40 @@ var MessageManager = class {
1369
1871
  this.client = client;
1370
1872
  this.channelId = channelId;
1371
1873
  }
1874
+ /** Structure cache keyed by message id (identity for {@link get}). */
1875
+ _structures = new Collection4();
1372
1876
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
1373
1877
  get(messageId) {
1374
1878
  const data = this.client._getMessageCache(this.channelId)?.get(messageId);
1375
- return data ? new Message(this.client, data) : void 0;
1879
+ if (!data) {
1880
+ this._structures.delete(messageId);
1881
+ return void 0;
1882
+ }
1883
+ const existing = this._structures.get(messageId);
1884
+ if (existing) return existing;
1885
+ const message = new Message(this.client, data);
1886
+ this._structures.set(messageId, message);
1887
+ return message;
1888
+ }
1889
+ /** Retrieve from cache, otherwise {@link fetch}. */
1890
+ async resolve(messageId) {
1891
+ return this.get(messageId) ?? this.fetch(messageId);
1376
1892
  }
1377
1893
  async fetch(idOrOptions) {
1378
1894
  return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
1379
1895
  }
1380
- /** Cache API data and return a {@link Message} built from the cached entry when present. */
1896
+ /** Cache API data and return a {@link Message} (reusing identity when present). */
1381
1897
  wrap(data) {
1382
1898
  this.client._addMessageToCache(this.channelId, data);
1383
1899
  const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
1384
- return new Message(this.client, cached);
1900
+ const existing = this._structures.get(data.id);
1901
+ if (existing) {
1902
+ existing._patch(cached);
1903
+ return existing;
1904
+ }
1905
+ const message = new Message(this.client, cached);
1906
+ this._structures.set(data.id, message);
1907
+ return message;
1385
1908
  }
1386
1909
  /** Fetch a single message from the API. */
1387
1910
  async fetchOne(messageId) {
@@ -1414,12 +1937,110 @@ var MessageManager = class {
1414
1937
  }
1415
1938
  const base = Routes5.channelMessages(this.channelId);
1416
1939
  const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
1417
- const collection = new Collection3();
1940
+ const collection = new Collection4();
1418
1941
  for (const msg of data) collection.set(msg.id, this.wrap(msg));
1419
1942
  return collection;
1420
1943
  }
1421
1944
  };
1422
1945
 
1946
+ // src/Helpers/MessageCollector.ts
1947
+ import { EventEmitter as EventEmitter2 } from "events";
1948
+ import { Collection as Collection5 } from "@fluxerjs/collection";
1949
+ function requireCollectorBounds(options) {
1950
+ const time = options.time ?? 0;
1951
+ const max = options.max ?? 0;
1952
+ if (time <= 0 && max <= 0) {
1953
+ throw new FluxerError("MessageCollector requires `time` and/or `max`", {
1954
+ code: ErrorCodes.CollectorOptionsRequired
1955
+ });
1956
+ }
1957
+ }
1958
+ var MessageCollector = class _MessageCollector extends EventEmitter2 {
1959
+ client;
1960
+ channelId;
1961
+ options;
1962
+ collected = new Collection5();
1963
+ _timeout = null;
1964
+ _ended = false;
1965
+ _listener;
1966
+ constructor(client, channelId, options = {}) {
1967
+ super();
1968
+ requireCollectorBounds(options);
1969
+ this.client = client;
1970
+ this.channelId = channelId;
1971
+ this.options = {
1972
+ filter: options.filter ?? (() => true),
1973
+ time: options.time ?? 0,
1974
+ max: options.max ?? 0
1975
+ };
1976
+ this._listener = (message) => {
1977
+ if (this._ended || message.channelId !== this.channelId) return;
1978
+ if (!this.options.filter(message)) return;
1979
+ this.collected.set(message.id, message);
1980
+ this.emit("collect", message);
1981
+ if (this.options.max > 0 && this.collected.size >= this.options.max) {
1982
+ this.stop("limit");
1983
+ }
1984
+ };
1985
+ this.client.on(Events.MessageCreate, this._listener);
1986
+ if (this.options.time > 0) {
1987
+ this._timeout = setTimeout(() => this.stop("time"), this.options.time);
1988
+ }
1989
+ }
1990
+ stop(reason = "user") {
1991
+ if (this._ended) return;
1992
+ this._ended = true;
1993
+ this.client.off(Events.MessageCreate, this._listener);
1994
+ if (this._timeout) {
1995
+ clearTimeout(this._timeout);
1996
+ this._timeout = null;
1997
+ }
1998
+ this.emit("end", this.collected, reason);
1999
+ }
2000
+ /**
2001
+ * One-shot helper used by {@link Channel.awaitMessages}.
2002
+ * Resolves with the collected messages when the collector ends for `user` (or when
2003
+ * the end reason is not listed in `errors`).
2004
+ * By default, `time` and `limit` reject with {@link FluxerError}
2005
+ * (`CollectorIdle` / `CollectorMax`).
2006
+ */
2007
+ static awaitMessages(client, channelId, options) {
2008
+ const errors = options?.errors ?? ["time", "limit"];
2009
+ return new Promise((resolve, reject) => {
2010
+ const collector = new _MessageCollector(client, channelId, options);
2011
+ collector.on("end", (collected, reason) => {
2012
+ if (!errors.includes(reason)) {
2013
+ resolve(collected);
2014
+ return;
2015
+ }
2016
+ if (reason === "time") {
2017
+ reject(
2018
+ new FluxerError("Message collector timed out", {
2019
+ code: ErrorCodes.CollectorIdle
2020
+ })
2021
+ );
2022
+ return;
2023
+ }
2024
+ if (reason === "limit") {
2025
+ reject(
2026
+ new FluxerError("Message collector reached max", {
2027
+ code: ErrorCodes.CollectorMax
2028
+ })
2029
+ );
2030
+ return;
2031
+ }
2032
+ reject(collected);
2033
+ });
2034
+ });
2035
+ }
2036
+ on(event, listener) {
2037
+ return super.on(event, listener);
2038
+ }
2039
+ emit(event, ...args) {
2040
+ return super.emit(event, ...args);
2041
+ }
2042
+ };
2043
+
1423
2044
  // src/Domain/Channel/Attachments.ts
1424
2045
  import { Routes as Routes6 } from "@fluxerjs/types";
1425
2046
  function asBytes(data) {
@@ -1498,6 +2119,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1498
2119
 
1499
2120
  // src/Domain/Channel/Base.ts
1500
2121
  var Channel = class extends Base {
2122
+ #messages;
1501
2123
  /** The {@link Client} that instantiated this channel. */
1502
2124
  client;
1503
2125
  /** Snowflake ID of this channel. */
@@ -1521,11 +2143,11 @@ var Channel = class extends Base {
1521
2143
  }
1522
2144
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
1523
2145
  get createdTimestamp() {
1524
- return SnowflakeUtil.timestampFromSnowflake(this.id);
2146
+ return SnowflakeUtil3.timestampFromSnowflake(this.id);
1525
2147
  }
1526
2148
  /** Date when this channel was created, derived from its snowflake ID. */
1527
2149
  get createdAt() {
1528
- return SnowflakeUtil.dateFromSnowflake(this.id);
2150
+ return SnowflakeUtil3.dateFromSnowflake(this.id);
1529
2151
  }
1530
2152
  /**
1531
2153
  * Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
@@ -1539,19 +2161,36 @@ var Channel = class extends Base {
1539
2161
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1540
2162
  }
1541
2163
  }
1542
- /** Wired in `structures/channel/index.ts` after subclasses load. */
2164
+ /** @internal Factory wired after subclasses load. */
1543
2165
  static from(_c, _d) {
1544
2166
  throw new Error("Channel.from not initialized");
1545
2167
  }
2168
+ /** @internal Factory wired after subclasses load. */
1546
2169
  static fromOrCreate(_c, _d) {
1547
2170
  throw new Error("Channel.fromOrCreate not initialized");
1548
2171
  }
2172
+ /** @internal Factory wired after subclasses load. */
1549
2173
  static createDM(_c, _d) {
1550
2174
  throw new Error("Channel.createDM not initialized");
1551
2175
  }
1552
- /** Check if this channel supports sending messages (text/DM). */
2176
+ /**
2177
+ * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
2178
+ * Checks {@link ChannelType}, not whether `send` exists on the instance.
2179
+ */
1553
2180
  isTextBased() {
1554
- return "send" in this;
2181
+ return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
2182
+ }
2183
+ /** Check if this is a guild channel (text, voice, category, or link). */
2184
+ isGuild() {
2185
+ return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
2186
+ }
2187
+ /** Check if this is a guild text channel. */
2188
+ isText() {
2189
+ return this.type === ChannelType.GuildText;
2190
+ }
2191
+ /** Check if this is a category channel. */
2192
+ isCategory() {
2193
+ return this.type === ChannelType.GuildCategory;
1555
2194
  }
1556
2195
  /** Check if this is a DM, group DM, or personal notes channel. */
1557
2196
  isDM() {
@@ -1563,11 +2202,11 @@ var Channel = class extends Base {
1563
2202
  }
1564
2203
  /** Check if this is a voice channel. */
1565
2204
  isVoice() {
1566
- return "bitrate" in this;
2205
+ return this.type === ChannelType.GuildVoice;
1567
2206
  }
1568
2207
  /** Check if this is a link channel. */
1569
2208
  isLink() {
1570
- return "url" in this;
2209
+ return this.type === ChannelType.GuildLink;
1571
2210
  }
1572
2211
  /**
1573
2212
  * Delete recent messages or an explicit ID list.
@@ -1606,7 +2245,7 @@ var Channel = class extends Base {
1606
2245
  for (const id of ids) this.client._removeMessageFromCache(this.id, id);
1607
2246
  return ids;
1608
2247
  }
1609
- /** Delete all messages sent by the bot in this channel (user account feature). */
2248
+ /** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
1610
2249
  async bulkDeleteMyMessages(options) {
1611
2250
  const body = options ? toSudoBody(options) : void 0;
1612
2251
  await this.client.rest.post(Routes7.channelBulkDeleteMine(this.id), {
@@ -1614,11 +2253,17 @@ var Channel = class extends Base {
1614
2253
  auth: true
1615
2254
  });
1616
2255
  }
1617
- /** Mark all pinned messages as read in this channel. */
2256
+ /**
2257
+ * Mark all pinned messages as read in this channel.
2258
+ * Session-token helper; bots usually skip this.
2259
+ */
1618
2260
  async acknowledgePins() {
1619
2261
  await this.client.rest.post(Routes7.channelPinsAck(this.id), { auth: true });
1620
2262
  }
1621
- /** Clear the read state for this channel. */
2263
+ /**
2264
+ * Clear the read state for this channel.
2265
+ * Session-token helper; bots usually skip this.
2266
+ */
1622
2267
  async clearReadState() {
1623
2268
  await this.client.rest.delete(Routes7.channelMessagesAck(this.id), { auth: true });
1624
2269
  }
@@ -1654,7 +2299,11 @@ var Channel = class extends Base {
1654
2299
  async sendTyping() {
1655
2300
  await this.client.rest.post(Routes7.channelTyping(this.id), { auth: true });
1656
2301
  }
1657
- /** Fetch available RTC regions for voice channels. */
2302
+ /**
2303
+ * Fetch available RTC regions for voice channels.
2304
+ * User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
2305
+ * Bots should skip this and join voice with `@fluxerjs/voice` instead.
2306
+ */
1658
2307
  async fetchRtcRegions() {
1659
2308
  const data = await this.client.rest.get(Routes7.channelRtcRegions(this.id), {
1660
2309
  auth: true
@@ -1673,71 +2322,65 @@ var Channel = class extends Base {
1673
2322
  nextSendAllowedAt: data.next_send_allowed_at
1674
2323
  };
1675
2324
  }
1676
- /** Check if the bot can send messages in this channel. */
2325
+ /** Whether this channel type can carry messages (does not check permissions). */
1677
2326
  canSendMessage() {
1678
- return this.isDM();
2327
+ return this.isTextBased();
1679
2328
  }
1680
- };
1681
-
1682
- // src/Domain/Channel/Dm.ts
1683
- import { ChannelType as ChannelType2, Routes as Routes9 } from "@fluxerjs/types";
1684
-
1685
- // src/Domain/Channel/TextCapable.ts
1686
- import { Routes as Routes8 } from "@fluxerjs/types";
1687
-
1688
- // src/Helpers/MessageCollector.ts
1689
- import { EventEmitter as EventEmitter2 } from "events";
1690
- import { Collection as Collection4 } from "@fluxerjs/collection";
1691
- var MessageCollector = class extends EventEmitter2 {
1692
- client;
1693
- channelId;
1694
- options;
1695
- collected = new Collection4();
1696
- _timeout = null;
1697
- _ended = false;
1698
- _listener;
1699
- constructor(client, channelId, options = {}) {
1700
- super();
1701
- this.client = client;
1702
- this.channelId = channelId;
1703
- this.options = {
1704
- filter: options.filter ?? (() => true),
1705
- time: options.time ?? 0,
1706
- max: options.max ?? 0
1707
- };
1708
- this._listener = (message) => {
1709
- if (this._ended || message.channelId !== this.channelId) return;
1710
- if (!this.options.filter(message)) return;
1711
- this.collected.set(message.id, message);
1712
- this.emit("collect", message);
1713
- if (this.options.max > 0 && this.collected.size >= this.options.max) {
1714
- this.stop("limit");
1715
- }
1716
- };
1717
- this.client.on(Events.MessageCreate, this._listener);
1718
- if (this.options.time > 0) {
1719
- this._timeout = setTimeout(() => this.stop("time"), this.options.time);
2329
+ /** Per-channel message cache + fetch. */
2330
+ get messages() {
2331
+ if (!this.#messages) {
2332
+ this.#messages = new MessageManager(this.client, this.id);
1720
2333
  }
2334
+ return this.#messages;
1721
2335
  }
1722
- stop(reason = "user") {
1723
- if (this._ended) return;
1724
- this._ended = true;
1725
- this.client.off(Events.MessageCreate, this._listener);
1726
- if (this._timeout) {
1727
- clearTimeout(this._timeout);
1728
- this._timeout = null;
1729
- }
1730
- this.emit("end", this.collected, reason);
2336
+ /** Collect messages in this channel until time/max/stop. */
2337
+ createMessageCollector(options) {
2338
+ return new MessageCollector(this.client, this.id, options);
1731
2339
  }
1732
- on(event, listener) {
1733
- return super.on(event, listener);
2340
+ /**
2341
+ * Wait for messages matching the filter, then resolve the collected set.
2342
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
2343
+ * @example
2344
+ * const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
2345
+ */
2346
+ awaitMessages(options) {
2347
+ return MessageCollector.awaitMessages(this.client, this.id, options);
1734
2348
  }
1735
- emit(event, ...args) {
1736
- return super.emit(event, ...args);
2349
+ /**
2350
+ * Delete this channel (or close it if it is a DM).
2351
+ * Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
2352
+ * @example
2353
+ * const channel = await client.channels.fetch(channelId);
2354
+ * await channel.delete();
2355
+ */
2356
+ async delete(options) {
2357
+ const params = new URLSearchParams();
2358
+ if (options?.silent) params.set("silent", "true");
2359
+ if (options?.deleteMessages) params.set("delete_messages", "true");
2360
+ const qs2 = params.toString();
2361
+ const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2362
+ const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2363
+ await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2364
+ body,
2365
+ auth: true
2366
+ });
2367
+ this.client.channels.delete(this.id);
2368
+ this.client._clearMessageCache(this.id);
2369
+ if (this.isGuild() && this.guildId) {
2370
+ this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2371
+ }
2372
+ }
2373
+ /** Channel mention (`<#id>`). */
2374
+ toString() {
2375
+ return `<#${this.id}>`;
1737
2376
  }
1738
2377
  };
1739
2378
 
2379
+ // src/Domain/Channel/Dm.ts
2380
+ import { ChannelType as ChannelType2, Routes as Routes9 } from "@fluxerjs/types";
2381
+
1740
2382
  // src/Domain/Channel/TextCapable.ts
2383
+ import { Routes as Routes8 } from "@fluxerjs/types";
1741
2384
  async function fetchPinnedMessagesPageFor(client, channelId, options) {
1742
2385
  const params = new URLSearchParams();
1743
2386
  if (options?.limit != null) params.set("limit", String(options.limit));
@@ -1755,27 +2398,19 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
1755
2398
  }
1756
2399
  function TextCapable(Base2) {
1757
2400
  class TextCapableChannel extends Base2 {
1758
- #messages;
2401
+ /**
2402
+ * Send a message in this channel.
2403
+ * @example
2404
+ * await channel.send('hi');
2405
+ */
1759
2406
  async send(options) {
1760
- const payload = await prepareMessagePostPayload(options, {
1761
- defaultAllowedMentions: this.client.options.defaultAllowedMentions
1762
- });
1763
- const data = await this.client.rest.post(Routes8.channelMessages(this.id), payload);
1764
- this.client._addMessageToCache(this.id, data);
1765
- return new Message(this.client, data);
1766
- }
1767
- get messages() {
1768
- if (!this.#messages) {
1769
- this.#messages = new MessageManager(this.client, this.id);
1770
- }
1771
- return this.#messages;
1772
- }
1773
- createMessageCollector(options) {
1774
- return new MessageCollector(this.client, this.id, options);
2407
+ return this.client.channels.send(this.id, options);
1775
2408
  }
2409
+ /** Fetch pinned messages in this channel. */
1776
2410
  async fetchPinnedMessages(options) {
1777
2411
  return (await this.fetchPinnedMessagesPage(options)).messages;
1778
2412
  }
2413
+ /** Fetch a page of pinned messages plus pagination metadata. */
1779
2414
  async fetchPinnedMessagesPage(options) {
1780
2415
  return fetchPinnedMessagesPageFor(this.client, this.id, options);
1781
2416
  }
@@ -1801,7 +2436,38 @@ var DMChannel = class extends TextCapable(Channel) {
1801
2436
  this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
1802
2437
  this.nicks = full.nicks ?? {};
1803
2438
  }
1804
- /** Purge all messages from personal notes. Only works on personal notes channels. */
2439
+ /**
2440
+ * Apply DM/group-DM fields in place.
2441
+ * @internal
2442
+ */
2443
+ _patch(data) {
2444
+ super._patch(data);
2445
+ const full = data;
2446
+ if ("last_message_id" in full && full.last_message_id !== void 0) {
2447
+ this.lastMessageId = full.last_message_id ?? null;
2448
+ }
2449
+ if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2450
+ if ("recipients" in full && full.recipients !== void 0) {
2451
+ this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2452
+ }
2453
+ if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2454
+ }
2455
+ /**
2456
+ * Edit this group DM (name, icon, nicks).
2457
+ * Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
2458
+ */
2459
+ async edit(options) {
2460
+ const data = await this.client.rest.patch(Routes9.channel(this.id), {
2461
+ body: toGroupDmEditBody(options),
2462
+ auth: true
2463
+ });
2464
+ this._patch(data);
2465
+ return this;
2466
+ }
2467
+ /**
2468
+ * Purge all messages from personal notes. Only works on personal notes channels.
2469
+ * Notes-only; bots usually skip this.
2470
+ */
1805
2471
  async purgeMessages() {
1806
2472
  if (this.type !== ChannelType2.DMPersonalNotes) {
1807
2473
  throw new FluxerError("purgeMessages is only available on personal notes channels", {
@@ -1814,15 +2480,24 @@ var DMChannel = class extends TextCapable(Channel) {
1814
2480
  );
1815
2481
  return data.deleted_count;
1816
2482
  }
1817
- /** Pin this DM channel to the top of the DM list. */
2483
+ /**
2484
+ * Pin this DM channel to the top of the DM list.
2485
+ * Session-token helper; bots usually skip this.
2486
+ */
1818
2487
  async pinInList() {
1819
2488
  await this.client.rest.put(Routes9.userMeChannelPin(this.id), { auth: true });
1820
2489
  }
1821
- /** Unpin this DM channel from the DM list. */
2490
+ /**
2491
+ * Unpin this DM channel from the DM list.
2492
+ * Session-token helper; bots usually skip this.
2493
+ */
1822
2494
  async unpinFromList() {
1823
2495
  await this.client.rest.delete(Routes9.userMeChannelPin(this.id), { auth: true });
1824
2496
  }
1825
- /** Add a user to this group DM. */
2497
+ /**
2498
+ * Add a user to this group DM.
2499
+ * Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
2500
+ */
1826
2501
  async addRecipient(userId) {
1827
2502
  await this.client.rest.put(Routes9.channelRecipient(this.id, userId), { auth: true });
1828
2503
  const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
@@ -1838,7 +2513,7 @@ var DMChannel = class extends TextCapable(Channel) {
1838
2513
  };
1839
2514
 
1840
2515
  // src/Domain/Channel/Guild.ts
1841
- import { Routes as Routes12 } from "@fluxerjs/types";
2516
+ import { Routes as Routes13 } from "@fluxerjs/types";
1842
2517
  import { PermissionFlags } from "@fluxerjs/util";
1843
2518
 
1844
2519
  // src/Domain/Invite.ts
@@ -1846,19 +2521,11 @@ import {
1846
2521
  InviteType,
1847
2522
  isGroupDmInvite,
1848
2523
  isGuildInvite,
1849
- isPackInvite,
1850
2524
  Routes as Routes10
1851
2525
  } from "@fluxerjs/types";
1852
2526
 
1853
2527
  // src/Helpers/Instance.ts
1854
2528
  import { isRecord } from "@fluxerjs/util";
1855
-
1856
- // src/Helpers/Constants.ts
1857
- import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
1858
- var CDN_URL = "https://fluxerusercontent.com";
1859
- var STATIC_CDN_URL = "https://fluxerstatic.com";
1860
-
1861
- // src/Helpers/Instance.ts
1862
2529
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
1863
2530
  api: "https://api.fluxer.app",
1864
2531
  api_client: "https://web.fluxer.app/api",
@@ -2049,13 +2716,36 @@ function parseInviteCode(codeOrUrl) {
2049
2716
  }
2050
2717
  return code;
2051
2718
  }
2719
+ function parseOptionalDate(value) {
2720
+ if (value == null || value === "") return null;
2721
+ const date = new Date(value);
2722
+ return Number.isNaN(date.getTime()) ? null : date;
2723
+ }
2724
+ function toInviteGuild(data) {
2725
+ return {
2726
+ id: data.id,
2727
+ name: data.name,
2728
+ icon: data.icon ?? null,
2729
+ banner: data.banner ?? null,
2730
+ splash: data.splash ?? null,
2731
+ features: data.features ?? []
2732
+ };
2733
+ }
2734
+ function toInviteChannel(data) {
2735
+ return {
2736
+ id: data.id,
2737
+ name: data.name ?? null,
2738
+ type: data.type,
2739
+ icon: data.icon ?? null,
2740
+ parentId: data.parent_id ?? null
2741
+ };
2742
+ }
2052
2743
  var Invite = class _Invite extends Base {
2053
2744
  client;
2054
2745
  code;
2055
2746
  type;
2056
- guild;
2057
- channel;
2058
- pack;
2747
+ guildSnapshot;
2748
+ channelSnapshot;
2059
2749
  inviter;
2060
2750
  memberCount;
2061
2751
  presenceCount;
@@ -2070,15 +2760,14 @@ var Invite = class _Invite extends Base {
2070
2760
  this.client = client;
2071
2761
  this.code = data.code;
2072
2762
  this.type = data.type;
2073
- this.guild = isGuildInvite(data) ? data.guild : null;
2074
- this.channel = isGuildInvite(data) || isGroupDmInvite(data) ? data.channel : null;
2075
- this.pack = isPackInvite(data) ? data.pack : null;
2763
+ this.guildSnapshot = isGuildInvite(data) ? toInviteGuild(data.guild) : null;
2764
+ this.channelSnapshot = isGuildInvite(data) || isGroupDmInvite(data) ? toInviteChannel(data.channel) : null;
2076
2765
  this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
2077
- this.memberCount = isPackInvite(data) ? null : data.member_count ?? null;
2766
+ this.memberCount = data.member_count ?? null;
2078
2767
  this.presenceCount = isGuildInvite(data) ? data.presence_count ?? null : null;
2079
- this.expiresAt = data.expires_at ?? null;
2768
+ this.expiresAt = parseOptionalDate(data.expires_at);
2080
2769
  this.temporary = data.temporary ?? null;
2081
- this.createdAt = data.created_at ?? null;
2770
+ this.createdAt = parseOptionalDate(data.created_at);
2082
2771
  this.uses = data.uses ?? null;
2083
2772
  this.maxUses = data.max_uses ?? null;
2084
2773
  this.maxAge = data.max_age ?? null;
@@ -2089,16 +2778,25 @@ var Invite = class _Invite extends Base {
2089
2778
  isGroupDM() {
2090
2779
  return this.type === InviteType.GroupDM;
2091
2780
  }
2092
- isPack() {
2093
- return this.type === InviteType.EmojiPack || this.type === InviteType.StickerPack;
2094
- }
2095
2781
  /** Full invite URL (uses this client's instance invite base). */
2096
2782
  get url() {
2097
2783
  return inviteUrl(this.client.instance.endpoints.invite, this.code);
2098
2784
  }
2099
- /** Cached guild for guild invites, else null. */
2100
- getGuild() {
2101
- return this.guild?.id ? this.client.guilds.get(this.guild.id) ?? null : null;
2785
+ /**
2786
+ * Resolve the cached/fetched {@link Guild} for this invite, or null.
2787
+ * `guildSnapshot` is metadata only.
2788
+ */
2789
+ async resolveGuild() {
2790
+ if (!this.guildSnapshot?.id) return null;
2791
+ return this.client.guilds.resolve(this.guildSnapshot.id);
2792
+ }
2793
+ /**
2794
+ * Resolve the cached/fetched {@link Channel} for this invite, or null.
2795
+ * `channelSnapshot` is metadata only.
2796
+ */
2797
+ async resolveChannel() {
2798
+ if (!this.channelSnapshot?.id) return null;
2799
+ return this.client.channels.resolve(this.channelSnapshot.id);
2102
2800
  }
2103
2801
  /** Fetch invite metadata by code or URL (does not join). */
2104
2802
  static async fetch(client, codeOrUrl) {
@@ -2116,69 +2814,7 @@ import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
2116
2814
  import {
2117
2815
  Routes as Routes11
2118
2816
  } from "@fluxerjs/types";
2119
- import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
2120
-
2121
- // src/Helpers/Cdn.ts
2122
- function mediaBase(options) {
2123
- return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
2124
- }
2125
- function staticBase(options) {
2126
- return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
2127
- }
2128
- function getExtension(hash, options) {
2129
- const ext = options?.extension ?? "png";
2130
- if (hash?.startsWith("a_")) return "gif";
2131
- return ext;
2132
- }
2133
- function appendSize(options) {
2134
- return options?.size ? `?size=${options.size}` : "";
2135
- }
2136
- function cdnAvatarURL(userId, avatarHash, options) {
2137
- if (!avatarHash) return null;
2138
- const ext = getExtension(avatarHash, options);
2139
- const size = appendSize(options);
2140
- return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
2141
- }
2142
- function cdnDisplayAvatarURL(userId, avatarHash, options) {
2143
- return cdnAvatarURL(userId, avatarHash, options) ?? cdnDefaultAvatarURL(userId, options);
2144
- }
2145
- function cdnBannerURL(resourceId, bannerHash, options) {
2146
- if (!bannerHash) return null;
2147
- const ext = getExtension(bannerHash, options);
2148
- const size = appendSize(options);
2149
- return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
2150
- }
2151
- function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
2152
- if (!avatarHash) return null;
2153
- const ext = getExtension(avatarHash, options);
2154
- const size = appendSize(options);
2155
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
2156
- }
2157
- function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
2158
- if (!bannerHash) return null;
2159
- const ext = getExtension(bannerHash, options);
2160
- const size = appendSize(options);
2161
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
2162
- }
2163
- function cdnDefaultAvatarURL(userIdOrIndex, options) {
2164
- const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
2165
- return `${staticBase(options)}/avatars/${index}.png`;
2166
- }
2167
- function cdnGuildAssetURL(kind, id, hash, options) {
2168
- if (!hash) return null;
2169
- const size = options?.size ? `?size=${options.size}` : "";
2170
- return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
2171
- }
2172
- function cdnEmojiURL(emojiId, animated, options) {
2173
- const ext = animated ? "gif" : "png";
2174
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
2175
- }
2176
- function cdnStickerURL(stickerId, animated, options) {
2177
- const ext = animated ? "gif" : "png";
2178
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
2179
- }
2180
-
2181
- // src/Domain/Webhook.ts
2817
+ import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
2182
2818
  var Webhook = class _Webhook extends Base {
2183
2819
  /** Parent client instance. */
2184
2820
  client;
@@ -2215,11 +2851,11 @@ var Webhook = class _Webhook extends Base {
2215
2851
  }
2216
2852
  /** Unix timestamp (ms) when this webhook was created, derived from its snowflake ID. */
2217
2853
  get createdTimestamp() {
2218
- return SnowflakeUtil2.timestampFromSnowflake(this.id);
2854
+ return SnowflakeUtil4.timestampFromSnowflake(this.id);
2219
2855
  }
2220
2856
  /** Date when this webhook was created, derived from its snowflake ID. */
2221
2857
  get createdAt() {
2222
- return SnowflakeUtil2.dateFromSnowflake(this.id);
2858
+ return SnowflakeUtil4.dateFromSnowflake(this.id);
2223
2859
  }
2224
2860
  /** Delete this webhook (token auth when available, otherwise bot auth). */
2225
2861
  async delete() {
@@ -2341,9 +2977,103 @@ var Webhook = class _Webhook extends Base {
2341
2977
  }
2342
2978
  };
2343
2979
 
2980
+ // src/Domain/Channel/PermissionOverwriteManager.ts
2981
+ import { Collection as Collection6 } from "@fluxerjs/collection";
2982
+ import { Routes as Routes12 } from "@fluxerjs/types";
2983
+ import { resolvePermissionsToBitfield as resolvePermissionsToBitfield3 } from "@fluxerjs/util";
2984
+
2985
+ // src/Domain/Channel/PermissionOverwrite.ts
2986
+ import { PermissionsBitField } from "@fluxerjs/util";
2987
+ var PermissionOverwrite = class {
2988
+ id;
2989
+ type;
2990
+ /** @internal Raw allow bitfield string. */
2991
+ _allow;
2992
+ /** @internal Raw deny bitfield string. */
2993
+ _deny;
2994
+ constructor(data) {
2995
+ this.id = data.id;
2996
+ this.type = data.type;
2997
+ this._allow = data.allow ?? "0";
2998
+ this._deny = data.deny ?? "0";
2999
+ }
3000
+ /** Allowed permissions for this overwrite. */
3001
+ get allow() {
3002
+ return new PermissionsBitField(BigInt(this._allow || "0"));
3003
+ }
3004
+ /** Denied permissions for this overwrite. */
3005
+ get deny() {
3006
+ return new PermissionsBitField(BigInt(this._deny || "0"));
3007
+ }
3008
+ /** Wire shape for permission computation / REST. */
3009
+ toJSON() {
3010
+ return {
3011
+ id: this.id,
3012
+ type: this.type,
3013
+ allow: this._allow,
3014
+ deny: this._deny
3015
+ };
3016
+ }
3017
+ };
3018
+
3019
+ // src/Domain/Channel/PermissionOverwriteManager.ts
3020
+ var PermissionOverwriteManager = class {
3021
+ constructor(channel, initial = []) {
3022
+ this.channel = channel;
3023
+ this._patch(initial);
3024
+ }
3025
+ _cache = new Collection6();
3026
+ /** Cached overwrites keyed by role/member ID. */
3027
+ get cache() {
3028
+ return this._cache;
3029
+ }
3030
+ get size() {
3031
+ return this._cache.size;
3032
+ }
3033
+ [Symbol.iterator]() {
3034
+ return this._cache.values();
3035
+ }
3036
+ /** Wire-shaped overwrites for permission computation. */
3037
+ toJSON() {
3038
+ return [...this._cache.values()].map((o) => o.toJSON());
3039
+ }
3040
+ /** Edit or create a permission overwrite. */
3041
+ async edit(overwriteId, options) {
3042
+ const allow = options.allow !== void 0 ? resolvePermissionsToBitfield3(options.allow) : "0";
3043
+ const deny = options.deny !== void 0 ? resolvePermissionsToBitfield3(options.deny) : "0";
3044
+ await this.channel.client.rest.put(Routes12.channelPermission(this.channel.id, overwriteId), {
3045
+ body: { type: options.type, allow, deny },
3046
+ auth: true
3047
+ });
3048
+ this._cache.set(
3049
+ overwriteId,
3050
+ new PermissionOverwrite({
3051
+ id: overwriteId,
3052
+ type: options.type,
3053
+ allow,
3054
+ deny
3055
+ })
3056
+ );
3057
+ }
3058
+ /** Delete a permission overwrite. */
3059
+ async delete(overwriteId) {
3060
+ await this.channel.client.rest.delete(Routes12.channelPermission(this.channel.id, overwriteId), {
3061
+ auth: true
3062
+ });
3063
+ this._cache.delete(overwriteId);
3064
+ }
3065
+ /** @internal Sync from an API channel payload. */
3066
+ _patch(overwrites) {
3067
+ this._cache.clear();
3068
+ for (const entry of overwrites ?? []) {
3069
+ this._cache.set(entry.id, new PermissionOverwrite(entry));
3070
+ }
3071
+ }
3072
+ };
3073
+
2344
3074
  // src/Domain/Channel/Guild.ts
2345
3075
  var GuildChannel = class extends Channel {
2346
- /** Guild ID this channel belongs to. */
3076
+ /** Guild ID this channel belongs to, or null if missing from the payload. */
2347
3077
  guildId;
2348
3078
  /** Position in the channel list. */
2349
3079
  position;
@@ -2353,11 +3083,14 @@ var GuildChannel = class extends Channel {
2353
3083
  permissionOverwrites;
2354
3084
  constructor(client, data) {
2355
3085
  super(client, data);
2356
- this.guildId = data.guild_id ?? "";
3086
+ this.guildId = data.guild_id ?? null;
2357
3087
  this.name = data.name ?? null;
2358
3088
  this.position = data.position;
2359
3089
  this.parentId = data.parent_id ?? null;
2360
- this.permissionOverwrites = data.permission_overwrites ?? [];
3090
+ this.permissionOverwrites = new PermissionOverwriteManager(
3091
+ this,
3092
+ data.permission_overwrites ?? []
3093
+ );
2361
3094
  }
2362
3095
  /**
2363
3096
  * Apply guild-channel fields in place.
@@ -2369,13 +3102,13 @@ var GuildChannel = class extends Channel {
2369
3102
  if (data.position !== void 0) this.position = data.position;
2370
3103
  if (data.parent_id !== void 0) this.parentId = data.parent_id ?? null;
2371
3104
  if (data.permission_overwrites !== void 0) {
2372
- this.permissionOverwrites = data.permission_overwrites ?? [];
3105
+ this.permissionOverwrites._patch(data.permission_overwrites ?? []);
2373
3106
  }
2374
3107
  this.applyEditPatch(data);
2375
3108
  }
2376
3109
  /** Create a webhook for this channel. Requires Manage Webhooks. */
2377
3110
  async createWebhook(options) {
2378
- const data = await this.client.rest.post(Routes12.channelWebhooks(this.id), {
3111
+ const data = await this.client.rest.post(Routes13.channelWebhooks(this.id), {
2379
3112
  body: options,
2380
3113
  auth: true
2381
3114
  });
@@ -2383,13 +3116,13 @@ var GuildChannel = class extends Channel {
2383
3116
  }
2384
3117
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
2385
3118
  async fetchWebhooks() {
2386
- const data = await this.client.rest.get(Routes12.channelWebhooks(this.id));
3119
+ const data = await this.client.rest.get(Routes13.channelWebhooks(this.id));
2387
3120
  return data.map((w) => new Webhook(this.client, w));
2388
3121
  }
2389
3122
  /** Create an invite for this channel. Requires Create Instant Invite. */
2390
3123
  async createInvite(options) {
2391
3124
  const body = options ? toChannelInviteBody(options) : {};
2392
- const data = await this.client.rest.post(Routes12.channelInvites(this.id), {
3125
+ const data = await this.client.rest.post(Routes13.channelInvites(this.id), {
2393
3126
  body: Object.keys(body).length ? body : void 0,
2394
3127
  auth: true
2395
3128
  });
@@ -2397,109 +3130,160 @@ var GuildChannel = class extends Channel {
2397
3130
  }
2398
3131
  /** Fetch all invites for this channel. Requires Manage Channels. */
2399
3132
  async fetchInvites() {
2400
- const data = await this.client.rest.get(Routes12.channelInvites(this.id));
3133
+ const data = await this.client.rest.get(Routes13.channelInvites(this.id));
2401
3134
  return data.map((i) => new Invite(this.client, i));
2402
3135
  }
2403
- /** Edit or create a permission overwrite. Requires Manage Roles. */
2404
- async editPermission(overwriteId, options) {
2405
- await this.client.rest.put(Routes12.channelPermission(this.id, overwriteId), {
2406
- body: options,
2407
- auth: true
2408
- });
2409
- const entry = {
2410
- id: overwriteId,
2411
- type: options.type,
2412
- allow: options.allow ?? "0",
2413
- deny: options.deny ?? "0"
2414
- };
2415
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2416
- if (idx >= 0) this.permissionOverwrites[idx] = entry;
2417
- else this.permissionOverwrites.push(entry);
2418
- }
2419
- /** Delete a permission overwrite. Requires Manage Roles. */
2420
- async deletePermission(overwriteId) {
2421
- await this.client.rest.delete(Routes12.channelPermission(this.id, overwriteId), { auth: true });
2422
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2423
- if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
2424
- }
2425
- /** Check if the bot can send messages in this channel (with permissions). */
3136
+ /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
2426
3137
  canSendMessage() {
3138
+ if (!this.guildId) return false;
2427
3139
  const me = this.client.guilds.get(this.guildId)?.members.me;
2428
3140
  if (!me) return false;
2429
3141
  const perms = me.permissionsIn(this);
2430
3142
  return perms.has(PermissionFlags.ViewChannel) && perms.has(PermissionFlags.SendMessages);
2431
3143
  }
3144
+ /**
3145
+ * Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
3146
+ * Returns false when the channel has no guildId.
3147
+ */
3148
+ async canSend() {
3149
+ if (!this.guildId) return false;
3150
+ const guild = this.client.guilds.get(this.guildId);
3151
+ if (!guild) return false;
3152
+ if (!guild.members.me) {
3153
+ try {
3154
+ await guild.members.fetchMe();
3155
+ } catch {
3156
+ return false;
3157
+ }
3158
+ }
3159
+ return this.canSendMessage();
3160
+ }
2432
3161
  /** Edit this channel's settings. Requires Manage Channels. */
2433
3162
  async edit(options) {
2434
- const data = await this.client.rest.patch(Routes12.channel(this.id), {
3163
+ const data = await this.client.rest.patch(Routes13.channel(this.id), {
2435
3164
  body: toChannelEditBody(options),
2436
3165
  auth: true
2437
3166
  });
2438
3167
  this.name = data.name ?? this.name;
2439
3168
  this.parentId = data.parent_id ?? this.parentId;
2440
- this.permissionOverwrites = data.permission_overwrites ?? this.permissionOverwrites;
3169
+ if (data.permission_overwrites !== void 0) {
3170
+ this.permissionOverwrites._patch(data.permission_overwrites);
3171
+ }
2441
3172
  this.applyEditPatch(data);
2442
3173
  return this;
2443
3174
  }
2444
3175
  applyEditPatch(_data) {
2445
3176
  }
2446
- /** Delete this channel. Requires Manage Channels or channel ownership. */
2447
- async delete(options) {
2448
- const params = new URLSearchParams();
2449
- if (options?.silent) params.set("silent", "true");
2450
- if (options?.deleteMessages) params.set("delete_messages", "true");
2451
- const qs2 = params.toString();
2452
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2453
- const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2454
- await this.client.rest.delete(Routes12.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2455
- body,
2456
- auth: true
2457
- });
2458
- this.client.channels.delete(this.id);
2459
- this.client._clearMessageCache(this.id);
2460
- this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2461
- }
2462
3177
  };
2463
3178
  var TextChannel = class extends TextCapable(GuildChannel) {
2464
3179
  /** Channel topic. */
2465
3180
  topic;
2466
3181
  /** Whether this channel is marked as NSFW. */
2467
3182
  nsfw;
3183
+ /** Per-channel NSFW override (`null` inherits). */
3184
+ nsfwOverride;
2468
3185
  /** Slowmode rate limit in seconds. */
2469
3186
  rateLimitPerUser;
2470
3187
  /** ID of the last message sent in this channel. */
2471
3188
  lastMessageId;
3189
+ /** Content warning level. */
3190
+ contentWarningLevel;
3191
+ /** Custom content warning text. */
3192
+ contentWarningText;
2472
3193
  constructor(client, data) {
2473
3194
  super(client, data);
2474
3195
  this.topic = data.topic ?? null;
2475
3196
  this.nsfw = data.nsfw ?? false;
3197
+ this.nsfwOverride = data.nsfw_override ?? null;
2476
3198
  this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
2477
3199
  this.lastMessageId = data.last_message_id ?? null;
3200
+ this.contentWarningLevel = data.content_warning_level ?? null;
3201
+ this.contentWarningText = data.content_warning_text ?? null;
3202
+ }
3203
+ /**
3204
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3205
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3206
+ */
3207
+ async setSlowmode(seconds) {
3208
+ return this.edit({ rateLimitPerUser: seconds });
2478
3209
  }
2479
3210
  applyEditPatch(data) {
2480
3211
  if ("topic" in data) this.topic = data.topic ?? null;
2481
3212
  if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3213
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
2482
3214
  if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3215
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3216
+ if ("content_warning_level" in data) {
3217
+ this.contentWarningLevel = data.content_warning_level ?? null;
3218
+ }
3219
+ if ("content_warning_text" in data) {
3220
+ this.contentWarningText = data.content_warning_text ?? null;
3221
+ }
2483
3222
  }
2484
3223
  };
2485
3224
  var CategoryChannel = class extends GuildChannel {
2486
3225
  };
2487
- var VoiceChannel = class extends GuildChannel {
3226
+ var VoiceChannel = class extends TextCapable(GuildChannel) {
3227
+ /** Channel topic. */
3228
+ topic;
3229
+ /** Whether this channel is marked as NSFW. */
3230
+ nsfw;
3231
+ /** Per-channel NSFW override (`null` inherits). */
3232
+ nsfwOverride;
3233
+ /** Slowmode rate limit in seconds. */
3234
+ rateLimitPerUser;
3235
+ /** ID of the last message sent in this channel. */
3236
+ lastMessageId;
3237
+ /** Content warning level. */
3238
+ contentWarningLevel;
3239
+ /** Custom content warning text. */
3240
+ contentWarningText;
2488
3241
  /** Voice bitrate. */
2489
3242
  bitrate;
2490
3243
  /** Maximum number of users allowed. */
2491
3244
  userLimit;
3245
+ /** Max active voice connections per user. */
3246
+ voiceConnectionLimit;
2492
3247
  /** RTC region override for this channel. */
2493
3248
  rtcRegion;
2494
3249
  constructor(client, data) {
2495
3250
  super(client, data);
3251
+ this.topic = data.topic ?? null;
3252
+ this.nsfw = data.nsfw ?? false;
3253
+ this.nsfwOverride = data.nsfw_override ?? null;
3254
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3255
+ this.lastMessageId = data.last_message_id ?? null;
3256
+ this.contentWarningLevel = data.content_warning_level ?? null;
3257
+ this.contentWarningText = data.content_warning_text ?? null;
2496
3258
  this.bitrate = data.bitrate ?? null;
2497
3259
  this.userLimit = data.user_limit ?? null;
3260
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
2498
3261
  this.rtcRegion = data.rtc_region ?? null;
2499
3262
  }
3263
+ /**
3264
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3265
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3266
+ */
3267
+ async setSlowmode(seconds) {
3268
+ return this.edit({ rateLimitPerUser: seconds });
3269
+ }
2500
3270
  applyEditPatch(data) {
3271
+ if ("topic" in data) this.topic = data.topic ?? null;
3272
+ if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3273
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
3274
+ if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3275
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3276
+ if ("content_warning_level" in data) {
3277
+ this.contentWarningLevel = data.content_warning_level ?? null;
3278
+ }
3279
+ if ("content_warning_text" in data) {
3280
+ this.contentWarningText = data.content_warning_text ?? null;
3281
+ }
2501
3282
  if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
2502
3283
  if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
3284
+ if ("voice_connection_limit" in data) {
3285
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3286
+ }
2503
3287
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
2504
3288
  }
2505
3289
  };
@@ -2510,6 +3294,9 @@ var LinkChannel = class extends GuildChannel {
2510
3294
  super(client, data);
2511
3295
  this.url = data.url ?? null;
2512
3296
  }
3297
+ applyEditPatch(data) {
3298
+ if ("url" in data) this.url = data.url ?? null;
3299
+ }
2513
3300
  };
2514
3301
 
2515
3302
  // src/Domain/Channel/Factory.ts
@@ -2542,8 +3329,8 @@ Channel.fromOrCreate = channelFromOrCreate;
2542
3329
  Channel.createDM = createDM;
2543
3330
 
2544
3331
  // src/Domain/Guild/GuildEmoji.ts
2545
- import { Routes as Routes13 } from "@fluxerjs/types";
2546
- import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
3332
+ import { Routes as Routes14 } from "@fluxerjs/types";
3333
+ import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
2547
3334
  var GuildEmoji = class extends Base {
2548
3335
  client;
2549
3336
  id;
@@ -2579,11 +3366,11 @@ var GuildEmoji = class extends Base {
2579
3366
  }
2580
3367
  /** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
2581
3368
  get createdTimestamp() {
2582
- return SnowflakeUtil3.timestampFromSnowflake(this.id);
3369
+ return SnowflakeUtil5.timestampFromSnowflake(this.id);
2583
3370
  }
2584
3371
  /** Date when this emoji was created, derived from its snowflake ID. */
2585
3372
  get createdAt() {
2586
- return SnowflakeUtil3.dateFromSnowflake(this.id);
3373
+ return SnowflakeUtil5.dateFromSnowflake(this.id);
2587
3374
  }
2588
3375
  /** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
2589
3376
  toString() {
@@ -2591,7 +3378,7 @@ var GuildEmoji = class extends Base {
2591
3378
  }
2592
3379
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
2593
3380
  async delete() {
2594
- await this.client.rest.delete(Routes13.guildEmoji(this.guildId, this.id), {
3381
+ await this.client.rest.delete(Routes14.guildEmoji(this.guildId, this.id), {
2595
3382
  auth: true
2596
3383
  });
2597
3384
  const guild = this.client.guilds.get(this.guildId);
@@ -2602,7 +3389,7 @@ var GuildEmoji = class extends Base {
2602
3389
  * Requires Manage Emojis and Stickers permission.
2603
3390
  */
2604
3391
  async edit(options) {
2605
- const data = await this.client.rest.patch(Routes13.guildEmoji(this.guildId, this.id), {
3392
+ const data = await this.client.rest.patch(Routes14.guildEmoji(this.guildId, this.id), {
2606
3393
  body: options,
2607
3394
  auth: true
2608
3395
  });
@@ -2612,8 +3399,8 @@ var GuildEmoji = class extends Base {
2612
3399
  };
2613
3400
 
2614
3401
  // src/Domain/Guild/GuildMember.ts
2615
- import { Routes as Routes15 } from "@fluxerjs/types";
2616
- import { PermissionsBitField } from "@fluxerjs/util";
3402
+ import { Routes as Routes16 } from "@fluxerjs/types";
3403
+ import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
2617
3404
 
2618
3405
  // src/Helpers/Permissions.ts
2619
3406
  import { OverwriteType } from "@fluxerjs/types";
@@ -2632,8 +3419,8 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
2632
3419
  }
2633
3420
 
2634
3421
  // src/Domain/Guild/GuildMemberRoleManager.ts
2635
- import { Collection as Collection5 } from "@fluxerjs/collection";
2636
- import { Routes as Routes14 } from "@fluxerjs/types";
3422
+ import { Collection as Collection7 } from "@fluxerjs/collection";
3423
+ import { Routes as Routes15 } from "@fluxerjs/types";
2637
3424
  function roleId(roleOrId) {
2638
3425
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
2639
3426
  }
@@ -2651,7 +3438,7 @@ var GuildMemberRoleManager = class {
2651
3438
  }
2652
3439
  /** Live Role objects from `guild.roles` for this member's role IDs. */
2653
3440
  get cache() {
2654
- const out = new Collection5();
3441
+ const out = new Collection7();
2655
3442
  for (const id of this.ids) {
2656
3443
  const role = this.member.guild.roles.get(id);
2657
3444
  if (role) out.set(id, role);
@@ -2662,7 +3449,7 @@ var GuildMemberRoleManager = class {
2662
3449
  const id = roleId(roleOrId);
2663
3450
  if (this.ids.includes(id)) return;
2664
3451
  await this.member.client.rest.put(
2665
- Routes14.guildMemberRole(this.member.guild.id, this.member.id, id)
3452
+ Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
2666
3453
  );
2667
3454
  this.ids.push(id);
2668
3455
  }
@@ -2671,13 +3458,13 @@ var GuildMemberRoleManager = class {
2671
3458
  const idx = this.ids.indexOf(id);
2672
3459
  if (idx === -1) return;
2673
3460
  await this.member.client.rest.delete(
2674
- Routes14.guildMemberRole(this.member.guild.id, this.member.id, id)
3461
+ Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
2675
3462
  );
2676
3463
  this.ids.splice(idx, 1);
2677
3464
  }
2678
3465
  async set(roleIds) {
2679
3466
  const data = await this.member.client.rest.patch(
2680
- Routes14.guildMember(this.member.guild.id, this.member.id),
3467
+ Routes15.guildMember(this.member.guild.id, this.member.id),
2681
3468
  { body: { roles: roleIds }, auth: true }
2682
3469
  );
2683
3470
  this.ids = data.roles ? [...data.roles] : [];
@@ -2690,6 +3477,8 @@ var GuildMemberRoleManager = class {
2690
3477
 
2691
3478
  // src/Domain/Guild/GuildMember.ts
2692
3479
  var GuildMember = class _GuildMember extends Base {
3480
+ /** Discriminant vs {@link PartialGuildMember}: always `false` on a hydrated member. */
3481
+ partial = false;
2693
3482
  /** Parent client instance. */
2694
3483
  client;
2695
3484
  /** User ID (same as `user.id`). */
@@ -2718,6 +3507,12 @@ var GuildMember = class _GuildMember extends Base {
2718
3507
  accentColor;
2719
3508
  /** Guild-specific profile flags. */
2720
3509
  profileFlags;
3510
+ /** Per-guild reply mention preference override. */
3511
+ mentionFlags;
3512
+ /** Guild-specific bio (set from member edit; not always on GET member). */
3513
+ bio;
3514
+ /** Guild-specific pronouns (set from member edit; not always on GET member). */
3515
+ pronouns;
2721
3516
  constructor(client, data, guild) {
2722
3517
  super();
2723
3518
  this.client = client;
@@ -2734,6 +3529,9 @@ var GuildMember = class _GuildMember extends Base {
2734
3529
  this.banner = data.banner ?? null;
2735
3530
  this.accentColor = data.accent_color ?? null;
2736
3531
  this.profileFlags = data.profile_flags ?? null;
3532
+ this.mentionFlags = data.mention_flags ?? null;
3533
+ this.bio = data.bio ?? null;
3534
+ this.pronouns = data.pronouns ?? null;
2737
3535
  }
2738
3536
  /**
2739
3537
  * Apply an API member payload in place (gateway GUILD_MEMBER_UPDATE / REST edit).
@@ -2752,6 +3550,9 @@ var GuildMember = class _GuildMember extends Base {
2752
3550
  if (data.banner !== void 0) this.banner = data.banner ?? null;
2753
3551
  if (data.accent_color !== void 0) this.accentColor = data.accent_color ?? null;
2754
3552
  if (data.profile_flags !== void 0) this.profileFlags = data.profile_flags ?? null;
3553
+ if (data.mention_flags !== void 0) this.mentionFlags = data.mention_flags ?? null;
3554
+ if (data.bio !== void 0) this.bio = data.bio ?? null;
3555
+ if (data.pronouns !== void 0) this.pronouns = data.pronouns ?? null;
2755
3556
  }
2756
3557
  /**
2757
3558
  * Snapshot for `guildMemberUpdate` old-member arg (before in-place patch).
@@ -2780,7 +3581,10 @@ var GuildMember = class _GuildMember extends Base {
2780
3581
  avatar: this.avatar,
2781
3582
  banner: this.banner,
2782
3583
  accent_color: this.accentColor,
2783
- profile_flags: this.profileFlags ?? void 0
3584
+ profile_flags: this.profileFlags ?? void 0,
3585
+ mention_flags: this.mentionFlags,
3586
+ bio: this.bio,
3587
+ pronouns: this.pronouns
2784
3588
  },
2785
3589
  this.guild
2786
3590
  );
@@ -2807,15 +3611,22 @@ var GuildMember = class _GuildMember extends Base {
2807
3611
  mediaBase: this.client.instance.endpoints.media
2808
3612
  });
2809
3613
  }
2810
- /** PATCH member (`/members/@me` when editing the bot). */
3614
+ /**
3615
+ * PATCH member (`/members/@me` when editing the bot).
3616
+ * @example
3617
+ * await member.edit({ nick: 'Ada' });
3618
+ */
2811
3619
  async edit(options) {
2812
3620
  const isMe = this.client.user?.id === this.id;
2813
- const route = isMe ? Routes15.guildMemberMe(this.guild.id) : Routes15.guildMember(this.guild.id, this.id);
3621
+ const route = isMe ? Routes16.guildMemberMe(this.guild.id) : Routes16.guildMember(this.guild.id, this.id);
2814
3622
  const data = await this.client.rest.patch(route, {
2815
3623
  body: toMemberEditBody(options),
2816
3624
  auth: true
2817
3625
  });
2818
3626
  this._patch(data);
3627
+ if (options.bio !== void 0) this.bio = options.bio;
3628
+ if (options.pronouns !== void 0) this.pronouns = options.pronouns;
3629
+ if (options.mentionFlags !== void 0) this.mentionFlags = options.mentionFlags;
2819
3630
  return this;
2820
3631
  }
2821
3632
  /**
@@ -2823,25 +3634,82 @@ var GuildMember = class _GuildMember extends Base {
2823
3634
  * @see {@link permissionsIn} for channel-specific permissions
2824
3635
  */
2825
3636
  get permissions() {
2826
- return new PermissionsBitField(this._effectivePermissions([], []));
3637
+ return new PermissionsBitField2(this._effectivePermissions([], []));
3638
+ }
3639
+ /**
3640
+ * Effective permissions in a channel (roles + overwrites).
3641
+ * @param channel - The guild channel
3642
+ * @returns Computed permissions bitfield
3643
+ */
3644
+ permissionsIn(channel) {
3645
+ return new PermissionsBitField2(
3646
+ this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
3647
+ );
3648
+ }
3649
+ /**
3650
+ * Move to a voice channel, or `null` to disconnect. Requires Move Members.
3651
+ * @param channelId - Voice channel ID or null to disconnect
3652
+ * @param connectionId - Optional connection ID for multi-session scenarios
3653
+ */
3654
+ async move(channelId, connectionId) {
3655
+ await this.edit({ channelId, connectionId });
3656
+ }
3657
+ /** Kick this member. Requires Kick Members. */
3658
+ async kick() {
3659
+ await this.guild.kick(this.id);
3660
+ }
3661
+ /** Ban this member. Requires Ban Members. */
3662
+ async ban(options) {
3663
+ await this.guild.ban(this.id, options);
3664
+ }
3665
+ /**
3666
+ * Whether the bot can kick this member (cache-only; needs `members.me`).
3667
+ * False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
3668
+ */
3669
+ get kickable() {
3670
+ return this._moderatableWith(PermissionFlags3.KickMembers);
3671
+ }
3672
+ /**
3673
+ * Whether the bot can ban this member (cache-only; needs `members.me`).
3674
+ */
3675
+ get bannable() {
3676
+ return this._moderatableWith(PermissionFlags3.BanMembers);
2827
3677
  }
2828
3678
  /**
2829
- * Effective permissions in a channel (roles + overwrites).
2830
- * @param channel - The guild channel
2831
- * @returns Computed permissions bitfield
3679
+ * Whether the bot can timeout this member (cache-only; needs `members.me`).
2832
3680
  */
2833
- permissionsIn(channel) {
2834
- return new PermissionsBitField(
2835
- this._effectivePermissions(channel.permissionOverwrites, [...this.roles.roleIds])
2836
- );
3681
+ get moderatable() {
3682
+ return this._moderatableWith(PermissionFlags3.ModerateMembers);
3683
+ }
3684
+ _moderatableWith(flag) {
3685
+ const me = this.guild.members.me;
3686
+ if (!me) return false;
3687
+ if (this.id === me.id) return false;
3688
+ if (this.guild.ownerId != null && String(this.guild.ownerId) === String(this.id)) return false;
3689
+ if (!me.permissions.has(flag)) return false;
3690
+ return this._compareRolePosition(me) < 0;
3691
+ }
3692
+ /** Negative when this member's highest role is below `other`'s. */
3693
+ _compareRolePosition(other) {
3694
+ const highest = (m) => {
3695
+ let pos = -1;
3696
+ for (const role of m.roles.cache.values()) {
3697
+ if (role.position > pos) pos = role.position;
3698
+ }
3699
+ return pos;
3700
+ };
3701
+ return highest(this) - highest(other);
2837
3702
  }
2838
3703
  /**
2839
- * Move to a voice channel, or `null` to disconnect. Requires Move Members.
2840
- * @param channelId - Voice channel ID or null to disconnect
2841
- * @param connectionId - Optional connection ID for multi-session scenarios
3704
+ * Timeout this member for `durationMs` milliseconds, or pass `null` to clear.
3705
+ * Requires Moderate Members.
2842
3706
  */
2843
- async move(channelId, connectionId) {
2844
- await this.edit({ channelId, connectionId });
3707
+ async timeout(durationMs, reason) {
3708
+ const communicationDisabledUntil = durationMs == null || durationMs <= 0 ? null : new Date(Date.now() + durationMs).toISOString();
3709
+ return this.edit({
3710
+ communicationDisabledUntil,
3711
+ ...reason !== void 0 ? { timeoutReason: reason } : {}
3712
+ });
2845
3713
  }
2846
3714
  _effectivePermissions(overwrites, roleIds) {
2847
3715
  const ownerId = this.guild.ownerId;
@@ -2862,8 +3730,8 @@ var GuildMember = class _GuildMember extends Base {
2862
3730
  };
2863
3731
 
2864
3732
  // src/Domain/Guild/GuildSticker.ts
2865
- import { Routes as Routes16 } from "@fluxerjs/types";
2866
- import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
3733
+ import { Routes as Routes17 } from "@fluxerjs/types";
3734
+ import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
2867
3735
  var GuildSticker = class extends Base {
2868
3736
  client;
2869
3737
  id;
@@ -2905,15 +3773,15 @@ var GuildSticker = class extends Base {
2905
3773
  }
2906
3774
  /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
2907
3775
  get createdTimestamp() {
2908
- return SnowflakeUtil4.timestampFromSnowflake(this.id);
3776
+ return SnowflakeUtil6.timestampFromSnowflake(this.id);
2909
3777
  }
2910
3778
  /** Date when this sticker was created, derived from its snowflake ID. */
2911
3779
  get createdAt() {
2912
- return SnowflakeUtil4.dateFromSnowflake(this.id);
3780
+ return SnowflakeUtil6.dateFromSnowflake(this.id);
2913
3781
  }
2914
3782
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
2915
3783
  async delete() {
2916
- await this.client.rest.delete(Routes16.guildSticker(this.guildId, this.id), {
3784
+ await this.client.rest.delete(Routes17.guildSticker(this.guildId, this.id), {
2917
3785
  auth: true
2918
3786
  });
2919
3787
  const guild = this.client.guilds.get(this.guildId);
@@ -2924,7 +3792,7 @@ var GuildSticker = class extends Base {
2924
3792
  * Requires Manage Emojis and Stickers permission.
2925
3793
  */
2926
3794
  async edit(options) {
2927
- const data = await this.client.rest.patch(Routes16.guildSticker(this.guildId, this.id), {
3795
+ const data = await this.client.rest.patch(Routes17.guildSticker(this.guildId, this.id), {
2928
3796
  body: options,
2929
3797
  auth: true
2930
3798
  });
@@ -2936,12 +3804,12 @@ var GuildSticker = class extends Base {
2936
3804
  };
2937
3805
 
2938
3806
  // src/Domain/Guild/Role.ts
2939
- import { Routes as Routes17 } from "@fluxerjs/types";
3807
+ import { Routes as Routes18 } from "@fluxerjs/types";
2940
3808
  import {
2941
3809
  ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
2942
- PermissionFlags as PermissionFlags3,
2943
- PermissionsBitField as PermissionsBitField2,
2944
- SnowflakeUtil as SnowflakeUtil5
3810
+ PermissionFlags as PermissionFlags4,
3811
+ PermissionsBitField as PermissionsBitField3,
3812
+ SnowflakeUtil as SnowflakeUtil7
2945
3813
  } from "@fluxerjs/util";
2946
3814
  var Role = class _Role extends Base {
2947
3815
  /** Parent client instance. */
@@ -2985,21 +3853,29 @@ var Role = class _Role extends Base {
2985
3853
  */
2986
3854
  get permissions() {
2987
3855
  const bits = BigInt(this._permissions);
2988
- return new PermissionsBitField2(
2989
- (bits & PermissionFlags3.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
3856
+ return new PermissionsBitField3(
3857
+ (bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
2990
3858
  );
2991
3859
  }
3860
+ /**
3861
+ * Alias of {@link permissions}.has for discord.js-style checks.
3862
+ * @example
3863
+ * if (role.has(PermissionFlags.BanMembers)) { ... }
3864
+ */
3865
+ has(permission) {
3866
+ return this.permissions.has(permission);
3867
+ }
2992
3868
  /**
2993
3869
  * Format as a mention string (`<@&id>`).
2994
3870
  * @returns Mention syntax
2995
3871
  */
2996
3872
  /** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
2997
3873
  get createdTimestamp() {
2998
- return SnowflakeUtil5.timestampFromSnowflake(this.id);
3874
+ return SnowflakeUtil7.timestampFromSnowflake(this.id);
2999
3875
  }
3000
3876
  /** Date when this role was created, derived from its snowflake ID. */
3001
3877
  get createdAt() {
3002
- return SnowflakeUtil5.dateFromSnowflake(this.id);
3878
+ return SnowflakeUtil7.dateFromSnowflake(this.id);
3003
3879
  }
3004
3880
  toString() {
3005
3881
  return `<@&${this.id}>`;
@@ -3042,8 +3918,8 @@ var Role = class _Role extends Base {
3042
3918
  * @returns This role instance (updated in-place)
3043
3919
  */
3044
3920
  async edit(options) {
3045
- const body = toRoleRequestBody(options);
3046
- const data = await this.client.rest.patch(Routes17.guildRole(this.guildId, this.id), {
3921
+ const body = toRoleEditBody(options);
3922
+ const data = await this.client.rest.patch(Routes18.guildRole(this.guildId, this.id), {
3047
3923
  body: Object.keys(body).length ? body : void 0,
3048
3924
  auth: true
3049
3925
  });
@@ -3054,7 +3930,7 @@ var Role = class _Role extends Base {
3054
3930
  * DELETE role. Requires Manage Roles.
3055
3931
  */
3056
3932
  async delete() {
3057
- await this.client.rest.delete(Routes17.guildRole(this.guildId, this.id), { auth: true });
3933
+ await this.client.rest.delete(Routes18.guildRole(this.guildId, this.id), { auth: true });
3058
3934
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
3059
3935
  }
3060
3936
  };
@@ -3062,17 +3938,15 @@ var Role = class _Role extends Base {
3062
3938
  // src/Domain/Guild/Cache.ts
3063
3939
  function putChannel(client, channel, guild) {
3064
3940
  client.channels.set(channel.id, channel);
3065
- const resolvedGuild = guild ?? (() => {
3066
- const guildId = "guildId" in channel ? channel.guildId : void 0;
3067
- return guildId ? client.guilds.get(guildId) : void 0;
3068
- })();
3941
+ if (!channel.isGuild()) return;
3942
+ const resolvedGuild = guild ?? (channel.guildId ? client.guilds.get(channel.guildId) : void 0);
3069
3943
  if (resolvedGuild) {
3070
3944
  resolvedGuild.channels.set(channel.id, channel);
3071
3945
  }
3072
3946
  }
3073
3947
  function cacheChannel(guild, data) {
3074
3948
  const existing = guild.channels.get(data.id) ?? guild.client.channels.get(data.id);
3075
- if (existing && "guildId" in existing && existing.type === data.type) {
3949
+ if (existing?.isGuild() && existing.type === data.type) {
3076
3950
  existing._patch(data);
3077
3951
  putChannel(guild.client, existing, guild);
3078
3952
  return existing;
@@ -3186,6 +4060,10 @@ var ChannelManager = class extends LimitedCollection {
3186
4060
  });
3187
4061
  this.client = client;
3188
4062
  }
4063
+ /**
4064
+ * Remove a channel from cache. Does not delete it on the API.
4065
+ * Use {@link Channel.delete} after {@link fetch} to delete the channel.
4066
+ */
3189
4067
  delete(key) {
3190
4068
  const channel = this.get(key);
3191
4069
  const deleted = super.delete(key);
@@ -3199,15 +4077,20 @@ var ChannelManager = class extends LimitedCollection {
3199
4077
  return this.get(channelId) ?? this.fetch(channelId);
3200
4078
  }
3201
4079
  /**
3202
- * Fetch a channel by ID.
3203
- * Returns the cached channel unless `force` is set, in which case REST metadata is applied.
4080
+ * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
4081
+ * and {@link Channel.send} (send throws if the type is not text-based).
4082
+ * Returns the cached channel unless `force` is set.
4083
+ * @example
4084
+ * const channel = await client.channels.fetch(channelId);
4085
+ * await channel.delete();
4086
+ * await channel.send('hi');
3204
4087
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
3205
4088
  */
3206
4089
  async fetch(channelId, options) {
3207
4090
  const cached = this.get(channelId);
3208
4091
  if (cached && !options?.force) return cached;
3209
4092
  try {
3210
- const data = await this.client.rest.get(Routes18.channel(channelId));
4093
+ const data = await this.client.rest.get(Routes19.channel(channelId));
3211
4094
  const guildId = "guild_id" in data ? data.guild_id : void 0;
3212
4095
  if (guildId) {
3213
4096
  const guild = this.client.guilds.get(guildId);
@@ -3243,6 +4126,7 @@ var ChannelManager = class extends LimitedCollection {
3243
4126
  }
3244
4127
  /**
3245
4128
  * Send to a channel by ID without resolving it first.
4129
+ * Prefer {@link Channel.send} after {@link fetch} when you want the channel object.
3246
4130
  * @example
3247
4131
  * await client.channels.send(logChannelId, 'User joined!');
3248
4132
  */
@@ -3251,7 +4135,7 @@ var ChannelManager = class extends LimitedCollection {
3251
4135
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
3252
4136
  });
3253
4137
  const data = await this.client.rest.post(
3254
- Routes18.channelMessages(channelId),
4138
+ Routes19.channelMessages(channelId),
3255
4139
  postPayload
3256
4140
  );
3257
4141
  this.client._addMessageToCache(channelId, data);
@@ -3266,8 +4150,8 @@ import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes34 } from "@fluxerjs
3266
4150
  import { createLogger } from "@fluxerjs/util";
3267
4151
 
3268
4152
  // src/Domain/User.ts
3269
- import { Routes as Routes19 } from "@fluxerjs/types";
3270
- import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
4153
+ import { Routes as Routes20 } from "@fluxerjs/types";
4154
+ import { SnowflakeUtil as SnowflakeUtil8 } from "@fluxerjs/util";
3271
4155
  var User = class extends Base {
3272
4156
  /** Parent client instance. */
3273
4157
  client;
@@ -3351,11 +4235,11 @@ var User = class extends Base {
3351
4235
  */
3352
4236
  /** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
3353
4237
  get createdTimestamp() {
3354
- return SnowflakeUtil6.timestampFromSnowflake(this.id);
4238
+ return SnowflakeUtil8.timestampFromSnowflake(this.id);
3355
4239
  }
3356
4240
  /** Date when this account was created, derived from its snowflake ID. */
3357
4241
  get createdAt() {
3358
- return SnowflakeUtil6.dateFromSnowflake(this.id);
4242
+ return SnowflakeUtil8.dateFromSnowflake(this.id);
3359
4243
  }
3360
4244
  toString() {
3361
4245
  return `<@${this.id}>`;
@@ -3365,7 +4249,7 @@ var User = class extends Base {
3365
4249
  * @returns DM channel instance (cached if already open)
3366
4250
  */
3367
4251
  async createDM() {
3368
- const data = await this.client.rest.post(Routes19.userMeChannels(), {
4252
+ const data = await this.client.rest.post(Routes20.userMeChannels(), {
3369
4253
  body: { recipient_id: this.id },
3370
4254
  auth: true
3371
4255
  });
@@ -3442,14 +4326,14 @@ function resolveCacheLimits(input) {
3442
4326
  }
3443
4327
 
3444
4328
  // src/ClientCore/ClientEmoji.ts
3445
- import { Collection as Collection6 } from "@fluxerjs/collection";
3446
- import { Routes as Routes20 } from "@fluxerjs/types";
3447
- import { formatEmoji, getUnicodeFromShortcode, parseEmoji as parseEmoji2 } from "@fluxerjs/util";
4329
+ import { Collection as Collection8 } from "@fluxerjs/collection";
4330
+ import { Routes as Routes21 } from "@fluxerjs/types";
4331
+ import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
3448
4332
  async function resolveClientEmoji(client, emoji, guildId) {
3449
4333
  if (typeof emoji === "object" && emoji.id) {
3450
4334
  return formatEmoji({ name: emoji.name, id: emoji.id, animated: emoji.animated });
3451
4335
  }
3452
- const parsed = parseEmoji2(
4336
+ const parsed = parseEmoji(
3453
4337
  typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
3454
4338
  );
3455
4339
  if (!parsed) {
@@ -3462,7 +4346,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
3462
4346
  const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
3463
4347
  if (unicodeFromShortcode) return unicodeFromShortcode;
3464
4348
  if (guildId) {
3465
- const emojis = await client.rest.get(Routes20.guildEmojis(guildId));
4349
+ const emojis = await client.rest.get(Routes21.guildEmojis(guildId));
3466
4350
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
3467
4351
  if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
3468
4352
  throw new FluxerError(
@@ -3479,28 +4363,31 @@ async function resolveClientEmoji(client, emoji, guildId) {
3479
4363
  return parsed.name;
3480
4364
  }
3481
4365
  async function fetchInstance(client) {
3482
- const raw = await client.rest.get(Routes20.instanceDiscovery(), { auth: false });
4366
+ const raw = await client.rest.get(Routes21.instanceDiscovery(), { auth: false });
3483
4367
  return parseInstanceDiscovery(raw);
3484
4368
  }
3485
4369
  function fetchGatewayInfo(client) {
3486
- return client.rest.get(Routes20.gatewayBot());
4370
+ return client.rest.get(Routes21.gatewayBot());
3487
4371
  }
3488
4372
  function fetchEmojiMetadata(client, emojiId) {
3489
- return client.rest.get(Routes20.emojiMetadata(emojiId), { auth: true });
4373
+ return client.rest.get(Routes21.emojiMetadata(emojiId), { auth: true });
3490
4374
  }
3491
4375
  function fetchStickerMetadata(client, stickerId) {
3492
- return client.rest.get(Routes20.stickerMetadata(stickerId), { auth: true });
4376
+ return client.rest.get(Routes21.stickerMetadata(stickerId), { auth: true });
3493
4377
  }
3494
4378
  function fetchApplication(client) {
3495
- return client.rest.get(Routes20.applicationsMe(), { auth: true });
4379
+ return client.rest.get(Routes21.applicationsMe(), { auth: true });
3496
4380
  }
3497
4381
  async function fetchOAuthApplications(client) {
3498
- const data = await client.rest.get(Routes20.oauth2ApplicationsMe(), { auth: true });
3499
- return Array.isArray(data) ? data : data.applications ?? [];
3500
- }
3501
- function checkUsernameTag(client, username, discriminator) {
3502
- const params = new URLSearchParams({ username, discriminator });
3503
- return client.rest.get(`${Routes20.checkUsernameTag()}?${params}`, { auth: true });
4382
+ const data = await client.rest.get(Routes21.oauth2ApplicationsMe(), { auth: true });
4383
+ if (Array.isArray(data)) return data;
4384
+ if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
4385
+ return data.applications;
4386
+ }
4387
+ if (data && typeof data === "object" && "id" in data && typeof data.id === "string") {
4388
+ return [data];
4389
+ }
4390
+ return [];
3504
4391
  }
3505
4392
  function assertChannelIdBatch(name, channelIds) {
3506
4393
  if (channelIds.length < 1 || channelIds.length > 100) {
@@ -3511,14 +4398,14 @@ function assertChannelIdBatch(name, channelIds) {
3511
4398
  }
3512
4399
  function preloadMessages(client, channelIds) {
3513
4400
  assertChannelIdBatch("preloadMessages", channelIds);
3514
- return client.rest.post(Routes20.preloadMessages(), {
4401
+ return client.rest.post(Routes21.preloadMessages(), {
3515
4402
  body: { channels: channelIds },
3516
4403
  auth: true
3517
4404
  });
3518
4405
  }
3519
4406
  function preloadMessagesAlt(client, channelIds) {
3520
4407
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
3521
- return client.rest.post(Routes20.preloadMessagesAlt(), {
4408
+ return client.rest.post(Routes21.preloadMessagesAlt(), {
3522
4409
  body: { channels: channelIds },
3523
4410
  auth: true
3524
4411
  });
@@ -3526,14 +4413,14 @@ function preloadMessagesAlt(client, channelIds) {
3526
4413
  async function bulkFetchMessages(client, requests, options = {}) {
3527
4414
  validateBulkMessageFetchRequests(requests);
3528
4415
  const wire = toBulkFetchWire(requests);
3529
- const data = await client.rest.post(Routes20.channelsMessagesBulk(), {
4416
+ const data = await client.rest.post(Routes21.channelsMessagesBulk(), {
3530
4417
  body: { requests: wire },
3531
4418
  auth: true
3532
4419
  });
3533
4420
  if (options.hydrate === false) return data;
3534
4421
  return {
3535
4422
  channels: data.channels.map((entry) => {
3536
- const collection = new Collection6();
4423
+ const collection = new Collection8();
3537
4424
  for (const msg of entry.messages) {
3538
4425
  client._addMessageToCache(entry.channel_id, msg);
3539
4426
  collection.set(msg.id, new Message(client, msg));
@@ -3542,6 +4429,13 @@ async function bulkFetchMessages(client, requests, options = {}) {
3542
4429
  })
3543
4430
  };
3544
4431
  }
4432
+ async function searchMessages(client, options = {}) {
4433
+ const data = await client.rest.post(Routes21.searchMessages(), {
4434
+ body: toMessageSearchBody(options),
4435
+ auth: true
4436
+ });
4437
+ return toMessageSearchResponse(data);
4438
+ }
3545
4439
 
3546
4440
  // src/ClientCore/ClientEvents.ts
3547
4441
  function createEventMethods(client) {
@@ -3557,16 +4451,16 @@ function createEventMethods(client) {
3557
4451
  }
3558
4452
 
3559
4453
  // src/ClientCore/GatewayReady.ts
3560
- import { WebSocketManager } from "@fluxerjs/ws";
4454
+ import { GatewayCloseCodes, WebSocketManager } from "@fluxerjs/ws";
3561
4455
 
3562
4456
  // src/Domain/Guild/Guild.ts
3563
- import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4457
+ import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
3564
4458
  import { GuildNSFWLevel } from "@fluxerjs/types";
3565
- import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
4459
+ import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
3566
4460
 
3567
4461
  // src/ClientCore/GuildMemberManager.ts
3568
4462
  import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
3569
- import { Routes as Routes21 } from "@fluxerjs/types";
4463
+ import { Routes as Routes22 } from "@fluxerjs/types";
3570
4464
  var GuildMemberManager = class extends LimitedCollection2 {
3571
4465
  constructor(guild) {
3572
4466
  super({ maxSize: guild.client.cache.limits.members });
@@ -3583,7 +4477,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
3583
4477
  * console.log(member.displayName);
3584
4478
  */
3585
4479
  async resolve(userId) {
3586
- return this.get(userId) ?? this.guild.fetchMember(userId);
4480
+ return this.get(userId) ?? this.fetch(userId);
3587
4481
  }
3588
4482
  /**
3589
4483
  * The current bot user as a GuildMember in this guild.
@@ -3610,17 +4504,20 @@ var GuildMemberManager = class extends LimitedCollection2 {
3610
4504
  async fetchMe() {
3611
4505
  return this.guild.fetchMe();
3612
4506
  }
3613
- /**
3614
- * Fetch guild members with pagination. GET /guilds/{id}/members.
3615
- * @param options - limit (1-1000), after (user ID for pagination)
3616
- * @returns Array of GuildMember objects (cached in guild.members)
3617
- */
3618
- async fetch(options) {
4507
+ async fetch(userIdOrOptions, options) {
4508
+ if (typeof userIdOrOptions === "string") {
4509
+ const cached = this.get(userIdOrOptions);
4510
+ if (cached && !options?.force) return cached;
4511
+ return this.guild.fetchMember(userIdOrOptions);
4512
+ }
4513
+ return this.fetchMany(userIdOrOptions);
4514
+ }
4515
+ async fetchMany(options) {
3619
4516
  const params = new URLSearchParams();
3620
4517
  if (options?.limit != null) params.set("limit", String(options.limit));
3621
4518
  if (options?.after) params.set("after", options.after);
3622
4519
  const qs2 = params.toString();
3623
- const url = Routes21.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
4520
+ const url = Routes22.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
3624
4521
  const data = await this.guild.client.rest.get(url, { auth: true });
3625
4522
  const members = [];
3626
4523
  for (const m of data) {
@@ -3643,7 +4540,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
3643
4540
  */
3644
4541
  async search(options = {}) {
3645
4542
  const data = await this.guild.client.rest.post(
3646
- Routes21.guildMembersSearch(this.guild.id),
4543
+ Routes22.guildMembersSearch(this.guild.id),
3647
4544
  { body: toMemberSearchBody(options), auth: true }
3648
4545
  );
3649
4546
  const offset = options.offset ?? 0;
@@ -3669,7 +4566,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
3669
4566
  };
3670
4567
 
3671
4568
  // src/Domain/Guild/Admin.ts
3672
- import { Routes as Routes22 } from "@fluxerjs/types";
4569
+ import { Routes as Routes23 } from "@fluxerjs/types";
3673
4570
  function toAuditLogEntryPayload(entry, guildId) {
3674
4571
  return {
3675
4572
  id: entry.id,
@@ -3690,7 +4587,7 @@ function toVanityPayload(data) {
3690
4587
  return { code: data.code ?? null, uses: data.uses };
3691
4588
  }
3692
4589
  async function fetchAuditLogs(guild, options) {
3693
- const url = Routes22.guildAuditLogs(guild.id) + qs({
4590
+ const url = Routes23.guildAuditLogs(guild.id) + qs({
3694
4591
  limit: options?.limit,
3695
4592
  before: options?.before,
3696
4593
  after: options?.after,
@@ -3714,7 +4611,7 @@ async function fetchAuditLogs(guild, options) {
3714
4611
  };
3715
4612
  }
3716
4613
  async function editGuild(guild, options) {
3717
- const data = await guild.client.rest.patch(Routes22.guild(guild.id), {
4614
+ const data = await guild.client.rest.patch(Routes23.guild(guild.id), {
3718
4615
  body: toGuildEditBody(options),
3719
4616
  auth: true
3720
4617
  });
@@ -3722,13 +4619,13 @@ async function editGuild(guild, options) {
3722
4619
  return guild;
3723
4620
  }
3724
4621
  async function fetchVanityURL(guild) {
3725
- const data = await guild.client.rest.get(Routes22.guildVanityUrl(guild.id), {
4622
+ const data = await guild.client.rest.get(Routes23.guildVanityUrl(guild.id), {
3726
4623
  auth: true
3727
4624
  });
3728
4625
  return toVanityPayload(data);
3729
4626
  }
3730
4627
  async function editVanityURL(guild, code) {
3731
- const data = await guild.client.rest.patch(Routes22.guildVanityUrl(guild.id), {
4628
+ const data = await guild.client.rest.patch(Routes23.guildVanityUrl(guild.id), {
3732
4629
  body: { code },
3733
4630
  auth: true
3734
4631
  });
@@ -3736,14 +4633,14 @@ async function editVanityURL(guild, code) {
3736
4633
  return toVanityPayload(data);
3737
4634
  }
3738
4635
  async function fetchDiscoveryStatus(guild) {
3739
- const data = await guild.client.rest.get(Routes22.guildDiscovery(guild.id), {
4636
+ const data = await guild.client.rest.get(Routes23.guildDiscovery(guild.id), {
3740
4637
  auth: true
3741
4638
  });
3742
4639
  return toDiscoveryStatusPayload(data);
3743
4640
  }
3744
4641
  async function applyForDiscovery(guild, options) {
3745
4642
  const data = await guild.client.rest.post(
3746
- Routes22.guildDiscovery(guild.id),
4643
+ Routes23.guildDiscovery(guild.id),
3747
4644
  {
3748
4645
  body: toDiscoveryBody(options),
3749
4646
  auth: true
@@ -3753,7 +4650,7 @@ async function applyForDiscovery(guild, options) {
3753
4650
  }
3754
4651
  async function editDiscoveryApplication(guild, options) {
3755
4652
  const data = await guild.client.rest.patch(
3756
- Routes22.guildDiscovery(guild.id),
4653
+ Routes23.guildDiscovery(guild.id),
3757
4654
  {
3758
4655
  body: toDiscoveryBody(options),
3759
4656
  auth: true
@@ -3762,34 +4659,34 @@ async function editDiscoveryApplication(guild, options) {
3762
4659
  return toDiscoveryApplicationPayload(data);
3763
4660
  }
3764
4661
  async function withdrawDiscoveryApplication(guild) {
3765
- await guild.client.rest.delete(Routes22.guildDiscovery(guild.id), { auth: true });
4662
+ await guild.client.rest.delete(Routes23.guildDiscovery(guild.id), { auth: true });
3766
4663
  }
3767
4664
  async function deleteGuild(guild, options) {
3768
4665
  const body = options ? toSudoBody(options) : {};
3769
- await guild.client.rest.post(Routes22.guildDelete(guild.id), {
4666
+ await guild.client.rest.post(Routes23.guildDelete(guild.id), {
3770
4667
  body,
3771
4668
  auth: true
3772
4669
  });
3773
4670
  guild.client.guilds.delete(guild.id);
3774
4671
  }
3775
4672
  async function transferOwnership(guild, newOwnerId, password) {
3776
- await guild.client.rest.post(Routes22.guildTransferOwnership(guild.id), {
4673
+ await guild.client.rest.post(Routes23.guildTransferOwnership(guild.id), {
3777
4674
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
3778
4675
  auth: true
3779
4676
  });
3780
4677
  }
3781
4678
 
3782
4679
  // src/Domain/Guild/Channels.ts
3783
- import { Routes as Routes23 } from "@fluxerjs/types";
3784
- async function createChannel(guild, data) {
3785
- const created = await guild.client.rest.post(Routes23.guildChannels(guild.id), {
3786
- body: data,
4680
+ import { Routes as Routes24 } from "@fluxerjs/types";
4681
+ async function createChannel(guild, options) {
4682
+ const created = await guild.client.rest.post(Routes24.guildChannels(guild.id), {
4683
+ body: toChannelCreateBody(options),
3787
4684
  auth: true
3788
4685
  });
3789
4686
  return cacheChannel(guild, created);
3790
4687
  }
3791
4688
  async function fetchChannels(guild) {
3792
- const data = await guild.client.rest.get(Routes23.guildChannels(guild.id));
4689
+ const data = await guild.client.rest.get(Routes24.guildChannels(guild.id));
3793
4690
  const channels = [];
3794
4691
  for (const ch of data) {
3795
4692
  const channel = cacheChannel(guild, ch);
@@ -3798,17 +4695,17 @@ async function fetchChannels(guild) {
3798
4695
  return channels;
3799
4696
  }
3800
4697
  async function setChannelPositions(guild, updates) {
3801
- await guild.client.rest.patch(Routes23.guildChannels(guild.id), {
4698
+ await guild.client.rest.patch(Routes24.guildChannels(guild.id), {
3802
4699
  body: toChannelPositionBody(updates),
3803
4700
  auth: true
3804
4701
  });
3805
4702
  }
3806
4703
  async function fetchWebhooks(guild) {
3807
- const data = await guild.client.rest.get(Routes23.guildWebhooks(guild.id));
4704
+ const data = await guild.client.rest.get(Routes24.guildWebhooks(guild.id));
3808
4705
  return data.map((w) => new Webhook(guild.client, w));
3809
4706
  }
3810
4707
  async function fetchInvites(guild) {
3811
- const data = await guild.client.rest.get(Routes23.guildInvites(guild.id));
4708
+ const data = await guild.client.rest.get(Routes24.guildInvites(guild.id));
3812
4709
  return data.map((invite) => new Invite(guild.client, invite));
3813
4710
  }
3814
4711
  async function fetchInvite(guild, codeOrUrl) {
@@ -3828,14 +4725,14 @@ function resolveGuildOnlineCount(data) {
3828
4725
  }
3829
4726
 
3830
4727
  // src/Domain/Guild/Emojis.ts
3831
- import { Routes as Routes24 } from "@fluxerjs/types";
4728
+ import { Routes as Routes25 } from "@fluxerjs/types";
3832
4729
  async function fetchEmojis(guild) {
3833
- const data = await guild.client.rest.get(Routes24.guildEmojis(guild.id));
4730
+ const data = await guild.client.rest.get(Routes25.guildEmojis(guild.id));
3834
4731
  return data.map((e) => cacheEmoji(guild, e));
3835
4732
  }
3836
4733
  async function fetchEmoji(guild, emojiId) {
3837
4734
  try {
3838
- const data = await guild.client.rest.get(Routes24.guildEmoji(guild.id, emojiId));
4735
+ const data = await guild.client.rest.get(Routes25.guildEmoji(guild.id, emojiId));
3839
4736
  return cacheEmoji(guild, data);
3840
4737
  } catch (err) {
3841
4738
  rethrowMapped(err, {
@@ -3845,14 +4742,14 @@ async function fetchEmoji(guild, emojiId) {
3845
4742
  }
3846
4743
  }
3847
4744
  async function createEmoji(guild, options) {
3848
- const data = await guild.client.rest.post(Routes24.guildEmojis(guild.id), {
4745
+ const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
3849
4746
  body: options,
3850
4747
  auth: true
3851
4748
  });
3852
4749
  return cacheEmoji(guild, data);
3853
4750
  }
3854
4751
  async function cloneEmoji(guild, sourceEmojiId) {
3855
- const data = await guild.client.rest.post(Routes24.guildEmojisClone(guild.id), {
4752
+ const data = await guild.client.rest.post(Routes25.guildEmojisClone(guild.id), {
3856
4753
  body: { source_emoji_id: sourceEmojiId },
3857
4754
  auth: true
3858
4755
  });
@@ -3860,18 +4757,18 @@ async function cloneEmoji(guild, sourceEmojiId) {
3860
4757
  }
3861
4758
  async function createEmojisBulk(guild, emojis) {
3862
4759
  const data = await guild.client.rest.post(
3863
- Routes24.guildEmojisBulk(guild.id),
4760
+ Routes25.guildEmojisBulk(guild.id),
3864
4761
  { body: { emojis }, auth: true }
3865
4762
  );
3866
4763
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
3867
4764
  }
3868
4765
 
3869
4766
  // src/Domain/Guild/MemberHttp.ts
3870
- import { Routes as Routes25 } from "@fluxerjs/types";
4767
+ import { Routes as Routes26 } from "@fluxerjs/types";
3871
4768
  async function fetchMember(guild, userId) {
3872
4769
  try {
3873
4770
  const data = await guild.client.rest.get(
3874
- Routes25.guildMember(guild.id, userId)
4771
+ Routes26.guildMember(guild.id, userId)
3875
4772
  );
3876
4773
  return cacheMember(guild, data);
3877
4774
  } catch (err) {
@@ -3886,23 +4783,28 @@ async function fetchMember(guild, userId) {
3886
4783
  }
3887
4784
  async function fetchMe(guild) {
3888
4785
  const data = await guild.client.rest.get(
3889
- Routes25.guildMemberMe(guild.id),
4786
+ Routes26.guildMemberMe(guild.id),
3890
4787
  { auth: true }
3891
4788
  );
3892
4789
  return cacheMember(guild, data);
3893
4790
  }
3894
4791
 
3895
4792
  // src/Domain/Guild/Moderation.ts
3896
- import { Routes as Routes27 } from "@fluxerjs/types";
4793
+ import { Routes as Routes28 } from "@fluxerjs/types";
3897
4794
 
3898
4795
  // src/Domain/Guild/GuildBan.ts
3899
- import { Routes as Routes26 } from "@fluxerjs/types";
4796
+ import { Routes as Routes27 } from "@fluxerjs/types";
4797
+ function parseOptionalDate2(value) {
4798
+ if (value == null || value === "") return null;
4799
+ const date = new Date(value);
4800
+ return Number.isNaN(date.getTime()) ? null : date;
4801
+ }
3900
4802
  var GuildBan = class extends Base {
3901
4803
  client;
3902
4804
  guildId;
3903
4805
  user;
3904
4806
  reason;
3905
- /** ISO timestamp when a temporary ban expires. Null for permanent bans. */
4807
+ /** When a temporary ban expires. Null for permanent bans. */
3906
4808
  expiresAt;
3907
4809
  /** @param data - API ban from GET /guilds/{id}/bans or gateway GUILD_BAN_ADD */
3908
4810
  constructor(client, data, guildId) {
@@ -3911,14 +4813,14 @@ var GuildBan = class extends Base {
3911
4813
  this.guildId = data.guild_id ?? guildId;
3912
4814
  this.user = client.getOrCreateUser(data.user);
3913
4815
  this.reason = data.reason ?? null;
3914
- this.expiresAt = data.expires_at ?? null;
4816
+ this.expiresAt = parseOptionalDate2(data.expires_at);
3915
4817
  }
3916
4818
  /**
3917
4819
  * Remove this ban (unban the user).
3918
4820
  * Requires Ban Members permission.
3919
4821
  */
3920
4822
  async unban() {
3921
- await this.client.rest.delete(Routes26.guildBan(this.guildId, this.user.id), {
4823
+ await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
3922
4824
  auth: true
3923
4825
  });
3924
4826
  }
@@ -3927,40 +4829,53 @@ var GuildBan = class extends Base {
3927
4829
  // src/Domain/Guild/Moderation.ts
3928
4830
  async function ban(guild, userId, options) {
3929
4831
  const body = options ? toGuildBanBody(options) : {};
3930
- await guild.client.rest.put(Routes27.guildBan(guild.id, userId), {
4832
+ await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
3931
4833
  body: Object.keys(body).length ? body : void 0,
3932
4834
  auth: true
3933
4835
  });
3934
4836
  }
3935
4837
  async function fetchBans(guild) {
3936
- const data = await guild.client.rest.get(Routes27.guildBans(guild.id));
4838
+ const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
3937
4839
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
3938
4840
  }
3939
4841
  async function unban(guild, userId) {
3940
- await guild.client.rest.delete(Routes27.guildBan(guild.id, userId), { auth: true });
4842
+ await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), { auth: true });
3941
4843
  }
3942
4844
  async function kick(guild, userId) {
3943
- await guild.client.rest.delete(Routes27.guildMember(guild.id, userId), { auth: true });
4845
+ await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), { auth: true });
3944
4846
  }
3945
4847
 
4848
+ // src/Domain/Guild/GuildRoleManager.ts
4849
+ import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4850
+ var GuildRoleManager = class extends LimitedCollection3 {
4851
+ constructor(guildId, options) {
4852
+ super(options);
4853
+ this.guildId = guildId;
4854
+ }
4855
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4856
+ get everyone() {
4857
+ return this.get(this.guildId);
4858
+ }
4859
+ };
4860
+
3946
4861
  // src/Domain/Guild/Roles.ts
3947
- import { Routes as Routes28 } from "@fluxerjs/types";
4862
+ import { Routes as Routes29 } from "@fluxerjs/types";
3948
4863
  import { parseRoleMention } from "@fluxerjs/util";
3949
4864
  async function createRole(guild, options = {}) {
3950
- const body = toRoleRequestBody(options);
3951
- const data = await guild.client.rest.post(Routes28.guildRoles(guild.id), {
4865
+ const body = toRoleCreateBody(options);
4866
+ const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
3952
4867
  body: Object.keys(body).length ? body : void 0,
3953
4868
  auth: true
3954
4869
  });
3955
4870
  return cacheRole(guild, data);
3956
4871
  }
3957
4872
  async function fetchRoles(guild) {
3958
- const data = await guild.client.rest.get(Routes28.guildRoles(guild.id));
4873
+ const data = await guild.client.rest.get(Routes29.guildRoles(guild.id));
3959
4874
  return data.map((r) => cacheRole(guild, r));
3960
4875
  }
3961
4876
  async function fetchRole(guild, roleId2) {
3962
4877
  try {
3963
- const data = await guild.client.rest.get(Routes28.guildRole(guild.id, roleId2));
4878
+ const data = await guild.client.rest.get(Routes29.guildRole(guild.id, roleId2));
3964
4879
  return cacheRole(guild, data);
3965
4880
  } catch (err) {
3966
4881
  rethrowMapped(err, {
@@ -3977,7 +4892,7 @@ async function resolveRoleId(guild, arg) {
3977
4892
  const needle = trimmed.toLowerCase();
3978
4893
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
3979
4894
  if (cached) return cached.id;
3980
- const roles = await guild.client.rest.get(Routes28.guildRoles(guild.id));
4895
+ const roles = await guild.client.rest.get(Routes29.guildRoles(guild.id));
3981
4896
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
3982
4897
  if (!role) return null;
3983
4898
  cacheRole(guild, role);
@@ -3986,7 +4901,7 @@ async function resolveRoleId(guild, arg) {
3986
4901
  async function setRolePositions(guild, updates) {
3987
4902
  return replaceRoles(
3988
4903
  guild,
3989
- await guild.client.rest.patch(Routes28.guildRoles(guild.id), {
4904
+ await guild.client.rest.patch(Routes29.guildRoles(guild.id), {
3990
4905
  body: updates,
3991
4906
  auth: true
3992
4907
  })
@@ -3995,7 +4910,7 @@ async function setRolePositions(guild, updates) {
3995
4910
  async function setRoleHoistPositions(guild, updates) {
3996
4911
  return replaceRoles(
3997
4912
  guild,
3998
- await guild.client.rest.patch(Routes28.guildRolesHoistPositions(guild.id), {
4913
+ await guild.client.rest.patch(Routes29.guildRolesHoistPositions(guild.id), {
3999
4914
  body: updates.map((u) => ({
4000
4915
  id: u.id,
4001
4916
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -4007,23 +4922,23 @@ async function setRoleHoistPositions(guild, updates) {
4007
4922
  async function resetRoleHoistPositions(guild) {
4008
4923
  return replaceRoles(
4009
4924
  guild,
4010
- await guild.client.rest.delete(Routes28.guildRolesHoistPositions(guild.id), {
4925
+ await guild.client.rest.delete(Routes29.guildRolesHoistPositions(guild.id), {
4011
4926
  auth: true
4012
4927
  })
4013
4928
  );
4014
4929
  }
4015
4930
 
4016
4931
  // src/Domain/Guild/Stickers.ts
4017
- import { Routes as Routes29 } from "@fluxerjs/types";
4932
+ import { Routes as Routes30 } from "@fluxerjs/types";
4018
4933
  async function createSticker(guild, options) {
4019
- const data = await guild.client.rest.post(Routes29.guildStickers(guild.id), {
4934
+ const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
4020
4935
  body: options,
4021
4936
  auth: true
4022
4937
  });
4023
4938
  return cacheSticker(guild, data);
4024
4939
  }
4025
4940
  async function cloneSticker(guild, sourceStickerId) {
4026
- const data = await guild.client.rest.post(Routes29.guildStickersClone(guild.id), {
4941
+ const data = await guild.client.rest.post(Routes30.guildStickersClone(guild.id), {
4027
4942
  body: { source_sticker_id: sourceStickerId },
4028
4943
  auth: true
4029
4944
  });
@@ -4031,17 +4946,17 @@ async function cloneSticker(guild, sourceStickerId) {
4031
4946
  }
4032
4947
  async function createStickersBulk(guild, stickers) {
4033
4948
  const data = await guild.client.rest.post(
4034
- Routes29.guildStickersBulk(guild.id),
4949
+ Routes30.guildStickersBulk(guild.id),
4035
4950
  { body: { stickers }, auth: true }
4036
4951
  );
4037
4952
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
4038
4953
  }
4039
4954
  async function fetchStickers(guild) {
4040
- const data = await guild.client.rest.get(Routes29.guildStickers(guild.id));
4955
+ const data = await guild.client.rest.get(Routes30.guildStickers(guild.id));
4041
4956
  return data.map((s) => cacheSticker(guild, s));
4042
4957
  }
4043
4958
  async function fetchSticker(guild, stickerId) {
4044
- const data = await guild.client.rest.get(Routes29.guildSticker(guild.id, stickerId));
4959
+ const data = await guild.client.rest.get(Routes30.guildSticker(guild.id, stickerId));
4045
4960
  return cacheSticker(guild, data);
4046
4961
  }
4047
4962
 
@@ -4081,8 +4996,26 @@ var Guild = class extends Base {
4081
4996
  systemChannelId;
4082
4997
  /** Rules channel ID (for Community guilds), or null if none. */
4083
4998
  rulesChannelId;
4999
+ /** {@link SystemChannelFlags} bitfield. */
5000
+ systemChannelFlags;
5001
+ /** Splash card alignment. */
5002
+ splashCardAlignment;
5003
+ /** Embed splash hash. */
5004
+ embedSplash;
4084
5005
  /** NSFW level for this guild. */
4085
5006
  nsfwLevel;
5007
+ /** Whether the guild is marked as adult (18+) content. */
5008
+ nsfw;
5009
+ /** Content warning level. */
5010
+ contentWarningLevel;
5011
+ /** Custom guild-wide content warning text. */
5012
+ contentWarningText;
5013
+ /** {@link GuildOperations} bitfield of disabled operations. */
5014
+ disabledOperations;
5015
+ /** ISO-8601 timestamp before which message history is not available. */
5016
+ messageHistoryCutoff;
5017
+ /** Permissions for the current member in this guild (bitfield string). */
5018
+ permissions;
4086
5019
  /** MFA level required for moderation actions. */
4087
5020
  mfaLevel;
4088
5021
  /** Banner width in pixels. */
@@ -4116,13 +5049,13 @@ var Guild = class extends Base {
4116
5049
  this.client = client;
4117
5050
  this.id = data.id;
4118
5051
  this.members = new GuildMemberManager(this);
4119
- this.channels = new LimitedCollection3({
5052
+ this.channels = new LimitedCollection4({
4120
5053
  maxSize: Number.POSITIVE_INFINITY,
4121
5054
  onEvict: (_id, channel) => client.cache.cascadeChannel(channel, "guild")
4122
5055
  });
4123
- this.roles = new LimitedCollection3({ maxSize: client.cache.limits.roles });
4124
- this.emojis = new LimitedCollection3({ maxSize: client.cache.limits.emojis });
4125
- this.stickers = new LimitedCollection3({ maxSize: client.cache.limits.stickers });
5056
+ this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
5057
+ this.emojis = new LimitedCollection4({ maxSize: client.cache.limits.emojis });
5058
+ this.stickers = new LimitedCollection4({ maxSize: client.cache.limits.stickers });
4126
5059
  this.name = data.name ?? "";
4127
5060
  this.icon = data.icon ?? null;
4128
5061
  this.banner = data.banner ?? null;
@@ -4137,7 +5070,16 @@ var Guild = class extends Base {
4137
5070
  this.afkTimeout = data.afk_timeout ?? 0;
4138
5071
  this.systemChannelId = data.system_channel_id ?? null;
4139
5072
  this.rulesChannelId = data.rules_channel_id ?? null;
5073
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5074
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5075
+ this.embedSplash = data.embed_splash ?? null;
4140
5076
  this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
5077
+ this.nsfw = data.nsfw ?? false;
5078
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5079
+ this.contentWarningText = data.content_warning_text ?? null;
5080
+ this.disabledOperations = data.disabled_operations ?? 0;
5081
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5082
+ this.permissions = data.permissions ?? null;
4141
5083
  this.mfaLevel = data.mfa_level ?? 0;
4142
5084
  this.bannerWidth = data.banner_width ?? null;
4143
5085
  this.bannerHeight = data.banner_height ?? null;
@@ -4172,7 +5114,28 @@ var Guild = class extends Base {
4172
5114
  if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
4173
5115
  if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
4174
5116
  if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
5117
+ if (data.system_channel_flags !== void 0) {
5118
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5119
+ }
5120
+ if (data.splash_card_alignment !== void 0) {
5121
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5122
+ }
5123
+ if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
4175
5124
  if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
5125
+ if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
5126
+ if (data.content_warning_level !== void 0) {
5127
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5128
+ }
5129
+ if (data.content_warning_text !== void 0) {
5130
+ this.contentWarningText = data.content_warning_text ?? null;
5131
+ }
5132
+ if (data.disabled_operations !== void 0) {
5133
+ this.disabledOperations = data.disabled_operations ?? 0;
5134
+ }
5135
+ if (data.message_history_cutoff !== void 0) {
5136
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5137
+ }
5138
+ if (data.permissions !== void 0) this.permissions = data.permissions ?? null;
4176
5139
  if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
4177
5140
  if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
4178
5141
  if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
@@ -4193,11 +5156,11 @@ var Guild = class extends Base {
4193
5156
  }
4194
5157
  /** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
4195
5158
  get createdTimestamp() {
4196
- return SnowflakeUtil7.timestampFromSnowflake(this.id);
5159
+ return SnowflakeUtil9.timestampFromSnowflake(this.id);
4197
5160
  }
4198
5161
  /** Date when this guild was created, derived from its snowflake ID. */
4199
5162
  get createdAt() {
4200
- return SnowflakeUtil7.dateFromSnowflake(this.id);
5163
+ return SnowflakeUtil9.dateFromSnowflake(this.id);
4201
5164
  }
4202
5165
  /** The guild's name. */
4203
5166
  toString() {
@@ -4225,11 +5188,11 @@ var Guild = class extends Base {
4225
5188
  });
4226
5189
  }
4227
5190
  /**
4228
- * Create a channel. `data.type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
5191
+ * Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
4229
5192
  * Requires Manage Channels.
4230
5193
  */
4231
- createChannel(data) {
4232
- return createChannel(this, data);
5194
+ createChannel(options) {
5195
+ return createChannel(this, options);
4233
5196
  }
4234
5197
  /** Fetch all channels in this guild from the API. */
4235
5198
  fetchChannels() {
@@ -4291,7 +5254,7 @@ var Guild = class extends Base {
4291
5254
  resetRoleHoistPositions() {
4292
5255
  return resetRoleHoistPositions(this);
4293
5256
  }
4294
- /** Ban a user from the guild. Requires Ban Members. `ban_duration_seconds`: 0 = permanent. */
5257
+ /** Ban a user from the guild. Requires Ban Members. `banDurationSeconds`: 0 = permanent. */
4295
5258
  ban(userId, options) {
4296
5259
  return ban(this, userId, options);
4297
5260
  }
@@ -4491,23 +5454,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
4491
5454
  }
4492
5455
 
4493
5456
  // src/ClientCore/ClientUser.ts
4494
- import { GatewayOpcodes, Routes as Routes30 } from "@fluxerjs/types";
5457
+ import { GatewayOpcodes, Routes as Routes31 } from "@fluxerjs/types";
4495
5458
  var ClientUser = class extends User {
4496
5459
  /** Broadcast presence (gateway opcode 3) on all shards. */
4497
5460
  setPresence(presence) {
5461
+ this.client.options.presence = presence;
4498
5462
  const wire = toPresenceWire(presence);
4499
- this.client.options.presence = wire;
4500
5463
  this.client._sendToAllShards({ op: GatewayOpcodes.PresenceUpdate, d: wire });
4501
5464
  }
4502
5465
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
4503
5466
  async fetch() {
4504
- const data = await this.client.rest.get(Routes30.currentUser(), { auth: true });
5467
+ const data = await this.client.rest.get(Routes31.currentUser(), { auth: true });
4505
5468
  this._patch(data);
4506
5469
  return this;
4507
5470
  }
4508
5471
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
4509
5472
  async fetchGuilds(options) {
4510
- const path = Routes30.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
5473
+ const path = Routes31.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
4511
5474
  const data = await this.client.rest.get(path, { auth: true });
4512
5475
  return data.map((g) => ({
4513
5476
  id: g.id,
@@ -4520,10 +5483,18 @@ var ClientUser = class extends User {
4520
5483
  ...g.approximate_presence_count !== void 0 ? { approximatePresenceCount: g.approximate_presence_count } : {}
4521
5484
  }));
4522
5485
  }
4523
- /** DELETE /users/@me/guilds/{guild_id} */
5486
+ /**
5487
+ * Leave a guild (`client.user.leaveGuild`).
5488
+ * DELETE /users/@me/guilds/{guild_id}.
5489
+ *
5490
+ * @param guildId - Guild to leave
5491
+ * @param options - Optional sudo / MFA body for user accounts
5492
+ * @example
5493
+ * await client.user.leaveGuild(guildId);
5494
+ */
4524
5495
  async leaveGuild(guildId, options) {
4525
5496
  const body = options ? toSudoBody(options) : void 0;
4526
- await this.client.rest.delete(Routes30.leaveGuild(guildId), {
5497
+ await this.client.rest.delete(Routes31.leaveGuild(guildId), {
4527
5498
  body: body && Object.keys(body).length ? body : void 0,
4528
5499
  auth: true
4529
5500
  });
@@ -4531,7 +5502,7 @@ var ClientUser = class extends User {
4531
5502
  /** Delete every message authored by the caller across a guild (sudo). */
4532
5503
  async bulkDeleteMyMessagesInGuild(guildId, options) {
4533
5504
  const body = options ? toSudoBody(options) : void 0;
4534
- await this.client.rest.post(Routes30.guildBulkDeleteMine(guildId), {
5505
+ await this.client.rest.post(Routes31.guildBulkDeleteMine(guildId), {
4535
5506
  body: body && Object.keys(body).length ? body : void 0,
4536
5507
  auth: true
4537
5508
  });
@@ -4698,7 +5669,7 @@ var guildResourceHandlers = {
4698
5669
  role = new Role(client, data.role, data.guild_id);
4699
5670
  guild?.roles.set(role.id, role);
4700
5671
  }
4701
- client.emit(Events.GuildRoleUpdate, { role, oldRole });
5672
+ client.emit(Events.GuildRoleUpdate, oldRole, role);
4702
5673
  },
4703
5674
  GUILD_ROLE_UPDATE_BULK(client, d) {
4704
5675
  const data = d;
@@ -4714,11 +5685,7 @@ var guildResourceHandlers = {
4714
5685
  const guild = client.guilds.get(data.guild_id);
4715
5686
  const role = guild?.roles.get(data.role_id) ?? null;
4716
5687
  guild?.roles.delete(data.role_id);
4717
- client.emit(Events.GuildRoleDelete, {
4718
- roleId: data.role_id,
4719
- guildId: data.guild_id,
4720
- role
4721
- });
5688
+ client.emit(Events.GuildRoleDelete, role, data.guild_id, data.role_id);
4722
5689
  },
4723
5690
  GUILD_BAN_ADD(client, d) {
4724
5691
  const data = d;
@@ -4827,7 +5794,7 @@ function normalizeInviteCreate(client, payload) {
4827
5794
  const code = str(raw?.code);
4828
5795
  if (!raw || !code) return null;
4829
5796
  const typeNum = num(raw.type);
4830
- const type = typeNum === InviteType2.GroupDM || typeNum === InviteType2.EmojiPack || typeNum === InviteType2.StickerPack ? typeNum : InviteType2.Guild;
5797
+ const type = typeNum === InviteType2.GroupDM ? InviteType2.GroupDM : InviteType2.Guild;
4831
5798
  const shared = {
4832
5799
  code,
4833
5800
  inviter: raw.inviter ?? null,
@@ -4839,11 +5806,6 @@ function normalizeInviteCreate(client, payload) {
4839
5806
  max_uses: num(raw.max_uses),
4840
5807
  max_age: num(raw.max_age)
4841
5808
  };
4842
- if (type === InviteType2.EmojiPack || type === InviteType2.StickerPack) {
4843
- const pack = asRecord(raw.pack);
4844
- if (!pack || !str(pack.id) || !str(pack.name)) return null;
4845
- return { ...shared, type, pack };
4846
- }
4847
5809
  const guildObj = asRecord(raw.guild);
4848
5810
  const channelObj = asRecord(raw.channel);
4849
5811
  const guildId = str(guildObj?.id) ?? str(raw.guild_id) ?? "0";
@@ -4895,6 +5857,30 @@ var inviteHandlers = {
4895
5857
  }
4896
5858
  };
4897
5859
 
5860
+ // src/Domain/Guild/PartialGuildMember.ts
5861
+ var PartialGuildMember = class {
5862
+ partial = true;
5863
+ client;
5864
+ id;
5865
+ user;
5866
+ guildId;
5867
+ guild;
5868
+ constructor(data) {
5869
+ this.client = data.client;
5870
+ this.id = data.id;
5871
+ this.user = data.user;
5872
+ this.guild = data.guild;
5873
+ this.guildId = data.guild.id;
5874
+ }
5875
+ /**
5876
+ * Fetch the full {@link GuildMember} from the API (cache-aware via `guild.members.fetch`).
5877
+ * @throws FluxerError with MEMBER_NOT_FOUND if the user is not in the guild
5878
+ */
5879
+ async fetch() {
5880
+ return this.guild.members.fetch(this.id);
5881
+ }
5882
+ };
5883
+
4898
5884
  // src/ClientCore/EventHandlers/Members.ts
4899
5885
  var memberHandlers = {
4900
5886
  GUILD_MEMBER_ADD(client, d) {
@@ -4921,28 +5907,15 @@ var memberHandlers = {
4921
5907
  const data = d;
4922
5908
  const guild = client.guilds.get(data.guild_id);
4923
5909
  if (!guild || !data.user?.id) return;
4924
- let member = guild.members.get(data.user.id);
4925
- if (member) {
4926
- guild.members.delete(data.user.id);
4927
- } else {
4928
- member = new GuildMember(
4929
- client,
4930
- {
4931
- user: {
4932
- ...unknownUser(data.user.id),
4933
- ...data.user,
4934
- username: data.user.username ?? "Unknown",
4935
- discriminator: data.user.discriminator ?? "0"
4936
- },
4937
- roles: [],
4938
- joined_at: (/* @__PURE__ */ new Date(0)).toISOString(),
4939
- nick: null,
4940
- mute: false,
4941
- deaf: false
4942
- },
4943
- guild
4944
- );
4945
- }
5910
+ const cached = guild.members.get(data.user.id);
5911
+ if (cached) guild.members.delete(data.user.id);
5912
+ const user = client.getOrCreateUser(data.user);
5913
+ const member = cached ?? new PartialGuildMember({
5914
+ client,
5915
+ id: data.user.id,
5916
+ user,
5917
+ guild
5918
+ });
4946
5919
  guild.adjustMemberCount(-1);
4947
5920
  client.emit(Events.GuildMemberRemove, member);
4948
5921
  },
@@ -4961,7 +5934,7 @@ var memberHandlers = {
4961
5934
  members,
4962
5935
  chunkIndex: data.chunk_index,
4963
5936
  chunkCount: data.chunk_count,
4964
- notFound: [],
5937
+ notFound: data.not_found ?? [],
4965
5938
  nonce: data.nonce ?? null
4966
5939
  };
4967
5940
  client.emit(Events.GuildMembersChunk, payload);
@@ -4969,7 +5942,35 @@ var memberHandlers = {
4969
5942
  };
4970
5943
 
4971
5944
  // src/ClientCore/EventHandlers/Messages.ts
4972
- function toReactionEmoji2(emoji) {
5945
+ import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
5946
+ function cachedTextChannel(client, channelId) {
5947
+ const channel = client.channels.get(channelId);
5948
+ return channel?.isTextBased() ? channel : null;
5949
+ }
5950
+ function cachedMessage(client, channelId, messageId) {
5951
+ const data = client._getMessageCache(channelId)?.get(messageId);
5952
+ return data ? new Message(client, data) : null;
5953
+ }
5954
+ function isHydratableMessage(data) {
5955
+ return Boolean(data.author?.id && data.timestamp);
5956
+ }
5957
+ function toPartialMessage(client, args) {
5958
+ const cached = args.cached;
5959
+ const authorId = args.authorId ?? cached?.author?.id ?? null;
5960
+ const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
5961
+ const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil10.isValid(args.id) ? SnowflakeUtil10.dateFromSnowflake(args.id) : null;
5962
+ return new PartialMessage(client, {
5963
+ id: args.id,
5964
+ channelId: args.channelId,
5965
+ guildId: args.guildId ?? cached?.guild_id ?? null,
5966
+ channel: cachedTextChannel(client, args.channelId),
5967
+ content: args.content ?? cached?.content ?? null,
5968
+ authorId,
5969
+ author,
5970
+ createdAt
5971
+ });
5972
+ }
5973
+ function toReactionEmoji(emoji) {
4973
5974
  return {
4974
5975
  name: emoji.name,
4975
5976
  ...emoji.id !== void 0 ? { id: emoji.id } : {},
@@ -4986,9 +5987,12 @@ function emitReaction(event) {
4986
5987
  const payload = {
4987
5988
  reaction,
4988
5989
  user,
5990
+ message: cachedMessage(client, data.channel_id, data.message_id),
5991
+ channel: cachedTextChannel(client, data.channel_id),
5992
+ member,
4989
5993
  messageId: data.message_id,
4990
5994
  channelId: data.channel_id,
4991
- emoji: toReactionEmoji2(data.emoji),
5995
+ emoji: toReactionEmoji(data.emoji),
4992
5996
  userId: data.user_id
4993
5997
  };
4994
5998
  client.emit(event, payload);
@@ -5008,37 +6012,60 @@ var messageHandlers = {
5008
6012
  },
5009
6013
  MESSAGE_UPDATE(client, d) {
5010
6014
  const partial = d;
5011
- const cache = client._getMessageCache(partial.channel_id);
5012
- let oldMessage = null;
5013
- let mergedData = partial;
5014
- if (cache) {
5015
- const oldData = cache.get(partial.id);
5016
- if (oldData) {
5017
- oldMessage = new Message(client, oldData);
5018
- mergedData = { ...oldData, ...partial };
5019
- }
6015
+ const oldData = client._getMessageCache(partial.channel_id)?.get(partial.id);
6016
+ const oldMessage = oldData ? new Message(client, oldData) : null;
6017
+ const mergedData = oldData ? { ...oldData, ...partial } : partial;
6018
+ if (isHydratableMessage(mergedData)) {
6019
+ client._addMessageToCache(partial.channel_id, mergedData);
6020
+ client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
6021
+ return;
5020
6022
  }
5021
- client._addMessageToCache(partial.channel_id, mergedData);
5022
- client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
6023
+ client.emit(
6024
+ Events.MessageUpdate,
6025
+ oldMessage,
6026
+ toPartialMessage(client, {
6027
+ id: partial.id,
6028
+ channelId: partial.channel_id,
6029
+ guildId: partial.guild_id ?? oldData?.guild_id ?? null,
6030
+ content: partial.content ?? oldData?.content ?? null,
6031
+ authorId: partial.author?.id ?? oldData?.author?.id ?? null,
6032
+ cached: oldData
6033
+ })
6034
+ );
5023
6035
  },
5024
6036
  MESSAGE_DELETE(client, d) {
5025
6037
  const data = d;
5026
- client._removeMessageFromCache(data.channel_id, data.id);
5027
- client.emit(Events.MessageDelete, {
6038
+ const cached = client._getMessageCache(data.channel_id)?.get(data.id);
6039
+ const payload = toPartialMessage(client, {
5028
6040
  id: data.id,
5029
6041
  channelId: data.channel_id,
5030
- channel: client.channels.get(data.channel_id) ?? null,
5031
- content: data.content ?? null,
5032
- authorId: data.author_id ?? null
6042
+ guildId: data.guild_id ?? cached?.guild_id ?? null,
6043
+ content: data.content ?? cached?.content ?? null,
6044
+ authorId: data.author_id ?? cached?.author?.id ?? null,
6045
+ cached
5033
6046
  });
6047
+ client._removeMessageFromCache(data.channel_id, data.id);
6048
+ client.emit(Events.MessageDelete, payload);
5034
6049
  },
5035
6050
  MESSAGE_DELETE_BULK(client, d) {
5036
6051
  const data = d;
5037
- for (const id of data.ids ?? []) client._removeMessageFromCache(data.channel_id, id);
6052
+ const ids = data.ids ?? [];
6053
+ const cache = client._getMessageCache(data.channel_id);
6054
+ const messages = ids.map(
6055
+ (id) => toPartialMessage(client, {
6056
+ id,
6057
+ channelId: data.channel_id,
6058
+ guildId: data.guild_id ?? cache?.get(id)?.guild_id ?? null,
6059
+ cached: cache?.get(id)
6060
+ })
6061
+ );
6062
+ for (const id of ids) client._removeMessageFromCache(data.channel_id, id);
5038
6063
  client.emit(Events.MessageDeleteBulk, {
5039
- ids: data.ids ?? [],
6064
+ ids,
5040
6065
  channelId: data.channel_id,
5041
- guildId: data.guild_id ?? null
6066
+ guildId: data.guild_id ?? null,
6067
+ channel: cachedTextChannel(client, data.channel_id),
6068
+ messages
5042
6069
  });
5043
6070
  },
5044
6071
  MESSAGE_REACTION_ADD: emitReaction(Events.MessageReactionAdd),
@@ -5048,7 +6075,9 @@ var messageHandlers = {
5048
6075
  const payload = {
5049
6076
  messageId: data.message_id,
5050
6077
  channelId: data.channel_id,
5051
- guildId: data.guild_id ?? null
6078
+ guildId: data.guild_id ?? null,
6079
+ message: cachedMessage(client, data.channel_id, data.message_id),
6080
+ channel: cachedTextChannel(client, data.channel_id)
5052
6081
  };
5053
6082
  client.emit(Events.MessageReactionRemoveAll, payload);
5054
6083
  },
@@ -5058,7 +6087,9 @@ var messageHandlers = {
5058
6087
  messageId: data.message_id,
5059
6088
  channelId: data.channel_id,
5060
6089
  guildId: data.guild_id ?? null,
5061
- emoji: toReactionEmoji2(data.emoji)
6090
+ emoji: toReactionEmoji(data.emoji),
6091
+ message: cachedMessage(client, data.channel_id, data.message_id),
6092
+ channel: cachedTextChannel(client, data.channel_id)
5062
6093
  };
5063
6094
  client.emit(Events.MessageReactionRemoveEmoji, payload);
5064
6095
  },
@@ -5077,7 +6108,7 @@ var messageHandlers = {
5077
6108
  }
5078
6109
  reactions.push({
5079
6110
  userId: entry.user_id,
5080
- emoji: toReactionEmoji2(entry.emoji),
6111
+ emoji: toReactionEmoji(entry.emoji),
5081
6112
  member
5082
6113
  });
5083
6114
  }
@@ -5085,6 +6116,8 @@ var messageHandlers = {
5085
6116
  channelId: data.channel_id,
5086
6117
  messageId: data.message_id,
5087
6118
  guildId: data.guild_id ?? null,
6119
+ message: cachedMessage(client, data.channel_id, data.message_id),
6120
+ channel: cachedTextChannel(client, data.channel_id),
5088
6121
  reactions
5089
6122
  };
5090
6123
  client.emit(Events.MessageReactionAddMany, payload);
@@ -5295,15 +6328,27 @@ function handleReadyPayload(client, data) {
5295
6328
  const waitForGuilds = client.options.waitForGuilds === true;
5296
6329
  const guilds = data.guilds ?? [];
5297
6330
  const pending = hydrateReadyGuilds(client, guilds, waitForGuilds);
6331
+ if (client.readyAt !== null) {
6332
+ if (pending !== null && pending.size > 0) {
6333
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6334
+ for (const id of pending) existing.add(id);
6335
+ client._pendingGuildIds = existing;
6336
+ }
6337
+ return;
6338
+ }
5298
6339
  if (pending !== null && pending.size > 0) {
5299
- client._pendingGuildIds = pending;
6340
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6341
+ for (const id of pending) existing.add(id);
6342
+ client._pendingGuildIds = existing;
5300
6343
  return;
5301
6344
  }
5302
6345
  if (waitForGuilds && guilds.length === 0) {
5303
- client._guildStreamSettleTimeout = setTimeout(() => {
5304
- client._guildStreamSettleTimeout = null;
5305
- finalizeClientReady(client);
5306
- }, GUILD_STREAM_SETTLE_MS);
6346
+ if (client._guildStreamSettleTimeout === null) {
6347
+ client._guildStreamSettleTimeout = setTimeout(() => {
6348
+ client._guildStreamSettleTimeout = null;
6349
+ if (client.readyAt === null) finalizeClientReady(client);
6350
+ }, GUILD_STREAM_SETTLE_MS);
6351
+ }
5307
6352
  return;
5308
6353
  }
5309
6354
  finalizeClientReady(client);
@@ -5315,7 +6360,7 @@ async function connectClientGateway(client, token, signal) {
5315
6360
  const ws = new WebSocketManager({
5316
6361
  token,
5317
6362
  intents: client.options.intents ?? 0,
5318
- presence: client.options.presence,
6363
+ presence: client.options.presence ? toPresenceWire(client.options.presence) : void 0,
5319
6364
  flags: client.options.identifyFlags,
5320
6365
  ignoredEvents: client.options.ignoredEvents,
5321
6366
  initialGuildId: client.options.initialGuildId,
@@ -5324,24 +6369,57 @@ async function connectClientGateway(client, token, signal) {
5324
6369
  },
5325
6370
  version: client.options.rest?.version ?? "1",
5326
6371
  debug: client.options.gatewayDebug !== false,
5327
- WebSocket: client.options.WebSocket
6372
+ WebSocket: client.options.WebSocket,
6373
+ shardCount: client.options.shardCount ?? client.options.totalShards,
6374
+ shardIds: client.options.shardIds ?? client.options.shardList,
6375
+ guildsPerShard: client.options.guildsPerShard,
6376
+ buildStrategy: client.options.buildStrategy,
6377
+ sessionStore: client.options.sessionStore,
6378
+ identifyThrottler: client.options.identifyThrottler
5328
6379
  });
5329
6380
  ws.on("dispatch", ({ payload }) => {
5330
6381
  handleGatewayDispatch(client, payload, client._deferredGatewayDispatches).catch(
5331
6382
  (err) => emitClientError(client, err)
5332
6383
  );
5333
6384
  });
5334
- ws.on("ready", ({ data }) => {
5335
- handleReadyPayload(client, data);
6385
+ ws.on("ready", ({ shardId, data }) => {
6386
+ client.emit(Events.ShardReady, shardId);
6387
+ try {
6388
+ handleReadyPayload(client, data);
6389
+ } catch (err) {
6390
+ emitClientError(client, err);
6391
+ }
6392
+ });
6393
+ ws.on("resumed", (shardId) => {
6394
+ client.emit(Events.ShardResumed, shardId);
6395
+ });
6396
+ ws.on("close", ({ shardId, code }) => {
6397
+ client.emit(Events.ShardDisconnect, shardId, code);
6398
+ if (code === GatewayCloseCodes.AuthenticationFailed) {
6399
+ emitClientError(
6400
+ client,
6401
+ new FluxerError("Gateway authentication failed (4004). Check the bot token.", {
6402
+ code: ErrorCodes.InvalidToken
6403
+ })
6404
+ );
6405
+ }
5336
6406
  });
5337
- ws.on("error", ({ error }) => {
5338
- client.logger.error("gateway error", { error: error.message, name: error.name });
6407
+ ws.on("error", ({ shardId, error }) => {
6408
+ if (shardId >= 0) client.emit(Events.ShardError, shardId, error);
6409
+ client.logger.error("gateway error", {
6410
+ error: error.message,
6411
+ name: error.name,
6412
+ shardId
6413
+ });
5339
6414
  client.emit(Events.Error, error);
5340
6415
  });
5341
6416
  ws.on("debug", (msg) => {
5342
6417
  client.logger.debug(msg);
5343
6418
  client.emit(Events.Debug, msg);
5344
6419
  });
6420
+ ws.on("shardingRequired", (payload) => {
6421
+ client.emit(Events.ShardingRequired, payload);
6422
+ });
5345
6423
  client._ws = ws;
5346
6424
  const onAbort = () => {
5347
6425
  ws.destroy();
@@ -5367,9 +6445,9 @@ async function connectClientGateway(client, token, signal) {
5367
6445
  }
5368
6446
 
5369
6447
  // src/ClientCore/GuildManager.ts
5370
- import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
5371
- import { Routes as Routes31 } from "@fluxerjs/types";
5372
- var GuildManager = class extends LimitedCollection4 {
6448
+ import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
6449
+ import { Routes as Routes32 } from "@fluxerjs/types";
6450
+ var GuildManager = class extends LimitedCollection5 {
5373
6451
  constructor(client) {
5374
6452
  super({
5375
6453
  maxSize: client.cache.limits.guilds,
@@ -5378,8 +6456,8 @@ var GuildManager = class extends LimitedCollection4 {
5378
6456
  this.client = client;
5379
6457
  }
5380
6458
  /**
5381
- * Remove a guild and cascade its channels / message caches.
5382
- * FIFO eviction uses `onEvict` instead (via `super.delete` in LimitedCollection).
6459
+ * Remove a guild from cache and cascade its channels / message caches.
6460
+ * Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
5383
6461
  */
5384
6462
  delete(key) {
5385
6463
  const guild = this.get(key);
@@ -5407,7 +6485,7 @@ var GuildManager = class extends LimitedCollection4 {
5407
6485
  const cached = this.get(guildId);
5408
6486
  if (cached && !options?.force) return cached;
5409
6487
  try {
5410
- const data = await this.client.rest.get(Routes31.guild(guildId));
6488
+ const data = await this.client.rest.get(Routes32.guild(guildId));
5411
6489
  if (cached) {
5412
6490
  cached._patch(data);
5413
6491
  return cached;
@@ -5492,184 +6570,13 @@ var MessageCache = class {
5492
6570
  }
5493
6571
  };
5494
6572
 
5495
- // src/ClientCore/PackManager.ts
5496
- import {
5497
- Routes as Routes32
5498
- } from "@fluxerjs/types";
5499
- function toPackSummaryPayload(data) {
5500
- return {
5501
- id: data.id,
5502
- name: data.name,
5503
- description: data.description,
5504
- type: data.type,
5505
- creatorId: data.creator_id,
5506
- createdAt: data.created_at,
5507
- updatedAt: data.updated_at,
5508
- ...data.installed_at !== void 0 ? { installedAt: data.installed_at } : {}
5509
- };
5510
- }
5511
- function toEmojiPayload(data) {
5512
- return {
5513
- id: data.id,
5514
- name: data.name,
5515
- animated: data.animated
5516
- };
5517
- }
5518
- function toStickerPayload(data) {
5519
- return {
5520
- id: data.id,
5521
- name: data.name,
5522
- description: data.description,
5523
- tags: data.tags,
5524
- animated: data.animated,
5525
- nsfw: data.nsfw
5526
- };
5527
- }
5528
- function toInvitePayload(data) {
5529
- return {
5530
- code: data.code,
5531
- ...data.max_uses !== void 0 ? { maxUses: data.max_uses } : {},
5532
- ...data.max_age !== void 0 ? { maxAge: data.max_age } : {},
5533
- ...data.uses !== void 0 ? { uses: data.uses } : {},
5534
- ...data.temporary !== void 0 ? { temporary: data.temporary } : {},
5535
- ...data.created_at !== void 0 ? { createdAt: data.created_at } : {},
5536
- ...data.expires_at !== void 0 ? { expiresAt: data.expires_at } : {}
5537
- };
5538
- }
5539
- function mapDashboardSection(section) {
5540
- return {
5541
- installedLimit: section.installed_limit,
5542
- createdLimit: section.created_limit,
5543
- installed: section.installed.map(toPackSummaryPayload),
5544
- created: section.created.map(toPackSummaryPayload)
5545
- };
5546
- }
5547
- var PackManager = class {
5548
- constructor(client) {
5549
- this.client = client;
5550
- }
5551
- /** Fetch the current user's pack dashboard (camelCase summaries). */
5552
- async fetchDashboard() {
5553
- const data = await this.client.rest.get(Routes32.packs());
5554
- return {
5555
- emoji: mapDashboardSection(data.emoji),
5556
- sticker: mapDashboardSection(data.sticker)
5557
- };
5558
- }
5559
- /** Create a pack. */
5560
- async create(packType, body) {
5561
- const data = await this.client.rest.post(Routes32.packsByType(packType), {
5562
- body
5563
- });
5564
- return toPackSummaryPayload(data);
5565
- }
5566
- /** Edit a pack. */
5567
- async edit(packId, body) {
5568
- const data = await this.client.rest.patch(Routes32.pack(packId), { body });
5569
- return toPackSummaryPayload(data);
5570
- }
5571
- /** Delete a pack. */
5572
- async delete(packId) {
5573
- await this.client.rest.delete(Routes32.pack(packId));
5574
- }
5575
- /** Install a pack for the current user. */
5576
- async install(packId) {
5577
- await this.client.rest.post(Routes32.packInstall(packId));
5578
- }
5579
- /** Uninstall a pack for the current user. */
5580
- async uninstall(packId) {
5581
- await this.client.rest.delete(Routes32.packInstall(packId));
5582
- }
5583
- /** List invites for a pack. */
5584
- async listInvites(packId) {
5585
- const data = await this.client.rest.get(Routes32.packInvites(packId));
5586
- return data.map(toInvitePayload);
5587
- }
5588
- /** Create an invite for a pack. */
5589
- async createInvite(packId, options = {}) {
5590
- const body = toPackInviteBody(options);
5591
- const data = await this.client.rest.post(Routes32.packInvites(packId), {
5592
- body: Object.keys(body).length ? body : void 0
5593
- });
5594
- return toInvitePayload(data);
5595
- }
5596
- /** List emojis in a pack. */
5597
- async listEmojis(packId) {
5598
- const data = await this.client.rest.get(Routes32.packEmojis(packId));
5599
- return data.map(toEmojiPayload);
5600
- }
5601
- /** Create an emoji in a pack. */
5602
- async createEmoji(packId, options) {
5603
- const data = await this.client.rest.post(Routes32.packEmojis(packId), {
5604
- body: toEmojiCreateBody(options)
5605
- });
5606
- return toEmojiPayload(data);
5607
- }
5608
- /** Bulk-create emojis in a pack. */
5609
- async createEmojisBulk(packId, emojis) {
5610
- const data = await this.client.rest.post(
5611
- Routes32.packEmojisBulk(packId),
5612
- { body: { emojis: emojis.map(toEmojiCreateBody) } }
5613
- );
5614
- return {
5615
- success: data.success.map(toEmojiPayload),
5616
- failed: data.failed
5617
- };
5618
- }
5619
- /** Edit an emoji in a pack. */
5620
- async editEmoji(packId, emojiId, options) {
5621
- const data = await this.client.rest.patch(Routes32.packEmoji(packId, emojiId), {
5622
- body: toEmojiEditBody(options)
5623
- });
5624
- return toEmojiPayload(data);
5625
- }
5626
- /** Delete an emoji from a pack. */
5627
- async deleteEmoji(packId, emojiId) {
5628
- await this.client.rest.delete(Routes32.packEmoji(packId, emojiId));
5629
- }
5630
- /** List stickers in a pack. */
5631
- async listStickers(packId) {
5632
- const data = await this.client.rest.get(Routes32.packStickers(packId));
5633
- return data.map(toStickerPayload);
5634
- }
5635
- /** Create a sticker in a pack. */
5636
- async createSticker(packId, options) {
5637
- const data = await this.client.rest.post(Routes32.packStickers(packId), {
5638
- body: toStickerCreateBody(options)
5639
- });
5640
- return toStickerPayload(data);
5641
- }
5642
- /** Bulk-create stickers in a pack. */
5643
- async createStickersBulk(packId, stickers) {
5644
- const data = await this.client.rest.post(
5645
- Routes32.packStickersBulk(packId),
5646
- { body: { stickers: stickers.map(toStickerCreateBody) } }
5647
- );
5648
- return {
5649
- success: data.success.map(toStickerPayload),
5650
- failed: data.failed
5651
- };
5652
- }
5653
- /** Edit a sticker in a pack. */
5654
- async editSticker(packId, stickerId, options) {
5655
- const data = await this.client.rest.patch(Routes32.packSticker(packId, stickerId), {
5656
- body: toStickerEditBody(options)
5657
- });
5658
- return toStickerPayload(data);
5659
- }
5660
- /** Delete a sticker from a pack. */
5661
- async deleteSticker(packId, stickerId) {
5662
- await this.client.rest.delete(Routes32.packSticker(packId, stickerId));
5663
- }
5664
- };
5665
-
5666
6573
  // src/ClientCore/UserManager.ts
5667
- import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
6574
+ import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
5668
6575
  import {
5669
6576
  Routes as Routes33
5670
6577
  } from "@fluxerjs/types";
5671
6578
  var soft = (p) => p.catch(() => null);
5672
- var UserManager = class extends LimitedCollection5 {
6579
+ var UserManager = class extends LimitedCollection6 {
5673
6580
  constructor(client) {
5674
6581
  super({ maxSize: client.cache.limits.users });
5675
6582
  this.client = client;
@@ -5687,11 +6594,17 @@ var UserManager = class extends LimitedCollection5 {
5687
6594
  }
5688
6595
  return removed;
5689
6596
  }
5690
- /** Fetch a user by ID and update cache. */
5691
- async fetch(userId) {
6597
+ /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
6598
+ async fetch(userId, options) {
6599
+ const cached = this.get(userId);
6600
+ if (cached && !options?.force) return cached;
5692
6601
  const data = await this.client.rest.get(Routes33.user(userId));
5693
6602
  return this.client.getOrCreateUser(data);
5694
6603
  }
6604
+ /** Return a cached user, otherwise {@link fetch}. */
6605
+ async resolve(userId) {
6606
+ return this.get(userId) ?? this.fetch(userId);
6607
+ }
5695
6608
  /**
5696
6609
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
5697
6610
  * @example
@@ -5751,14 +6664,22 @@ var Client = class _Client extends EventEmitter3 {
5751
6664
  users;
5752
6665
  /** Cache limits, stats, sweeps, and cascade entry points. */
5753
6666
  cache;
5754
- /** Emoji/sticker pack REST wrappers (`/packs/*`). */
5755
- packs = new PackManager(this);
5756
- /** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
6667
+ /** Typed event handlers. Prefer `client.on(Events.*, ...)`. */
5757
6668
  events;
5758
6669
  /** The authenticated bot user. Null until READY is received. */
5759
6670
  user = null;
5760
6671
  /** Timestamp when the client became ready. Null until READY is received. */
5761
6672
  readyAt = null;
6673
+ /**
6674
+ * Milliseconds since {@link readyAt}, or `null` if the client is not ready.
6675
+ * @example
6676
+ * client.on(Events.Ready, () => {
6677
+ * console.log(client.uptime);
6678
+ * });
6679
+ */
6680
+ get uptime() {
6681
+ return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
6682
+ }
5762
6683
  /** @internal WebSocket manager. */
5763
6684
  _ws = null;
5764
6685
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
@@ -5899,33 +6820,23 @@ var Client = class _Client extends EventEmitter3 {
5899
6820
  return fetchApplication(this);
5900
6821
  }
5901
6822
  /**
5902
- * Fetch OAuth2 applications owned by this bot.
5903
- * @returns Array of OAuth application objects
6823
+ * Fetch OAuth2 applications (`GET /oauth2/applications/@me`).
6824
+ * A bot token returns the bot application object (normalized to a one-element array).
6825
+ * A user token returns the owner's application list.
5904
6826
  */
5905
6827
  fetchOAuthApplications() {
5906
6828
  return fetchOAuthApplications(this);
5907
6829
  }
5908
- /**
5909
- * Check username#discriminator availability.
5910
- * @param username - Username to check
5911
- * @param discriminator - Discriminator to check
5912
- * @returns Availability result
5913
- */
5914
- checkUsernameTag(username, discriminator) {
5915
- return checkUsernameTag(this, username, discriminator);
5916
- }
5917
6830
  /**
5918
6831
  * Preload recent messages for multiple channels (batch endpoint).
5919
- * @param channelIds - Array of channel IDs to preload
5920
- * @returns Preload response with message counts/timestamps
6832
+ * Prefer this over {@link bulkFetchMessages} for bots (`bulkFetchMessages` is user-account only).
5921
6833
  */
5922
6834
  preloadMessages(channelIds) {
5923
6835
  return preloadMessages(this, channelIds);
5924
6836
  }
5925
6837
  /**
5926
6838
  * Preload recent messages (alternate endpoint).
5927
- * @param channelIds - Array of channel IDs to preload
5928
- * @returns Preload response with message counts/timestamps
6839
+ * Prefer this over {@link bulkFetchMessages} for bots.
5929
6840
  */
5930
6841
  preloadMessagesAlt(channelIds) {
5931
6842
  return preloadMessagesAlt(this, channelIds);
@@ -5933,6 +6844,14 @@ var Client = class _Client extends EventEmitter3 {
5933
6844
  bulkFetchMessages(requests, options = {}) {
5934
6845
  return bulkFetchMessages(this, requests, options);
5935
6846
  }
6847
+ /**
6848
+ * Search messages in the current bot scope (`POST /search/messages`, `scope: current`).
6849
+ * Other scopes are denied for bots (`BOT_SEARCH_SCOPE_UNAVAILABLE`).
6850
+ * Returns camelCase results (`hitsPerPage`) or `{ indexing: true }` while channels are indexed.
6851
+ */
6852
+ searchMessages(options) {
6853
+ return searchMessages(this, options);
6854
+ }
5936
6855
  /** @internal */
5937
6856
  _getMessageCache(channelId) {
5938
6857
  return this._messageCache.get(channelId);
@@ -5956,12 +6875,16 @@ var Client = class _Client extends EventEmitter3 {
5956
6875
  /**
5957
6876
  * Sweep cached messages (remove entries matching filter).
5958
6877
  * Prefer {@link CacheController.sweepMessages} (`client.cache.sweepMessages`).
6878
+ * The filter receives a hydrated {@link Message} (`createdAt`), not the stored wire payload.
5959
6879
  * @param filter - Predicate to test each message (return true to remove)
5960
6880
  * @param channelId - Optional channel ID to scope sweep
5961
6881
  * @returns Count of messages removed
5962
6882
  */
5963
6883
  sweepMessages(filter, channelId) {
5964
- return this._messageCache.sweep(filter, channelId);
6884
+ return this._messageCache.sweep(
6885
+ filter ? (data, chId) => filter(new Message(this, data), chId) : void 0,
6886
+ channelId
6887
+ );
5965
6888
  }
5966
6889
  /**
5967
6890
  * Sweep cached members across all guilds (remove entries matching filter).
@@ -5994,6 +6917,9 @@ var Client = class _Client extends EventEmitter3 {
5994
6917
  }
5995
6918
  /**
5996
6919
  * The underlying {@link WebSocketManager} (throws if not logged in).
6920
+ * Gateway heartbeat ACK latency: `client.ws.ping` (ms, or `-1` before the first ACK).
6921
+ * @example
6922
+ * console.log(client.ws.ping);
5997
6923
  * @throws {@link FluxerError} with {@link ErrorCodes.NotLoggedIn}
5998
6924
  */
5999
6925
  get ws() {
@@ -6032,6 +6958,37 @@ var Client = class _Client extends EventEmitter3 {
6032
6958
  if (options.nonce !== void 0) data.nonce = options.nonce;
6033
6959
  this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildMembers, d: data });
6034
6960
  }
6961
+ /**
6962
+ * Request guild member/online counts via gateway opcode 15.
6963
+ * Listen for `guildCountsUpdate`. Cached `guild.memberCount` / `guild.onlineCount` update when that event arrives.
6964
+ */
6965
+ requestGuildCounts(options) {
6966
+ const guildIds = [...new Set(options.guildIds.filter(Boolean))];
6967
+ if (!guildIds.length) {
6968
+ throw new FluxerError("requestGuildCounts requires at least one guildId", {
6969
+ code: ErrorCodes.InvalidGatewayRequest
6970
+ });
6971
+ }
6972
+ const data = { guild_ids: guildIds };
6973
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6974
+ this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildCounts, d: data });
6975
+ }
6976
+ /**
6977
+ * Request per-channel member counts via gateway opcode 16.
6978
+ * Event-only: listen for `channelMemberCountsUpdate`. There is no `channel.memberCount` field.
6979
+ */
6980
+ requestChannelMemberCounts(options) {
6981
+ if (!options.guildId) {
6982
+ throw new FluxerError("requestChannelMemberCounts requires guildId", {
6983
+ code: ErrorCodes.InvalidGatewayRequest
6984
+ });
6985
+ }
6986
+ const data = { guild_id: options.guildId };
6987
+ if (options.channelId !== void 0) data.channel_id = options.channelId;
6988
+ if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
6989
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6990
+ this._sendToAllShards({ op: GatewayOpcodes2.RequestChannelMemberCounts, d: data });
6991
+ }
6035
6992
  /**
6036
6993
  * Broadcast a gateway payload to all shards.
6037
6994
  * @param payload - Gateway send payload
@@ -6045,9 +7002,13 @@ var Client = class _Client extends EventEmitter3 {
6045
7002
  }
6046
7003
  /**
6047
7004
  * Connect to the gateway with a bot token.
7005
+ * @example
7006
+ * const client = new Client();
7007
+ * client.on(Events.Ready, () => console.log('Ready!'));
7008
+ * await client.login(process.env.FLUXER_BOT_TOKEN);
6048
7009
  * @param token - Bot token from the developer portal
6049
7010
  * @param options - Optional abort signal for cancellation
6050
- * @returns The token that was used (echo)
7011
+ * @returns This client (for chaining)
6051
7012
  * @throws {@link FluxerError} if already logged in or token is invalid
6052
7013
  */
6053
7014
  async login(token, options) {
@@ -6062,7 +7023,7 @@ var Client = class _Client extends EventEmitter3 {
6062
7023
  this.rest.setToken(token);
6063
7024
  try {
6064
7025
  this._ws = await connectClientGateway(this, token, options?.signal);
6065
- return token;
7026
+ return this;
6066
7027
  } catch (err) {
6067
7028
  this._ws?.destroy();
6068
7029
  this._ws = null;
@@ -6115,6 +7076,20 @@ var Client = class _Client extends EventEmitter3 {
6115
7076
  );
6116
7077
  }
6117
7078
  }
7079
+ /**
7080
+ * REST path helpers ({@link Routes}). Pass the path to {@link REST client.rest}.
7081
+ * Prefer high-level helpers (`channel.send()`, `guild.members.fetch()`) when they exist.
7082
+ *
7083
+ * @example
7084
+ * const channel = await client.rest.get(Client.Routes.channel(channelId));
7085
+ *
7086
+ * @example
7087
+ * await client.rest.post(Client.Routes.channelMessages(channelId), {
7088
+ * body: { content: 'hello' },
7089
+ * });
7090
+ *
7091
+ * @see {@link Routes}
7092
+ */
6118
7093
  static get Routes() {
6119
7094
  return Routes34;
6120
7095
  }
@@ -6458,7 +7433,8 @@ var ClientCluster = class extends EventEmitter4 {
6458
7433
  };
6459
7434
  export {
6460
7435
  AllowedMentions,
6461
- AttachmentBuilder,
7436
+ AttachmentBuilder2 as AttachmentBuilder,
7437
+ AttachmentMeta,
6462
7438
  AuditLogActionType,
6463
7439
  BETA_CLIENT_CLUSTER_WARNING,
6464
7440
  Base,
@@ -6485,31 +7461,38 @@ export {
6485
7461
  GuildBan,
6486
7462
  GuildChannel,
6487
7463
  GuildEmoji,
7464
+ GuildManager,
6488
7465
  GuildMember,
6489
7466
  GuildMemberManager,
6490
7467
  GuildMemberProfileFlags,
6491
7468
  GuildMemberRoleManager,
6492
7469
  GuildNSFWLevel2 as GuildNSFWLevel,
6493
7470
  GuildOperations,
7471
+ GuildRoleManager,
6494
7472
  GuildSticker,
6495
7473
  Invite,
6496
7474
  InviteType3 as InviteType,
6497
7475
  LinkChannel,
6498
7476
  Message,
6499
- MessageAttachmentFlags,
7477
+ MessageAttachmentFlags2 as MessageAttachmentFlags,
6500
7478
  MessageCollector,
6501
7479
  MessageFlags,
6502
- MessageFlagsBitField,
7480
+ MessageFlagsBitField2 as MessageFlagsBitField,
6503
7481
  MessageFlagsBits,
6504
7482
  MessageManager,
6505
7483
  MessagePayload2 as MessagePayload,
6506
7484
  MessageReaction,
7485
+ MessageReactionManager,
6507
7486
  MessageReferenceType2 as MessageReferenceType,
7487
+ MessageSticker,
6508
7488
  MessageType2 as MessageType,
6509
7489
  OverwriteType2 as OverwriteType,
6510
- PackManager,
6511
- PermissionFlags4 as PermissionFlags,
6512
- PermissionsBitField3 as PermissionsBitField,
7490
+ PartialGuildMember,
7491
+ PartialMessage,
7492
+ PermissionFlags5 as PermissionFlags,
7493
+ PermissionOverwrite,
7494
+ PermissionOverwriteManager,
7495
+ PermissionsBitField4 as PermissionsBitField,
6513
7496
  PublicUserFlags,
6514
7497
  ReactionCollector,
6515
7498
  RelationshipType,
@@ -6544,26 +7527,6 @@ export {
6544
7527
  resolveCacheLimits,
6545
7528
  resolveInstanceEndpoints,
6546
7529
  resolveKlipyToImageUrl,
6547
- resolvePermissionsToBitfield2 as resolvePermissionsToBitfield,
6548
- serializeError,
6549
- toAttachmentUploadCompleteBody,
6550
- toAttachmentUploadPlanBody,
6551
- toBulkFetchWire,
6552
- toChannelEditBody,
6553
- toChannelInviteBody,
6554
- toDiscoveryApplicationPayload,
6555
- toDiscoveryBody,
6556
- toDiscoveryStatusPayload,
6557
- toEmojiCreateBody,
6558
- toEmojiEditBody,
6559
- toMemberEditBody,
6560
- toMemberSearchBody,
6561
- toMessageAttachmentEditWire,
6562
- toPackInviteBody,
6563
- toPackSummaryPayload,
6564
- toPresenceWire,
6565
- toProfilePayload,
6566
- toStickerCreateBody,
6567
- toStickerEditBody,
6568
- toSudoBody
7530
+ resolvePermissionsToBitfield4 as resolvePermissionsToBitfield,
7531
+ serializeError
6569
7532
  };