@fluxerjs/core 3.2.0 → 3.4.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.js CHANGED
@@ -24,7 +24,7 @@ __export(src_exports, {
24
24
  AnnouncementChannel: () => AnnouncementChannel,
25
25
  AttachmentBuilder: () => import_builders5.AttachmentBuilder,
26
26
  AttachmentMeta: () => import_builders5.AttachmentMeta,
27
- AuditLogActionType: () => import_types40.AuditLogActionType,
27
+ AuditLogActionType: () => import_types46.AuditLogActionType,
28
28
  BETA_CLIENT_CLUSTER_WARNING: () => BETA_CLIENT_CLUSTER_WARNING,
29
29
  Base: () => Base,
30
30
  CDN_URL: () => CDN_URL,
@@ -32,12 +32,12 @@ __export(src_exports, {
32
32
  CategoryChannel: () => CategoryChannel,
33
33
  Channel: () => Channel,
34
34
  ChannelManager: () => ChannelManager,
35
- ChannelType: () => import_types40.ChannelType,
35
+ ChannelType: () => import_types46.ChannelType,
36
36
  Client: () => Client,
37
37
  ClientCluster: () => ClientCluster,
38
38
  ClientClusterEvents: () => ClientClusterEvents,
39
39
  ClientUser: () => ClientUser,
40
- ContentWarningLevel: () => import_types40.ContentWarningLevel,
40
+ ContentWarningLevel: () => import_types46.ContentWarningLevel,
41
41
  DEFAULT_CACHE_LIMITS: () => DEFAULT_CACHE_LIMITS,
42
42
  DEFAULT_INSTANCE_ENDPOINTS: () => DEFAULT_INSTANCE_ENDPOINTS,
43
43
  DMChannel: () => DMChannel,
@@ -45,7 +45,11 @@ __export(src_exports, {
45
45
  ErrorCodes: () => import_util3.ErrorCodes,
46
46
  Events: () => Events,
47
47
  FluxerError: () => import_util4.FluxerError,
48
- GatewayOpcodes: () => import_types40.GatewayOpcodes,
48
+ ForumChannel: () => ForumChannel,
49
+ ForumLayout: () => import_types46.ForumLayout,
50
+ ForumSortOrder: () => import_types46.ForumSortOrder,
51
+ ForumTagSetting: () => import_types46.ForumTagSetting,
52
+ GatewayOpcodes: () => import_types46.GatewayOpcodes,
49
53
  Guild: () => Guild,
50
54
  GuildBan: () => GuildBan,
51
55
  GuildChannel: () => GuildChannel,
@@ -53,45 +57,52 @@ __export(src_exports, {
53
57
  GuildManager: () => GuildManager,
54
58
  GuildMember: () => GuildMember,
55
59
  GuildMemberManager: () => GuildMemberManager,
56
- GuildMemberProfileFlags: () => import_types40.GuildMemberProfileFlags,
60
+ GuildMemberProfileFlags: () => import_types46.GuildMemberProfileFlags,
57
61
  GuildMemberRoleManager: () => GuildMemberRoleManager,
58
- GuildNSFWLevel: () => import_types40.GuildNSFWLevel,
59
- GuildOperations: () => import_types40.GuildOperations,
62
+ GuildNSFWLevel: () => import_types46.GuildNSFWLevel,
63
+ GuildOperations: () => import_types46.GuildOperations,
60
64
  GuildRoleManager: () => GuildRoleManager,
61
65
  GuildSticker: () => GuildSticker,
62
66
  INSTANCE_DISCOVERY_PATH: () => INSTANCE_DISCOVERY_PATH,
63
67
  Invite: () => Invite,
64
- InviteType: () => import_types40.InviteType,
68
+ InviteType: () => import_types46.InviteType,
65
69
  LinkChannel: () => LinkChannel,
70
+ MediaChannel: () => MediaChannel,
66
71
  Message: () => Message,
67
- MessageAttachmentFlags: () => import_types40.MessageAttachmentFlags,
72
+ MessageAttachmentFlags: () => import_types46.MessageAttachmentFlags,
68
73
  MessageCollector: () => MessageCollector,
69
- MessageFlags: () => import_types40.MessageFlags,
74
+ MessageFlags: () => import_types46.MessageFlags,
70
75
  MessageFlagsBitField: () => import_util27.MessageFlagsBitField,
71
76
  MessageFlagsBits: () => import_util27.MessageFlagsBits,
72
77
  MessageManager: () => MessageManager,
73
78
  MessagePayload: () => import_builders5.MessagePayload,
74
79
  MessageReaction: () => MessageReaction,
75
80
  MessageReactionManager: () => MessageReactionManager,
76
- MessageReferenceType: () => import_types40.MessageReferenceType,
81
+ MessageReferenceType: () => import_types46.MessageReferenceType,
77
82
  MessageSticker: () => MessageSticker,
78
- MessageType: () => import_types40.MessageType,
79
- OverwriteType: () => import_types40.OverwriteType,
83
+ MessageType: () => import_types46.MessageType,
84
+ OverwriteType: () => import_types46.OverwriteType,
80
85
  PartialGuildMember: () => PartialGuildMember,
81
86
  PartialMessage: () => PartialMessage,
82
87
  PermissionFlags: () => import_util27.PermissionFlags,
83
88
  PermissionOverwrite: () => PermissionOverwrite,
84
89
  PermissionOverwriteManager: () => PermissionOverwriteManager,
85
90
  PermissionsBitField: () => import_util27.PermissionsBitField,
86
- PublicUserFlags: () => import_types40.PublicUserFlags,
91
+ PublicUserFlags: () => import_types46.PublicUserFlags,
87
92
  ReactionCollector: () => ReactionCollector,
88
- RelationshipType: () => import_types40.RelationshipType,
93
+ RelationshipType: () => import_types46.RelationshipType,
89
94
  Role: () => Role,
90
- Routes: () => import_types40.Routes,
95
+ Routes: () => import_types46.Routes,
91
96
  STATIC_CDN_URL: () => STATIC_CDN_URL,
92
- SplashCardAlignment: () => import_types40.SplashCardAlignment,
93
- SystemChannelFlags: () => import_types40.SystemChannelFlags,
97
+ SplashCardAlignment: () => import_types46.SplashCardAlignment,
98
+ SystemChannelFlags: () => import_types46.SystemChannelFlags,
94
99
  TextChannel: () => TextChannel,
100
+ ThreadAutoArchiveDuration: () => import_types46.ThreadAutoArchiveDuration,
101
+ ThreadChannel: () => ThreadChannel,
102
+ ThreadManager: () => ThreadManager,
103
+ ThreadMember: () => ThreadMember,
104
+ ThreadMemberFlags: () => import_types46.ThreadMemberFlags,
105
+ ThreadMemberManager: () => ThreadMemberManager,
95
106
  User: () => User,
96
107
  UserFlagsBitField: () => import_util27.UserFlagsBitField,
97
108
  UserFlagsBits: () => import_util27.UserFlagsBits,
@@ -108,6 +119,7 @@ __export(src_exports, {
108
119
  cdnMemberBannerURL: () => cdnMemberBannerURL,
109
120
  cdnStickerURL: () => cdnStickerURL,
110
121
  createLogger: () => import_util27.createLogger,
122
+ fetchActiveThreads: () => fetchActiveThreads,
111
123
  instanceDiscoveryUrl: () => instanceDiscoveryUrl,
112
124
  inviteUrl: () => inviteUrl,
113
125
  normalizeApiOrigin: () => normalizeApiOrigin,
@@ -123,7 +135,7 @@ __export(src_exports, {
123
135
  });
124
136
  module.exports = __toCommonJS(src_exports);
125
137
  var import_builders5 = require("@fluxerjs/builders");
126
- var import_types40 = require("@fluxerjs/types");
138
+ var import_types46 = require("@fluxerjs/types");
127
139
  var import_util27 = require("@fluxerjs/util");
128
140
 
129
141
  // src/ClientCore/CacheController.ts
@@ -267,20 +279,20 @@ var CacheController = class {
267
279
 
268
280
  // src/ClientCore/ChannelManager.ts
269
281
  var import_collection8 = require("@fluxerjs/collection");
270
- var import_types22 = require("@fluxerjs/types");
282
+ var import_types28 = require("@fluxerjs/types");
271
283
 
272
284
  // src/Domain/Channel/Base.ts
273
- var import_types8 = require("@fluxerjs/types");
285
+ var import_types10 = require("@fluxerjs/types");
274
286
  var import_util8 = require("@fluxerjs/util");
275
287
 
276
288
  // src/ClientCore/MessageManager.ts
277
289
  var import_collection4 = require("@fluxerjs/collection");
278
- var import_types6 = require("@fluxerjs/types");
290
+ var import_types8 = require("@fluxerjs/types");
279
291
 
280
292
  // src/Domain/Message/Message.ts
281
293
  var import_builders3 = require("@fluxerjs/builders");
282
294
  var import_collection3 = require("@fluxerjs/collection");
283
- var import_types5 = require("@fluxerjs/types");
295
+ var import_types7 = require("@fluxerjs/types");
284
296
  var import_util6 = require("@fluxerjs/util");
285
297
 
286
298
  // src/ClientCore/SdkOptions/Attachments.ts
@@ -348,7 +360,130 @@ function toAttachmentUploadPlanResponse(data) {
348
360
  }
349
361
 
350
362
  // src/ClientCore/SdkOptions/Channels.ts
363
+ var import_types2 = require("@fluxerjs/types");
351
364
  var import_util = require("@fluxerjs/util");
365
+
366
+ // src/ClientCore/SdkOptions/Threads.ts
367
+ var import_types = require("@fluxerjs/types");
368
+ function toThreadEditBody(type, options) {
369
+ const body = {};
370
+ if (options.name !== void 0) body.name = options.name;
371
+ if (options.archived !== void 0) body.archived = options.archived;
372
+ if (options.autoArchiveDuration !== void 0) {
373
+ body.auto_archive_duration = options.autoArchiveDuration;
374
+ }
375
+ if (options.locked !== void 0) body.locked = options.locked;
376
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
377
+ if (options.flags !== void 0) body.flags = options.flags;
378
+ if (options.appliedTags !== void 0 && type !== import_types.ChannelType.PrivateThread) {
379
+ body.applied_tags = options.appliedTags;
380
+ }
381
+ if (options.invitable !== void 0 && type === import_types.ChannelType.PrivateThread) {
382
+ body.invitable = options.invitable;
383
+ }
384
+ return body;
385
+ }
386
+ function toThreadParentEditBody(options) {
387
+ const body = {};
388
+ if (options.autoArchiveDuration !== void 0) {
389
+ body.default_auto_archive_duration = options.autoArchiveDuration;
390
+ }
391
+ if (options.rateLimitPerUser !== void 0) {
392
+ body.default_thread_rate_limit_per_user = options.rateLimitPerUser;
393
+ }
394
+ return body;
395
+ }
396
+ function toStartThreadBody(channelType, options) {
397
+ const type = options.type ?? (channelType === import_types.ChannelType.GuildAnnouncement ? import_types.ChannelType.AnnouncementThread : import_types.ChannelType.PublicThread);
398
+ const body = { name: options.name, type };
399
+ if (options.autoArchiveDuration !== void 0) {
400
+ body.auto_archive_duration = options.autoArchiveDuration;
401
+ }
402
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
403
+ if (options.invitable !== void 0) body.invitable = options.invitable;
404
+ return body;
405
+ }
406
+ function toStartThreadFromMessageBody(options) {
407
+ const body = { name: options.name };
408
+ if (options.autoArchiveDuration !== void 0) {
409
+ body.auto_archive_duration = options.autoArchiveDuration;
410
+ }
411
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
412
+ return body;
413
+ }
414
+ function toForumThreadMessage(body) {
415
+ const message = {};
416
+ if (body.content !== void 0) message.content = body.content;
417
+ if (body.embeds !== void 0) message.embeds = body.embeds;
418
+ if (body.attachments !== void 0) message.attachments = body.attachments;
419
+ if (body.allowed_mentions !== void 0) message.allowed_mentions = body.allowed_mentions;
420
+ if (body.flags !== void 0) message.flags = body.flags;
421
+ if (body.sticker_ids !== void 0) message.sticker_ids = body.sticker_ids;
422
+ return message;
423
+ }
424
+ function toForumTagBody(options) {
425
+ const body = { name: options.name };
426
+ if ("id" in options && options.id !== void 0) body.id = options.id;
427
+ if (options.moderated !== void 0) body.moderated = options.moderated;
428
+ if (options.emojiId !== void 0) body.emoji_id = options.emojiId;
429
+ if (options.emojiName !== void 0) body.emoji_name = options.emojiName;
430
+ return body;
431
+ }
432
+ function forumParentWire(options, includeLayout) {
433
+ const body = {};
434
+ if (options.availableTags !== void 0) {
435
+ body.available_tags = options.availableTags.map((tag) => toForumTagBody(tag));
436
+ }
437
+ if (options.defaultReactionEmoji !== void 0) {
438
+ body.default_reaction_emoji = options.defaultReactionEmoji === null ? null : reactionEmojiWire(options.defaultReactionEmoji);
439
+ }
440
+ if (options.defaultSortOrder !== void 0) body.default_sort_order = options.defaultSortOrder;
441
+ if (options.defaultTagSetting !== void 0) body.default_tag_setting = options.defaultTagSetting;
442
+ if (options.flags !== void 0) body.flags = options.flags;
443
+ if (options.defaultAutoArchiveDuration !== void 0) {
444
+ body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
445
+ }
446
+ if (options.defaultThreadRateLimitPerUser !== void 0) {
447
+ body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
448
+ }
449
+ if (includeLayout && options.defaultForumLayout !== void 0) {
450
+ body.default_forum_layout = options.defaultForumLayout;
451
+ }
452
+ return body;
453
+ }
454
+ function reactionEmojiWire(emoji) {
455
+ const body = {};
456
+ if (emoji.emojiId !== void 0) body.emoji_id = emoji.emojiId;
457
+ if (emoji.emojiName !== void 0) body.emoji_name = emoji.emojiName;
458
+ return body;
459
+ }
460
+ function toThreadMemberSettingsBody(options) {
461
+ const body = {};
462
+ if (options.flags !== void 0) body.flags = options.flags;
463
+ if (options.muted !== void 0) body.muted = options.muted;
464
+ if (options.muteConfig !== void 0) {
465
+ body.mute_config = options.muteConfig === null ? null : {
466
+ ...options.muteConfig.endTime !== void 0 ? { end_time: options.muteConfig.endTime } : {},
467
+ selected_time_window: options.muteConfig.selectedTimeWindow
468
+ };
469
+ }
470
+ return body;
471
+ }
472
+ function withQuery(path, params) {
473
+ const query = new URLSearchParams();
474
+ for (const [key, value] of Object.entries(params)) {
475
+ if (value === void 0) continue;
476
+ if (Array.isArray(value)) {
477
+ for (const item of value) query.append(key, item);
478
+ continue;
479
+ }
480
+ query.set(key, String(value));
481
+ }
482
+ const text = query.toString();
483
+ return text ? `${path}?${text}` : path;
484
+ }
485
+
486
+ // src/ClientCore/SdkOptions/Channels.ts
352
487
  function toOverwriteWire(overwrite) {
353
488
  return {
354
489
  id: overwrite.id,
@@ -409,6 +544,16 @@ function toChannelCreateBody(options) {
409
544
  body.content_warning_text = options.contentWarningText;
410
545
  }
411
546
  if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
547
+ if (options.defaultAutoArchiveDuration !== void 0) {
548
+ body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
549
+ }
550
+ if (options.defaultThreadRateLimitPerUser !== void 0) {
551
+ body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
552
+ }
553
+ const forumParent = options.type === import_types2.ChannelType.GuildForum || options.type === import_types2.ChannelType.GuildMedia;
554
+ if (forumParent) {
555
+ Object.assign(body, forumParentWire(options, options.type === import_types2.ChannelType.GuildForum));
556
+ }
412
557
  return body;
413
558
  }
414
559
  function toChannelInviteBody(options) {
@@ -704,7 +849,7 @@ function auditReasonHeaders(reason) {
704
849
 
705
850
  // src/Helpers/MessageUtils/Body.ts
706
851
  var import_builders = require("@fluxerjs/builders");
707
- var import_types = require("@fluxerjs/types");
852
+ var import_types3 = require("@fluxerjs/types");
708
853
 
709
854
  // src/LibErrors/ErrorCodes.ts
710
855
  var import_util3 = require("@fluxerjs/util");
@@ -787,7 +932,7 @@ function normalizeSendFiles(files) {
787
932
  id: i,
788
933
  filename: file.filename,
789
934
  ...file.description != null ? { description: file.description } : {},
790
- ...file.spoiler ? { flags: import_types.MessageAttachmentFlags.IS_SPOILER } : {}
935
+ ...file.spoiler ? { flags: import_types3.MessageAttachmentFlags.IS_SPOILER } : {}
791
936
  };
792
937
  if (file.description != null || file.spoiler) anyBuilderMeta = true;
793
938
  metaFromBuilders.push(meta);
@@ -837,8 +982,8 @@ function toMessageReference(target, forceForward = false) {
837
982
  message_id: target.messageId
838
983
  };
839
984
  if (target.guildId) ref.guild_id = target.guildId;
840
- const type = forceForward ? import_types.MessageReferenceType.Forward : target.type ?? import_types.MessageReferenceType.Default;
841
- if (type !== import_types.MessageReferenceType.Default) ref.type = type;
985
+ const type = forceForward ? import_types3.MessageReferenceType.Forward : target.type ?? import_types3.MessageReferenceType.Default;
986
+ if (type !== import_types3.MessageReferenceType.Default) ref.type = type;
842
987
  if (target.attachmentIds?.length) ref.attachment_ids = target.attachmentIds;
843
988
  if (target.embedIndices?.length) ref.embed_indices = target.embedIndices;
844
989
  return ref;
@@ -934,7 +1079,7 @@ var import_node_events = require("events");
934
1079
  var import_collection = require("@fluxerjs/collection");
935
1080
 
936
1081
  // src/Domain/Message/MessageReaction.ts
937
- var import_types2 = require("@fluxerjs/types");
1082
+ var import_types4 = require("@fluxerjs/types");
938
1083
 
939
1084
  // src/Helpers/HttpErrors.ts
940
1085
  var import_rest = require("@fluxerjs/rest");
@@ -1051,7 +1196,7 @@ var MessageReaction = class _MessageReaction extends Base {
1051
1196
  if (cached) return cached;
1052
1197
  try {
1053
1198
  const data = await this.client.rest.get(
1054
- import_types2.Routes.channelMessage(this.channelId, this.messageId)
1199
+ import_types4.Routes.channelMessage(this.channelId, this.messageId)
1055
1200
  );
1056
1201
  return new Message(this.client, data);
1057
1202
  } catch (err) {
@@ -1089,6 +1234,7 @@ var Events = {
1089
1234
  GuildEmojisUpdate: "guildEmojisUpdate",
1090
1235
  GuildStickersUpdate: "guildStickersUpdate",
1091
1236
  GuildCountsUpdate: "guildCountsUpdate",
1237
+ GuildHealthUpdate: "guildHealthUpdate",
1092
1238
  ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
1093
1239
  GuildMemberAdd: "guildMemberAdd",
1094
1240
  GuildMemberUpdate: "guildMemberUpdate",
@@ -1100,6 +1246,14 @@ var Events = {
1100
1246
  ChannelCreate: "channelCreate",
1101
1247
  ChannelUpdate: "channelUpdate",
1102
1248
  ChannelDelete: "channelDelete",
1249
+ ThreadCreate: "threadCreate",
1250
+ ThreadUpdate: "threadUpdate",
1251
+ ThreadDelete: "threadDelete",
1252
+ ThreadListSync: "threadListSync",
1253
+ ThreadMemberUpdate: "threadMemberUpdate",
1254
+ ThreadMembersUpdate: "threadMembersUpdate",
1255
+ ThreadMemberListUpdate: "threadMemberListUpdate",
1256
+ ForumUnreads: "forumUnreads",
1103
1257
  ChannelPinsUpdate: "channelPinsUpdate",
1104
1258
  ChannelRecipientAdd: "channelRecipientAdd",
1105
1259
  ChannelRecipientRemove: "channelRecipientRemove",
@@ -1115,6 +1269,8 @@ var Events = {
1115
1269
  VoiceStateAck: "voiceStateAck",
1116
1270
  VoiceServerUpdate: "voiceServerUpdate",
1117
1271
  EntranceSoundPlay: "entranceSoundPlay",
1272
+ VoiceSignal: "voiceSignal",
1273
+ OperatorPassUpdate: "operatorPassUpdate",
1118
1274
  VoiceStatesSync: "voiceStatesSync",
1119
1275
  WebhooksUpdate: "webhooksUpdate",
1120
1276
  Resumed: "resumed",
@@ -1237,6 +1393,30 @@ var ReactionCollector = class _ReactionCollector extends import_node_events.Even
1237
1393
  }
1238
1394
  };
1239
1395
 
1396
+ // src/Domain/Channel/ThreadCache.ts
1397
+ function cacheThread(client, data) {
1398
+ const existing = client.channels.get(data.id);
1399
+ if (existing?.isThread() && existing.type === data.type) {
1400
+ existing._patch(data);
1401
+ placeThread(client, existing);
1402
+ return existing;
1403
+ }
1404
+ const created = Channel.from(client, data);
1405
+ if (!created.isThread()) {
1406
+ throw new import_util4.FluxerError(`Channel ${data.id} is not a thread`, {
1407
+ code: import_util3.ErrorCodes.InvalidChannelType
1408
+ });
1409
+ }
1410
+ placeThread(client, created);
1411
+ return created;
1412
+ }
1413
+ function placeThread(client, thread) {
1414
+ client.channels.set(thread.id, thread);
1415
+ if (!thread.guildId) return;
1416
+ const guild = client.guilds.get(thread.guildId);
1417
+ if (guild) guild.channels.set(thread.id, thread);
1418
+ }
1419
+
1240
1420
  // src/Domain/Message/Attachment.ts
1241
1421
  function toMessageAttachment(data) {
1242
1422
  return {
@@ -1515,27 +1695,27 @@ var MessageSticker = class extends Base {
1515
1695
  };
1516
1696
 
1517
1697
  // src/Domain/Message/Reactions.ts
1518
- var import_types3 = require("@fluxerjs/types");
1698
+ var import_types5 = require("@fluxerjs/types");
1519
1699
  async function emojiPath(message, emoji) {
1520
1700
  return message.client.resolveEmoji(emoji, message.guildId);
1521
1701
  }
1522
1702
  async function reactToMessage(message, emoji) {
1523
1703
  const wire = await emojiPath(message, emoji);
1524
1704
  await message.client.rest.put(
1525
- import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
1705
+ import_types5.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
1526
1706
  );
1527
1707
  }
1528
1708
  async function removeMessageReaction(message, emoji, userId) {
1529
1709
  const e = await emojiPath(message, emoji);
1530
- const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
1710
+ const route = userId ? import_types5.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types5.Routes.channelMessageReactionMe(message.channelId, message.id, e);
1531
1711
  await message.client.rest.delete(route);
1532
1712
  }
1533
1713
  async function removeAllMessageReactions(message) {
1534
- await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
1714
+ await message.client.rest.delete(import_types5.Routes.channelMessageReactions(message.channelId, message.id));
1535
1715
  }
1536
1716
  async function removeMessageReactionEmoji(message, emoji) {
1537
1717
  const e = await emojiPath(message, emoji);
1538
- await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
1718
+ await message.client.rest.delete(import_types5.Routes.channelMessageReaction(message.channelId, message.id, e));
1539
1719
  }
1540
1720
  async function fetchMessageReactionUsers(message, emoji, options) {
1541
1721
  return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
@@ -1546,7 +1726,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
1546
1726
  if (options?.limit != null) params.set("limit", String(options.limit));
1547
1727
  if (options?.after) params.set("after", options.after);
1548
1728
  const qs2 = params.toString();
1549
- const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
1729
+ const route = import_types5.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
1550
1730
  const data = await message.client.rest.get(route);
1551
1731
  if (Array.isArray(data)) {
1552
1732
  return {
@@ -1565,7 +1745,7 @@ async function fetchMessageReactionUsersPage(message, emoji, options) {
1565
1745
 
1566
1746
  // src/Domain/Message/Send.ts
1567
1747
  var import_builders2 = require("@fluxerjs/builders");
1568
- var import_types4 = require("@fluxerjs/types");
1748
+ var import_types6 = require("@fluxerjs/types");
1569
1749
  function toReplyTarget(ref) {
1570
1750
  return {
1571
1751
  channelId: ref.channel_id,
@@ -1599,7 +1779,7 @@ function asReplyTarget(value) {
1599
1779
  }
1600
1780
  async function sendPrepared(message, payload) {
1601
1781
  const data = await message.client.rest.post(
1602
- import_types4.Routes.channelMessages(message.channelId),
1782
+ import_types6.Routes.channelMessages(message.channelId),
1603
1783
  payload
1604
1784
  );
1605
1785
  message.client._addMessageToCache(message.channelId, data);
@@ -1708,6 +1888,8 @@ var Message = class _Message extends Base {
1708
1888
  nonce;
1709
1889
  /** IDs of custom emojis in the message classified as explicit. */
1710
1890
  nsfwEmojis;
1891
+ /** Thread started from this message, when the payload included one. */
1892
+ thread;
1711
1893
  /**
1712
1894
  * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1713
1895
  * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
@@ -1755,13 +1937,13 @@ var Message = class _Message extends Base {
1755
1937
  this.channelId = data.channel_id;
1756
1938
  this.guildId = data.guild_id ?? null;
1757
1939
  this.author = client.getOrCreateUser(data.author);
1758
- this.content = data.content;
1759
- this.createdAt = new Date(data.timestamp);
1940
+ this.content = data.content ?? "";
1941
+ this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
1760
1942
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1761
- this.pinned = data.pinned;
1943
+ this.pinned = data.pinned ?? false;
1762
1944
  this.attachments = new import_collection3.Collection();
1763
1945
  for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1764
- this.type = data.type ?? import_types5.MessageType.Default;
1946
+ this.type = data.type ?? import_types7.MessageType.Default;
1765
1947
  this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
1766
1948
  this.mentionEveryone = data.mention_everyone ?? false;
1767
1949
  this.tts = data.tts ?? false;
@@ -1783,39 +1965,55 @@ var Message = class _Message extends Base {
1783
1965
  this.mentionRoles = data.mention_roles ?? [];
1784
1966
  this.nonce = data.nonce ?? null;
1785
1967
  this.nsfwEmojis = data.nsfw_emojis ?? [];
1968
+ this.thread = data.thread ? cacheThread(client, data.thread) : null;
1786
1969
  }
1787
1970
  /**
1788
1971
  * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
1789
1972
  * @internal
1790
1973
  */
1791
1974
  _patch(data) {
1792
- this.content = data.content;
1793
- this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1794
- this.pinned = data.pinned;
1795
- this.attachments.clear();
1796
- for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1797
- this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
1798
- this.mentionEveryone = data.mention_everyone ?? false;
1799
- this.tts = data.tts ?? false;
1800
- this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1801
- this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1802
- this.reactions._patch(data.reactions);
1803
- this.messageReference = data.message_reference ? {
1804
- channelId: data.message_reference.channel_id,
1805
- messageId: data.message_reference.message_id,
1806
- guildId: data.message_reference.guild_id ?? null,
1807
- ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1808
- } : null;
1809
- this.messageSnapshots = (data.message_snapshots ?? []).map(
1810
- (s) => toMessageSnapshot(this.client, s)
1811
- );
1812
- this.call = data.call ? toMessageCall(data.call) : null;
1813
- this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
1814
- this.webhookId = data.webhook_id ?? null;
1815
- this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1816
- this.mentionRoles = data.mention_roles ?? [];
1817
- this.nonce = data.nonce ?? null;
1818
- this.nsfwEmojis = data.nsfw_emojis ?? [];
1975
+ if (data.content !== void 0) this.content = data.content ?? "";
1976
+ if (data.edited_timestamp !== void 0) {
1977
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1978
+ }
1979
+ if (data.pinned !== void 0) this.pinned = data.pinned;
1980
+ if (data.attachments !== void 0) {
1981
+ this.attachments.clear();
1982
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1983
+ }
1984
+ if (data.flags !== void 0) this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
1985
+ if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
1986
+ if (data.tts !== void 0) this.tts = data.tts;
1987
+ if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1988
+ if (data.stickers !== void 0) {
1989
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1990
+ }
1991
+ if (data.reactions !== void 0) this.reactions._patch(data.reactions);
1992
+ if (data.message_reference !== void 0) {
1993
+ this.messageReference = data.message_reference ? {
1994
+ channelId: data.message_reference.channel_id,
1995
+ messageId: data.message_reference.message_id,
1996
+ guildId: data.message_reference.guild_id ?? null,
1997
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1998
+ } : null;
1999
+ }
2000
+ if (data.message_snapshots !== void 0) {
2001
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
2002
+ (s) => toMessageSnapshot(this.client, s)
2003
+ );
2004
+ }
2005
+ if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
2006
+ if (data.referenced_message !== void 0) {
2007
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
2008
+ }
2009
+ if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
2010
+ if (data.mentions !== void 0) {
2011
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
2012
+ }
2013
+ if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
2014
+ if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
2015
+ if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
2016
+ if (data.thread) this.thread = cacheThread(this.client, data.thread);
1819
2017
  }
1820
2018
  /**
1821
2019
  * Send a standalone message in this channel (not a reply).
@@ -1876,7 +2074,7 @@ var Message = class _Message extends Base {
1876
2074
  if (options.attachments !== void 0) {
1877
2075
  body.attachments = toMessageAttachmentEditWire(options.attachments);
1878
2076
  }
1879
- const data = await this.client.rest.patch(import_types5.Routes.channelMessage(this.channelId, this.id), {
2077
+ const data = await this.client.rest.patch(import_types7.Routes.channelMessage(this.channelId, this.id), {
1880
2078
  body
1881
2079
  });
1882
2080
  const updated = new _Message(this.client, data);
@@ -1894,13 +2092,47 @@ var Message = class _Message extends Base {
1894
2092
  awaitReactions(options) {
1895
2093
  return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
1896
2094
  }
2095
+ /**
2096
+ * Start a thread from this message.
2097
+ * Fluxer chooses a public or announcement thread from the parent channel.
2098
+ */
2099
+ async startThread(options) {
2100
+ const data = await this.client.rest.post(
2101
+ import_types7.Routes.channelMessageThreads(this.channelId, this.id),
2102
+ {
2103
+ body: toStartThreadFromMessageBody(options),
2104
+ auth: true,
2105
+ ...auditReasonHeaders(options.reason)
2106
+ }
2107
+ );
2108
+ const thread = cacheThread(this.client, data);
2109
+ this.thread = thread;
2110
+ return thread;
2111
+ }
1897
2112
  /** Fetch the latest version of this message from the API. */
1898
2113
  async fetch() {
1899
2114
  return this.client.channels.fetchMessage(this.channelId, this.id);
1900
2115
  }
2116
+ /** Publish this announcement message to channels following its channel. */
2117
+ async crosspost() {
2118
+ const data = await this.client.rest.post(
2119
+ import_types7.Routes.channelMessageCrosspost(this.channelId, this.id),
2120
+ { auth: true }
2121
+ );
2122
+ const published = new _Message(this.client, data);
2123
+ this.client._addMessageToCache(this.channelId, data);
2124
+ return published;
2125
+ }
2126
+ /** Fetch the source guild of a crossposted (followed-channel) message. */
2127
+ async fetchCrosspostSource() {
2128
+ return this.client.rest.get(
2129
+ import_types7.Routes.channelMessageCrosspostSource(this.channelId, this.id),
2130
+ { auth: true }
2131
+ );
2132
+ }
1901
2133
  /** Delete this message. */
1902
2134
  async delete(reason) {
1903
- await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id), {
2135
+ await this.client.rest.delete(import_types7.Routes.channelMessage(this.channelId, this.id), {
1904
2136
  ...auditReasonHeaders(reason)
1905
2137
  });
1906
2138
  this.client._removeMessageFromCache(this.channelId, this.id);
@@ -1908,19 +2140,19 @@ var Message = class _Message extends Base {
1908
2140
  /** Delete a specific attachment from this message. */
1909
2141
  async deleteAttachment(attachmentId) {
1910
2142
  await this.client.rest.delete(
1911
- import_types5.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
2143
+ import_types7.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
1912
2144
  { auth: true }
1913
2145
  );
1914
2146
  this.attachments.delete(attachmentId);
1915
2147
  }
1916
2148
  /** Pin this message in the channel. */
1917
2149
  async pin() {
1918
- await this.client.rest.put(import_types5.Routes.channelPinMessage(this.channelId, this.id));
2150
+ await this.client.rest.put(import_types7.Routes.channelPinMessage(this.channelId, this.id));
1919
2151
  this.pinned = true;
1920
2152
  }
1921
2153
  /** Unpin this message from the channel. */
1922
2154
  async unpin() {
1923
- await this.client.rest.delete(import_types5.Routes.channelPinMessage(this.channelId, this.id));
2155
+ await this.client.rest.delete(import_types7.Routes.channelPinMessage(this.channelId, this.id));
1924
2156
  this.pinned = false;
1925
2157
  }
1926
2158
  /** React to this message with an emoji. */
@@ -2000,6 +2232,43 @@ var PartialMessage = class {
2000
2232
  }
2001
2233
  };
2002
2234
 
2235
+ // src/ClientCore/Resolve.ts
2236
+ function normalizeSnowflakeId(value, label) {
2237
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
2238
+ throw new TypeError(
2239
+ `${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
2240
+ );
2241
+ }
2242
+ const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
2243
+ if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
2244
+ throw new TypeError(`${label} requires a non-empty ID`);
2245
+ }
2246
+ return id;
2247
+ }
2248
+ function assertApiObjectWithId(data, label) {
2249
+ if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
2250
+ throw new TypeError(`${label} received an invalid API payload (missing string id)`);
2251
+ }
2252
+ return data;
2253
+ }
2254
+ function assertApiArray(data, label) {
2255
+ if (!Array.isArray(data)) {
2256
+ throw new TypeError(`${label} received an invalid API payload (expected an array)`);
2257
+ }
2258
+ return data;
2259
+ }
2260
+ async function dedupeFetch(pending, key, fn) {
2261
+ const existing = pending.get(key);
2262
+ if (existing) return existing;
2263
+ const request = fn();
2264
+ pending.set(key, request);
2265
+ try {
2266
+ return await request;
2267
+ } finally {
2268
+ if (pending.get(key) === request) pending.delete(key);
2269
+ }
2270
+ }
2271
+
2003
2272
  // src/ClientCore/MessageManager.ts
2004
2273
  var BULK = {
2005
2274
  requests: { min: 1, max: 25 },
@@ -2036,25 +2305,32 @@ var MessageManager = class {
2036
2305
  }
2037
2306
  /** Structure cache keyed by message id (identity for {@link get}). */
2038
2307
  _structures = new import_collection4.Collection();
2308
+ pendingFetches = /* @__PURE__ */ new Map();
2039
2309
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
2040
2310
  get(messageId) {
2041
- const data = this.client._getMessageCache(this.channelId)?.get(messageId);
2311
+ const id = String(messageId ?? "").trim();
2312
+ if (!id) return void 0;
2313
+ const data = this.client._getMessageCache(this.channelId)?.get(id);
2042
2314
  if (!data) {
2043
- this._structures.delete(messageId);
2315
+ this._structures.delete(id);
2044
2316
  return void 0;
2045
2317
  }
2046
- const existing = this._structures.get(messageId);
2047
- if (existing) return existing;
2318
+ const existing = this._structures.get(id);
2319
+ if (existing) {
2320
+ existing._patch(data);
2321
+ return existing;
2322
+ }
2048
2323
  const message = new Message(this.client, data);
2049
- this._structures.set(messageId, message);
2324
+ this._structures.set(id, message);
2050
2325
  return message;
2051
2326
  }
2052
2327
  /** Retrieve from cache, otherwise {@link fetch}. */
2053
2328
  async resolve(messageId) {
2054
- return this.get(messageId) ?? this.fetch(messageId);
2329
+ const id = normalizeSnowflakeId(messageId, "messages.resolve()");
2330
+ return this.get(id) ?? this.fetch(id);
2055
2331
  }
2056
2332
  async fetch(idOrOptions) {
2057
- return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
2333
+ return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
2058
2334
  }
2059
2335
  /** Cache API data and return a {@link Message} (reusing identity when present). */
2060
2336
  wrap(data) {
@@ -2071,9 +2347,13 @@ var MessageManager = class {
2071
2347
  }
2072
2348
  /** Fetch a single message from the API. */
2073
2349
  async fetchOne(messageId) {
2350
+ return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
2351
+ }
2352
+ async fetchOneFresh(messageId) {
2074
2353
  try {
2075
- const data = await this.client.rest.get(
2076
- import_types6.Routes.channelMessage(this.channelId, messageId)
2354
+ const data = assertApiObjectWithId(
2355
+ await this.client.rest.get(import_types8.Routes.channelMessage(this.channelId, messageId)),
2356
+ "messages.fetch()"
2077
2357
  );
2078
2358
  return this.wrap(data);
2079
2359
  } catch (err) {
@@ -2098,10 +2378,16 @@ var MessageManager = class {
2098
2378
  const value = options[key];
2099
2379
  if (value != null && value !== "") qs2.set(key, String(value));
2100
2380
  }
2101
- const base = import_types6.Routes.channelMessages(this.channelId);
2102
- const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
2381
+ const base = import_types8.Routes.channelMessages(this.channelId);
2382
+ const data = assertApiArray(
2383
+ await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
2384
+ "messages.fetch()"
2385
+ );
2103
2386
  const collection = new import_collection4.Collection();
2104
- for (const msg of data) collection.set(msg.id, this.wrap(msg));
2387
+ for (const msg of data) {
2388
+ if (!msg?.id) continue;
2389
+ collection.set(msg.id, this.wrap(msg));
2390
+ }
2105
2391
  return collection;
2106
2392
  }
2107
2393
  };
@@ -2205,7 +2491,7 @@ var MessageCollector = class _MessageCollector extends import_node_events2.Event
2205
2491
  };
2206
2492
 
2207
2493
  // src/Domain/Channel/Attachments.ts
2208
- var import_types7 = require("@fluxerjs/types");
2494
+ var import_types9 = require("@fluxerjs/types");
2209
2495
  var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
2210
2496
  var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
2211
2497
  function instanceLimitOverridesSnapshot(client) {
@@ -2250,7 +2536,7 @@ async function putBlob(url, body, contentType) {
2250
2536
  async function uploadAttachmentsForSend(client, channelId, files) {
2251
2537
  assertBotAttachmentLimits(client, files);
2252
2538
  const plan = await client.rest.post(
2253
- import_types7.Routes.channelAttachments(channelId),
2539
+ import_types9.Routes.channelAttachments(channelId),
2254
2540
  {
2255
2541
  body: {
2256
2542
  attachments: files.map((f) => ({
@@ -2296,7 +2582,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
2296
2582
  });
2297
2583
  }
2298
2584
  if (multipart.length) {
2299
- await client.rest.post(import_types7.Routes.channelAttachmentsComplete(channelId), {
2585
+ await client.rest.post(import_types9.Routes.channelAttachmentsComplete(channelId), {
2300
2586
  body: { uploads: multipart },
2301
2587
  auth: true
2302
2588
  });
@@ -2305,6 +2591,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
2305
2591
  }
2306
2592
 
2307
2593
  // src/Domain/Channel/Base.ts
2594
+ function isFullChannelData(data) {
2595
+ return "guild_id" in data || "permission_overwrites" in data || "position" in data || "last_message_id" in data || "topic" in data || "thread_metadata" in data || "available_tags" in data;
2596
+ }
2308
2597
  var Channel = class extends Base {
2309
2598
  #messages;
2310
2599
  /** The {@link Client} that instantiated this channel. */
@@ -2319,6 +2608,11 @@ var Channel = class extends Base {
2319
2608
  icon;
2320
2609
  /** ISO8601 timestamp of the last pinned message update. */
2321
2610
  lastPinTimestamp;
2611
+ /**
2612
+ * True when built from a partial payload (e.g. a DM stub) and not yet hydrated
2613
+ * with a full channel object. `channels.resolve()` refetches partial channels.
2614
+ */
2615
+ partial;
2322
2616
  constructor(client, data) {
2323
2617
  super();
2324
2618
  this.client = client;
@@ -2327,6 +2621,7 @@ var Channel = class extends Base {
2327
2621
  this.name = data.name ?? null;
2328
2622
  this.icon = data.icon ?? null;
2329
2623
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
2624
+ this.partial = !isFullChannelData(data);
2330
2625
  }
2331
2626
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
2332
2627
  get createdTimestamp() {
@@ -2347,6 +2642,7 @@ var Channel = class extends Base {
2347
2642
  if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
2348
2643
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
2349
2644
  }
2645
+ if (isFullChannelData(data)) this.partial = false;
2350
2646
  }
2351
2647
  /** @internal Factory wired after subclasses load. */
2352
2648
  static from(_c, _d) {
@@ -2361,43 +2657,56 @@ var Channel = class extends Base {
2361
2657
  throw new Error("Channel.createDM not initialized");
2362
2658
  }
2363
2659
  /**
2364
- * Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
2660
+ * Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
2661
+ * Forum and media channels contain threads and do not accept `send`.
2365
2662
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
2366
2663
  */
2367
2664
  isTextBased() {
2368
- return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildAnnouncement || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
2665
+ return this.type === import_types10.ChannelType.GuildText || this.type === import_types10.ChannelType.GuildAnnouncement || this.type === import_types10.ChannelType.GuildVoice || this.type === import_types10.ChannelType.DM || this.type === import_types10.ChannelType.GroupDM || this.type === import_types10.ChannelType.DMPersonalNotes || this.type === import_types10.ChannelType.AnnouncementThread || this.type === import_types10.ChannelType.PublicThread || this.type === import_types10.ChannelType.PrivateThread;
2369
2666
  }
2370
- /** Check if this is a guild channel (text, announcement, voice, category, or link). */
2667
+ /** Check if this is a guild channel, including threads, forums, and media channels. */
2371
2668
  isGuild() {
2372
- return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildAnnouncement || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.GuildCategory || this.type === import_types8.ChannelType.GuildLink;
2669
+ return this.type === import_types10.ChannelType.GuildText || this.type === import_types10.ChannelType.GuildAnnouncement || this.type === import_types10.ChannelType.GuildVoice || this.type === import_types10.ChannelType.GuildCategory || this.type === import_types10.ChannelType.GuildLink || this.type === import_types10.ChannelType.AnnouncementThread || this.type === import_types10.ChannelType.PublicThread || this.type === import_types10.ChannelType.PrivateThread || this.type === import_types10.ChannelType.GuildForum || this.type === import_types10.ChannelType.GuildMedia;
2670
+ }
2671
+ /** Check if this is a thread (public, private, or announcement). */
2672
+ isThread() {
2673
+ return this.type === import_types10.ChannelType.AnnouncementThread || this.type === import_types10.ChannelType.PublicThread || this.type === import_types10.ChannelType.PrivateThread;
2674
+ }
2675
+ /** Check if this is a forum channel. */
2676
+ isForum() {
2677
+ return this.type === import_types10.ChannelType.GuildForum;
2678
+ }
2679
+ /** Check if this is a media channel. */
2680
+ isMedia() {
2681
+ return this.type === import_types10.ChannelType.GuildMedia;
2373
2682
  }
2374
2683
  /** Check if this is a guild text channel. */
2375
2684
  isText() {
2376
- return this.type === import_types8.ChannelType.GuildText;
2685
+ return this.type === import_types10.ChannelType.GuildText;
2377
2686
  }
2378
2687
  /** Check if this is a guild announcement channel. */
2379
2688
  isAnnouncement() {
2380
- return this.type === import_types8.ChannelType.GuildAnnouncement;
2689
+ return this.type === import_types10.ChannelType.GuildAnnouncement;
2381
2690
  }
2382
2691
  /** Check if this is a category channel. */
2383
2692
  isCategory() {
2384
- return this.type === import_types8.ChannelType.GuildCategory;
2693
+ return this.type === import_types10.ChannelType.GuildCategory;
2385
2694
  }
2386
2695
  /** Check if this is a DM, group DM, or personal notes channel. */
2387
2696
  isDM() {
2388
- return this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
2697
+ return this.type === import_types10.ChannelType.DM || this.type === import_types10.ChannelType.GroupDM || this.type === import_types10.ChannelType.DMPersonalNotes;
2389
2698
  }
2390
2699
  /** Check if this is a personal notes channel. */
2391
2700
  isPersonalNotes() {
2392
- return this.type === import_types8.ChannelType.DMPersonalNotes;
2701
+ return this.type === import_types10.ChannelType.DMPersonalNotes;
2393
2702
  }
2394
2703
  /** Check if this is a voice channel. */
2395
2704
  isVoice() {
2396
- return this.type === import_types8.ChannelType.GuildVoice;
2705
+ return this.type === import_types10.ChannelType.GuildVoice;
2397
2706
  }
2398
2707
  /** Check if this is a link channel. */
2399
2708
  isLink() {
2400
- return this.type === import_types8.ChannelType.GuildLink;
2709
+ return this.type === import_types10.ChannelType.GuildLink;
2401
2710
  }
2402
2711
  /**
2403
2712
  * Delete recent messages or an explicit ID list.
@@ -2420,7 +2729,7 @@ var Channel = class extends Base {
2420
2729
  }
2421
2730
  if (ids.length === 0) return [];
2422
2731
  if (ids.length === 1) {
2423
- await this.client.rest.delete(import_types8.Routes.channelMessage(this.id, ids[0]), { auth: true });
2732
+ await this.client.rest.delete(import_types10.Routes.channelMessage(this.id, ids[0]), { auth: true });
2424
2733
  this.client._removeMessageFromCache(this.id, ids[0]);
2425
2734
  return ids;
2426
2735
  }
@@ -2429,7 +2738,7 @@ var Channel = class extends Base {
2429
2738
  code: import_util3.ErrorCodes.InvalidBulkDelete
2430
2739
  });
2431
2740
  }
2432
- await this.client.rest.post(import_types8.Routes.channelBulkDelete(this.id), {
2741
+ await this.client.rest.post(import_types10.Routes.channelBulkDelete(this.id), {
2433
2742
  body: { message_ids: ids },
2434
2743
  auth: true
2435
2744
  });
@@ -2439,7 +2748,7 @@ var Channel = class extends Base {
2439
2748
  /** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
2440
2749
  async bulkDeleteMyMessages(options) {
2441
2750
  const body = options ? toSudoBody(options) : void 0;
2442
- await this.client.rest.post(import_types8.Routes.channelBulkDeleteMine(this.id), {
2751
+ await this.client.rest.post(import_types10.Routes.channelBulkDeleteMine(this.id), {
2443
2752
  body: body && Object.keys(body).length ? body : void 0,
2444
2753
  auth: true
2445
2754
  });
@@ -2449,19 +2758,19 @@ var Channel = class extends Base {
2449
2758
  * Session-token helper; bots usually skip this.
2450
2759
  */
2451
2760
  async acknowledgePins() {
2452
- await this.client.rest.post(import_types8.Routes.channelPinsAck(this.id), { auth: true });
2761
+ await this.client.rest.post(import_types10.Routes.channelPinsAck(this.id), { auth: true });
2453
2762
  }
2454
2763
  /**
2455
2764
  * Clear the read state for this channel.
2456
2765
  * Session-token helper; bots usually skip this.
2457
2766
  */
2458
2767
  async clearReadState() {
2459
- await this.client.rest.delete(import_types8.Routes.channelMessagesAck(this.id), { auth: true });
2768
+ await this.client.rest.delete(import_types10.Routes.channelMessagesAck(this.id), { auth: true });
2460
2769
  }
2461
2770
  /** Request upload URLs for attachments before sending a message. */
2462
2771
  async requestAttachmentUploads(attachments) {
2463
2772
  const data = await this.client.rest.post(
2464
- import_types8.Routes.channelAttachments(this.id),
2773
+ import_types10.Routes.channelAttachments(this.id),
2465
2774
  {
2466
2775
  body: toAttachmentUploadPlanBody(attachments),
2467
2776
  auth: true
@@ -2472,7 +2781,7 @@ var Channel = class extends Base {
2472
2781
  /** Complete the attachment upload flow after uploading to the CDN. */
2473
2782
  async completeAttachmentUploads(uploads) {
2474
2783
  const data = await this.client.rest.post(
2475
- import_types8.Routes.channelAttachmentsComplete(this.id),
2784
+ import_types10.Routes.channelAttachmentsComplete(this.id),
2476
2785
  {
2477
2786
  body: toAttachmentUploadCompleteBody(uploads),
2478
2787
  auth: true
@@ -2488,7 +2797,7 @@ var Channel = class extends Base {
2488
2797
  }
2489
2798
  /** Trigger the typing indicator in this channel. */
2490
2799
  async sendTyping() {
2491
- await this.client.rest.post(import_types8.Routes.channelTyping(this.id), { auth: true });
2800
+ await this.client.rest.post(import_types10.Routes.channelTyping(this.id), { auth: true });
2492
2801
  }
2493
2802
  /**
2494
2803
  * Fetch available RTC regions for voice channels.
@@ -2496,7 +2805,7 @@ var Channel = class extends Base {
2496
2805
  * Bots should skip this and join voice with `@fluxerjs/voice` instead.
2497
2806
  */
2498
2807
  async fetchRtcRegions() {
2499
- const data = await this.client.rest.get(import_types8.Routes.channelRtcRegions(this.id), {
2808
+ const data = await this.client.rest.get(import_types10.Routes.channelRtcRegions(this.id), {
2500
2809
  auth: true
2501
2810
  });
2502
2811
  return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
@@ -2504,7 +2813,7 @@ var Channel = class extends Base {
2504
2813
  /** Fetch slowmode state for this channel. */
2505
2814
  async fetchSlowmode() {
2506
2815
  const data = await this.client.rest.get(
2507
- import_types8.Routes.channelSlowmode(this.id),
2816
+ import_types10.Routes.channelSlowmode(this.id),
2508
2817
  { auth: true }
2509
2818
  );
2510
2819
  return {
@@ -2551,7 +2860,7 @@ var Channel = class extends Base {
2551
2860
  const qs2 = params.toString();
2552
2861
  const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
2553
2862
  const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2554
- await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2863
+ await this.client.rest.delete(import_types10.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2555
2864
  body,
2556
2865
  auth: true,
2557
2866
  ...auditReasonHeaders(_reason)
@@ -2569,17 +2878,17 @@ var Channel = class extends Base {
2569
2878
  };
2570
2879
 
2571
2880
  // src/Domain/Channel/Dm.ts
2572
- var import_types10 = require("@fluxerjs/types");
2881
+ var import_types12 = require("@fluxerjs/types");
2573
2882
 
2574
2883
  // src/Domain/Channel/TextCapable.ts
2575
- var import_types9 = require("@fluxerjs/types");
2884
+ var import_types11 = require("@fluxerjs/types");
2576
2885
  async function fetchPinnedMessagesPageFor(client, channelId, options) {
2577
2886
  const params = new URLSearchParams();
2578
2887
  if (options?.limit != null) params.set("limit", String(options.limit));
2579
2888
  if (options?.before) params.set("before", options.before);
2580
2889
  const qs2 = params.toString();
2581
2890
  const data = await client.rest.get(
2582
- import_types9.Routes.channelPins(channelId) + (qs2 ? `?${qs2}` : "")
2891
+ import_types11.Routes.channelPins(channelId) + (qs2 ? `?${qs2}` : "")
2583
2892
  );
2584
2893
  const items = data.items ?? [];
2585
2894
  return {
@@ -2625,7 +2934,7 @@ var DMChannel = class extends TextCapable(Channel) {
2625
2934
  const full = data;
2626
2935
  this.lastMessageId = full.last_message_id ?? null;
2627
2936
  this.ownerId = full.owner_id ?? null;
2628
- this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
2937
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
2629
2938
  this.nicks = full.nicks ?? {};
2630
2939
  }
2631
2940
  /**
@@ -2640,7 +2949,7 @@ var DMChannel = class extends TextCapable(Channel) {
2640
2949
  }
2641
2950
  if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2642
2951
  if ("recipients" in full && full.recipients !== void 0) {
2643
- this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2952
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
2644
2953
  }
2645
2954
  if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2646
2955
  }
@@ -2649,7 +2958,7 @@ var DMChannel = class extends TextCapable(Channel) {
2649
2958
  * Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
2650
2959
  */
2651
2960
  async edit(options) {
2652
- const data = await this.client.rest.patch(import_types10.Routes.channel(this.id), {
2961
+ const data = await this.client.rest.patch(import_types12.Routes.channel(this.id), {
2653
2962
  body: toGroupDmEditBody(options),
2654
2963
  auth: true
2655
2964
  });
@@ -2661,13 +2970,13 @@ var DMChannel = class extends TextCapable(Channel) {
2661
2970
  * Notes-only; bots usually skip this.
2662
2971
  */
2663
2972
  async purgeMessages() {
2664
- if (this.type !== import_types10.ChannelType.DMPersonalNotes) {
2973
+ if (this.type !== import_types12.ChannelType.DMPersonalNotes) {
2665
2974
  throw new import_util4.FluxerError("purgeMessages is only available on personal notes channels", {
2666
2975
  code: import_util3.ErrorCodes.InvalidChannelType
2667
2976
  });
2668
2977
  }
2669
2978
  const data = await this.client.rest.post(
2670
- import_types10.Routes.channelMessagesPurge(this.id),
2979
+ import_types12.Routes.channelMessagesPurge(this.id),
2671
2980
  { auth: true }
2672
2981
  );
2673
2982
  return data.deleted_count;
@@ -2677,54 +2986,59 @@ var DMChannel = class extends TextCapable(Channel) {
2677
2986
  * Session-token helper; bots usually skip this.
2678
2987
  */
2679
2988
  async pinInList() {
2680
- await this.client.rest.put(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
2989
+ await this.client.rest.put(import_types12.Routes.userMeChannelPin(this.id), { auth: true });
2681
2990
  }
2682
2991
  /**
2683
2992
  * Unpin this DM channel from the DM list.
2684
2993
  * Session-token helper; bots usually skip this.
2685
2994
  */
2686
2995
  async unpinFromList() {
2687
- await this.client.rest.delete(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
2996
+ await this.client.rest.delete(import_types12.Routes.userMeChannelPin(this.id), { auth: true });
2688
2997
  }
2689
2998
  /**
2690
2999
  * Add a user to this group DM.
2691
3000
  * Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
2692
3001
  */
2693
3002
  async addRecipient(userId) {
2694
- await this.client.rest.put(import_types10.Routes.channelRecipient(this.id, userId), { auth: true });
3003
+ await this.client.rest.put(import_types12.Routes.channelRecipient(this.id, userId), { auth: true });
2695
3004
  const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
2696
3005
  if (user) this.recipients.push(user);
2697
3006
  }
2698
3007
  /** Remove a user from this group DM. */
2699
3008
  async removeRecipient(userId, options) {
2700
- const url = import_types10.Routes.channelRecipient(this.id, userId) + (options?.silent ? "?silent=true" : "");
3009
+ const url = import_types12.Routes.channelRecipient(this.id, userId) + (options?.silent ? "?silent=true" : "");
2701
3010
  await this.client.rest.delete(url, { auth: true });
2702
3011
  const idx = this.recipients.findIndex((u) => u.id === userId);
2703
3012
  if (idx >= 0) this.recipients.splice(idx, 1);
2704
3013
  }
2705
3014
  };
2706
3015
 
3016
+ // src/Domain/Channel/Forum.ts
3017
+ var import_types19 = require("@fluxerjs/types");
3018
+
2707
3019
  // src/Domain/Channel/Guild.ts
2708
- var import_types14 = require("@fluxerjs/types");
3020
+ var import_types16 = require("@fluxerjs/types");
2709
3021
  var import_util13 = require("@fluxerjs/util");
2710
3022
 
2711
3023
  // src/Domain/Invite.ts
2712
- var import_types11 = require("@fluxerjs/types");
3024
+ var import_types13 = require("@fluxerjs/types");
2713
3025
 
2714
3026
  // src/Helpers/Instance.ts
2715
3027
  var import_util9 = require("@fluxerjs/util");
2716
3028
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2717
- api: "https://web.fluxer.app/api",
2718
- api_client: "https://web.fluxer.app/api",
2719
- api_public: "https://api.fluxer.app",
2720
- gateway: "wss://gateway.fluxer.app",
3029
+ api: "https://fluxer.com/api",
3030
+ api_client: "https://fluxer.com/api",
3031
+ api_public: "https://fluxer.com/api",
3032
+ gateway: "wss://gateway.fluxer.com",
2721
3033
  media: CDN_URL,
3034
+ upload_relay: "https://uploads.fluxer.app",
2722
3035
  static_cdn: STATIC_CDN_URL,
2723
- marketing: "https://fluxer.app",
3036
+ marketing: "https://fluxer.com",
3037
+ docs: "https://docs.fluxer.com",
2724
3038
  admin: "https://admin.fluxer.app",
2725
3039
  invite: "https://fluxer.gg",
2726
3040
  gift: "https://fluxer.gift",
2727
- webapp: "https://web.fluxer.app"
3041
+ webapp: "https://fluxer.com"
2728
3042
  });
2729
3043
  var ENDPOINT_KEYS = [
2730
3044
  "api",
@@ -2739,6 +3053,11 @@ var ENDPOINT_KEYS = [
2739
3053
  "gift",
2740
3054
  "webapp"
2741
3055
  ];
3056
+ var OPTIONAL_ENDPOINT_KEYS = [
3057
+ "api_transport",
3058
+ "upload_relay",
3059
+ "docs"
3060
+ ];
2742
3061
  function requireString(obj, key, path) {
2743
3062
  const value = obj[key];
2744
3063
  if (typeof value !== "string" || value.length === 0) {
@@ -2779,6 +3098,10 @@ function parseInstanceDiscovery(raw) {
2779
3098
  for (const key of ENDPOINT_KEYS) {
2780
3099
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2781
3100
  }
3101
+ for (const key of OPTIONAL_ENDPOINT_KEYS) {
3102
+ const value = raw.endpoints[key];
3103
+ if (typeof value === "string" && value.length > 0) endpoints[key] = value;
3104
+ }
2782
3105
  endpoints.api = normalizeApiOrigin(endpoints.api);
2783
3106
  endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2784
3107
  endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
@@ -2832,7 +3155,21 @@ function parseInstanceDiscovery(raw) {
2832
3155
  defaultsHash: ""
2833
3156
  },
2834
3157
  push: raw.push ?? { public_vapid_key: null },
2835
- app_public: raw.app_public ?? {}
3158
+ app_public: raw.app_public ?? {},
3159
+ ...typeof raw.codename === "string" ? { codename: raw.codename } : {},
3160
+ age_policy: (0, import_util9.isRecord)(raw.age_policy) ? raw.age_policy : { geos: [] },
3161
+ ...raw.notice === null || (0, import_util9.isRecord)(raw.notice) ? { notice: raw.notice } : {},
3162
+ ...(0, import_util9.isRecord)(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
3163
+ ...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
3164
+ ...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
3165
+ ...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
3166
+ ...(0, import_util9.isRecord)(raw.built_in_guild_badge_images) ? {
3167
+ built_in_guild_badge_images: raw.built_in_guild_badge_images
3168
+ } : {},
3169
+ ...Array.isArray(raw.hidden_built_in_guild_badges) ? {
3170
+ hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
3171
+ } : {},
3172
+ ...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
2836
3173
  };
2837
3174
  }
2838
3175
  function resolveInstanceEndpoints(input) {
@@ -2852,7 +3189,7 @@ function resolveInstanceEndpoints(input) {
2852
3189
  }
2853
3190
  const partial = input;
2854
3191
  const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
2855
- for (const key of ENDPOINT_KEYS) {
3192
+ for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
2856
3193
  const value = partial[key];
2857
3194
  if (typeof value === "string" && value.length > 0) {
2858
3195
  merged[key] = value;
@@ -2958,11 +3295,11 @@ var Invite = class _Invite extends Base {
2958
3295
  this.client = client;
2959
3296
  this.code = data.code;
2960
3297
  this.type = data.type;
2961
- this.guildSnapshot = (0, import_types11.isGuildInvite)(data) ? toInviteGuild(data.guild) : null;
2962
- this.channelSnapshot = (0, import_types11.isGuildInvite)(data) || (0, import_types11.isGroupDmInvite)(data) ? toInviteChannel(data.channel) : null;
3298
+ this.guildSnapshot = (0, import_types13.isGuildInvite)(data) ? toInviteGuild(data.guild) : null;
3299
+ this.channelSnapshot = (0, import_types13.isGuildInvite)(data) || (0, import_types13.isGroupDmInvite)(data) ? toInviteChannel(data.channel) : null;
2963
3300
  this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
2964
3301
  this.memberCount = data.member_count ?? null;
2965
- this.presenceCount = (0, import_types11.isGuildInvite)(data) ? data.presence_count ?? null : null;
3302
+ this.presenceCount = (0, import_types13.isGuildInvite)(data) ? data.presence_count ?? null : null;
2966
3303
  this.expiresAt = parseOptionalDate(data.expires_at);
2967
3304
  this.temporary = data.temporary ?? null;
2968
3305
  this.createdAt = parseOptionalDate(data.created_at);
@@ -2971,10 +3308,10 @@ var Invite = class _Invite extends Base {
2971
3308
  this.maxAge = data.max_age ?? null;
2972
3309
  }
2973
3310
  isGuild() {
2974
- return this.type === import_types11.InviteType.Guild;
3311
+ return this.type === import_types13.InviteType.Guild;
2975
3312
  }
2976
3313
  isGroupDM() {
2977
- return this.type === import_types11.InviteType.GroupDM;
3314
+ return this.type === import_types13.InviteType.GroupDM;
2978
3315
  }
2979
3316
  /** Full invite URL (uses this client's instance invite base). */
2980
3317
  get url() {
@@ -2998,18 +3335,18 @@ var Invite = class _Invite extends Base {
2998
3335
  }
2999
3336
  /** Fetch invite metadata by code or URL (does not join). */
3000
3337
  static async fetch(client, codeOrUrl) {
3001
- const data = await client.rest.get(import_types11.Routes.invite(parseInviteCode(codeOrUrl)));
3338
+ const data = await client.rest.get(import_types13.Routes.invite(parseInviteCode(codeOrUrl)));
3002
3339
  return new _Invite(client, data);
3003
3340
  }
3004
3341
  /** Delete this invite. Requires Manage Guild or Create Instant Invite. */
3005
3342
  async delete() {
3006
- await this.client.rest.delete(import_types11.Routes.invite(this.code), { auth: true });
3343
+ await this.client.rest.delete(import_types13.Routes.invite(this.code), { auth: true });
3007
3344
  }
3008
3345
  };
3009
3346
 
3010
3347
  // src/Domain/Webhook.ts
3011
3348
  var import_builders4 = require("@fluxerjs/builders");
3012
- var import_types12 = require("@fluxerjs/types");
3349
+ var import_types14 = require("@fluxerjs/types");
3013
3350
  var import_util10 = require("@fluxerjs/util");
3014
3351
  var Webhook = class _Webhook extends Base {
3015
3352
  /** Parent client instance. */
@@ -3028,6 +3365,8 @@ var Webhook = class _Webhook extends Base {
3028
3365
  token;
3029
3366
  /** The user that created this webhook. */
3030
3367
  user;
3368
+ /** Incoming or channel-follower webhook. */
3369
+ type;
3031
3370
  constructor(client, data) {
3032
3371
  super();
3033
3372
  this.client = client;
@@ -3038,6 +3377,7 @@ var Webhook = class _Webhook extends Base {
3038
3377
  this.avatar = data.avatar ?? null;
3039
3378
  this.token = data.token ?? null;
3040
3379
  this.user = client.getOrCreateUser(data.user);
3380
+ this.type = data.type ?? import_types14.WebhookType.Incoming;
3041
3381
  }
3042
3382
  avatarURL(options) {
3043
3383
  return cdnAvatarURL(this.id, this.avatar, {
@@ -3056,10 +3396,10 @@ var Webhook = class _Webhook extends Base {
3056
3396
  /** Delete this webhook (token auth when available, otherwise bot auth). */
3057
3397
  async delete() {
3058
3398
  if (this.token) {
3059
- await this.client.rest.delete(import_types12.Routes.webhookExecute(this.id, this.token), { auth: false });
3399
+ await this.client.rest.delete(import_types14.Routes.webhookExecute(this.id, this.token), { auth: false });
3060
3400
  return;
3061
3401
  }
3062
- await this.client.rest.delete(import_types12.Routes.webhook(this.id), { auth: true });
3402
+ await this.client.rest.delete(import_types14.Routes.webhook(this.id), { auth: true });
3063
3403
  }
3064
3404
  /**
3065
3405
  * Edit name/avatar. With bot auth (no token), `channelId` may also be set.
@@ -3071,10 +3411,10 @@ var Webhook = class _Webhook extends Base {
3071
3411
  if (!this.token && options.channelId !== void 0) {
3072
3412
  body.channel_id = options.channelId;
3073
3413
  }
3074
- const data = this.token ? await this.client.rest.patch(import_types12.Routes.webhookExecute(this.id, this.token), {
3414
+ const data = this.token ? await this.client.rest.patch(import_types14.Routes.webhookExecute(this.id, this.token), {
3075
3415
  body,
3076
3416
  auth: false
3077
- }) : await this.client.rest.patch(import_types12.Routes.webhook(this.id), { body, auth: true });
3417
+ }) : await this.client.rest.patch(import_types14.Routes.webhook(this.id), { body, auth: true });
3078
3418
  this.name = data.name ?? this.name;
3079
3419
  this.avatar = data.avatar ?? null;
3080
3420
  if (!this.token) this.channelId = data.channel_id ?? this.channelId;
@@ -3095,7 +3435,7 @@ var Webhook = class _Webhook extends Base {
3095
3435
  if (overrides.avatarUrl !== void 0) {
3096
3436
  body.avatar_url = overrides.avatarUrl;
3097
3437
  }
3098
- const route = `${import_types12.Routes.webhookExecute(this.id, token)}${wait ? "?wait=true" : ""}`;
3438
+ const route = `${import_types14.Routes.webhookExecute(this.id, token)}${wait ? "?wait=true" : ""}`;
3099
3439
  const data = await this.client.rest.post(route, {
3100
3440
  body,
3101
3441
  ...files?.length ? { files } : {},
@@ -3136,7 +3476,7 @@ var Webhook = class _Webhook extends Base {
3136
3476
  }
3137
3477
  /** Fetch a webhook by ID (bot auth; no token). */
3138
3478
  static async fetch(client, webhookId) {
3139
- const data = await client.rest.get(import_types12.Routes.webhook(webhookId));
3479
+ const data = await client.rest.get(import_types14.Routes.webhook(webhookId));
3140
3480
  return new _Webhook(client, data);
3141
3481
  }
3142
3482
  /** Build a webhook from a stored id + token (e.g. webhook URL). */
@@ -3148,6 +3488,7 @@ var Webhook = class _Webhook extends Base {
3148
3488
  name: options?.name ?? "Webhook",
3149
3489
  avatar: null,
3150
3490
  token,
3491
+ type: import_types14.WebhookType.Incoming,
3151
3492
  user: {
3152
3493
  id: "",
3153
3494
  username: "webhook",
@@ -3169,13 +3510,13 @@ var Webhook = class _Webhook extends Base {
3169
3510
  return this.token;
3170
3511
  }
3171
3512
  messageRoute(messageId) {
3172
- return import_types12.Routes.webhookMessage(this.id, this.requireToken(), messageId);
3513
+ return import_types14.Routes.webhookMessage(this.id, this.requireToken(), messageId);
3173
3514
  }
3174
3515
  };
3175
3516
 
3176
3517
  // src/Domain/Channel/PermissionOverwriteManager.ts
3177
3518
  var import_collection6 = require("@fluxerjs/collection");
3178
- var import_types13 = require("@fluxerjs/types");
3519
+ var import_types15 = require("@fluxerjs/types");
3179
3520
  var import_util12 = require("@fluxerjs/util");
3180
3521
 
3181
3522
  // src/Domain/Channel/PermissionOverwrite.ts
@@ -3237,7 +3578,7 @@ var PermissionOverwriteManager = class {
3237
3578
  async edit(overwriteId, options) {
3238
3579
  const allow = options.allow !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.allow) : "0";
3239
3580
  const deny = options.deny !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.deny) : "0";
3240
- await this.channel.client.rest.put(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
3581
+ await this.channel.client.rest.put(import_types15.Routes.channelPermission(this.channel.id, overwriteId), {
3241
3582
  body: { type: options.type, allow, deny },
3242
3583
  auth: true
3243
3584
  });
@@ -3253,7 +3594,7 @@ var PermissionOverwriteManager = class {
3253
3594
  }
3254
3595
  /** Delete a permission overwrite. */
3255
3596
  async delete(overwriteId) {
3256
- await this.channel.client.rest.delete(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
3597
+ await this.channel.client.rest.delete(import_types15.Routes.channelPermission(this.channel.id, overwriteId), {
3257
3598
  auth: true
3258
3599
  });
3259
3600
  this._cache.delete(overwriteId);
@@ -3267,6 +3608,23 @@ var PermissionOverwriteManager = class {
3267
3608
  }
3268
3609
  };
3269
3610
 
3611
+ // src/Domain/Channel/ThreadBind.ts
3612
+ var factory;
3613
+ var managers = /* @__PURE__ */ new WeakMap();
3614
+ function bindThreadManager(next) {
3615
+ factory = next;
3616
+ }
3617
+ function threadManagerFor(channel) {
3618
+ const existing = managers.get(channel);
3619
+ if (existing) return existing;
3620
+ if (!factory) {
3621
+ throw new Error("ThreadManager is not initialized");
3622
+ }
3623
+ const created = factory(channel);
3624
+ managers.set(channel, created);
3625
+ return created;
3626
+ }
3627
+
3270
3628
  // src/Domain/Channel/Guild.ts
3271
3629
  var GuildChannel = class extends Channel {
3272
3630
  /** Guild ID this channel belongs to, or null if missing from the payload. */
@@ -3304,7 +3662,7 @@ var GuildChannel = class extends Channel {
3304
3662
  }
3305
3663
  /** Create a webhook for this channel. Requires Manage Webhooks. */
3306
3664
  async createWebhook(options) {
3307
- const data = await this.client.rest.post(import_types14.Routes.channelWebhooks(this.id), {
3665
+ const data = await this.client.rest.post(import_types16.Routes.channelWebhooks(this.id), {
3308
3666
  body: options,
3309
3667
  auth: true
3310
3668
  });
@@ -3312,13 +3670,13 @@ var GuildChannel = class extends Channel {
3312
3670
  }
3313
3671
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
3314
3672
  async fetchWebhooks() {
3315
- const data = await this.client.rest.get(import_types14.Routes.channelWebhooks(this.id));
3673
+ const data = await this.client.rest.get(import_types16.Routes.channelWebhooks(this.id));
3316
3674
  return data.map((w) => new Webhook(this.client, w));
3317
3675
  }
3318
3676
  /** Create an invite for this channel. Requires Create Instant Invite. */
3319
3677
  async createInvite(options) {
3320
3678
  const body = options ? toChannelInviteBody(options) : {};
3321
- const data = await this.client.rest.post(import_types14.Routes.channelInvites(this.id), {
3679
+ const data = await this.client.rest.post(import_types16.Routes.channelInvites(this.id), {
3322
3680
  body: Object.keys(body).length ? body : void 0,
3323
3681
  auth: true
3324
3682
  });
@@ -3326,7 +3684,7 @@ var GuildChannel = class extends Channel {
3326
3684
  }
3327
3685
  /** Fetch all invites for this channel. Requires Manage Channels. */
3328
3686
  async fetchInvites() {
3329
- const data = await this.client.rest.get(import_types14.Routes.channelInvites(this.id));
3687
+ const data = await this.client.rest.get(import_types16.Routes.channelInvites(this.id));
3330
3688
  return data.map((i) => new Invite(this.client, i));
3331
3689
  }
3332
3690
  /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
@@ -3356,7 +3714,7 @@ var GuildChannel = class extends Channel {
3356
3714
  }
3357
3715
  /** Edit this channel's settings. Requires Manage Channels. */
3358
3716
  async edit(options) {
3359
- const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
3717
+ const data = await this.client.rest.patch(import_types16.Routes.channel(this.id), {
3360
3718
  body: toChannelEditBody(options),
3361
3719
  auth: true,
3362
3720
  ...auditReasonHeaders(options.reason)
@@ -3387,6 +3745,10 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3387
3745
  contentWarningLevel;
3388
3746
  /** Custom content warning text. */
3389
3747
  contentWarningText;
3748
+ /** Default auto-archive duration in minutes for new threads. */
3749
+ defaultAutoArchiveDuration;
3750
+ /** Slowmode in seconds copied onto new threads. */
3751
+ defaultThreadRateLimitPerUser;
3390
3752
  constructor(client, data) {
3391
3753
  super(client, data);
3392
3754
  this.topic = data.topic ?? null;
@@ -3396,6 +3758,12 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3396
3758
  this.lastMessageId = data.last_message_id ?? null;
3397
3759
  this.contentWarningLevel = data.content_warning_level ?? null;
3398
3760
  this.contentWarningText = data.content_warning_text ?? null;
3761
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
3762
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
3763
+ }
3764
+ /** Create, list, and search threads in this channel. */
3765
+ get threads() {
3766
+ return threadManagerFor(this);
3399
3767
  }
3400
3768
  /**
3401
3769
  * Set slowmode (seconds between messages). Pass `0` to disable.
@@ -3416,9 +3784,45 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3416
3784
  if ("content_warning_text" in data) {
3417
3785
  this.contentWarningText = data.content_warning_text ?? null;
3418
3786
  }
3787
+ if ("default_auto_archive_duration" in data) {
3788
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
3789
+ }
3790
+ if ("default_thread_rate_limit_per_user" in data) {
3791
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
3792
+ }
3793
+ }
3794
+ /**
3795
+ * Set the auto-archive and slowmode defaults copied onto new threads.
3796
+ * Sends only those fields. The thread-parent update body does not accept a channel rename.
3797
+ */
3798
+ async editThreadDefaults(options) {
3799
+ const data = await this.client.rest.patch(import_types16.Routes.channel(this.id), {
3800
+ body: toThreadParentEditBody(options),
3801
+ auth: true,
3802
+ ...auditReasonHeaders(options.reason)
3803
+ });
3804
+ this._patch(data);
3805
+ return this;
3419
3806
  }
3420
3807
  };
3421
3808
  var AnnouncementChannel = class extends TextChannel {
3809
+ /**
3810
+ * Follow this announcement channel into `webhookChannelId` (a channel in a guild
3811
+ * where the bot can manage webhooks). Published messages are copied there.
3812
+ */
3813
+ async follow(webhookChannelId) {
3814
+ return this.client.rest.post(
3815
+ import_types16.Routes.channelFollowers(this.id),
3816
+ { body: { webhook_channel_id: webhookChannelId }, auth: true }
3817
+ );
3818
+ }
3819
+ /** Fetch follower counts for this announcement channel. */
3820
+ async fetchFollowerStats() {
3821
+ return this.client.rest.get(
3822
+ import_types16.Routes.channelFollowerStats(this.id),
3823
+ { auth: true }
3824
+ );
3825
+ }
3422
3826
  };
3423
3827
  var CategoryChannel = class extends GuildChannel {
3424
3828
  };
@@ -3445,6 +3849,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3445
3849
  voiceConnectionLimit;
3446
3850
  /** RTC region override for this channel. */
3447
3851
  rtcRegion;
3852
+ /** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
3853
+ rtcP2p;
3448
3854
  constructor(client, data) {
3449
3855
  super(client, data);
3450
3856
  this.topic = data.topic ?? null;
@@ -3458,6 +3864,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3458
3864
  this.userLimit = data.user_limit ?? null;
3459
3865
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3460
3866
  this.rtcRegion = data.rtc_region ?? null;
3867
+ this.rtcP2p = data.rtc_p2p ?? false;
3461
3868
  }
3462
3869
  /**
3463
3870
  * Set slowmode (seconds between messages). Pass `0` to disable.
@@ -3484,40 +3891,537 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3484
3891
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3485
3892
  }
3486
3893
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
3894
+ if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
3895
+ }
3896
+ };
3897
+ var LinkChannel = class extends GuildChannel {
3898
+ /** External URL this channel links to. */
3899
+ url;
3900
+ constructor(client, data) {
3901
+ super(client, data);
3902
+ this.url = data.url ?? null;
3903
+ }
3904
+ applyEditPatch(data) {
3905
+ if ("url" in data) this.url = data.url ?? null;
3906
+ }
3907
+ };
3908
+
3909
+ // src/Domain/Channel/ThreadManager.ts
3910
+ var import_types18 = require("@fluxerjs/types");
3911
+
3912
+ // src/Domain/Channel/ThreadChannel.ts
3913
+ var import_types17 = require("@fluxerjs/types");
3914
+ var ThreadMember = class {
3915
+ /** Thread ID. */
3916
+ id;
3917
+ /** User ID. */
3918
+ userId;
3919
+ /** When the user last joined the thread. */
3920
+ joinedAt;
3921
+ /** Thread member flags bitfield. */
3922
+ flags;
3923
+ /** Whether the current user has muted the thread. */
3924
+ muted;
3925
+ /** ISO-8601 timestamp when the mute expires, if set. */
3926
+ muteEndTime;
3927
+ /** Selected mute duration in seconds, if set. */
3928
+ muteWindow;
3929
+ constructor(data) {
3930
+ this.id = data.id ?? null;
3931
+ this.userId = data.user_id ?? data.member?.user?.id ?? null;
3932
+ this.joinedAt = new Date(data.join_timestamp);
3933
+ this.flags = data.flags;
3934
+ this.muted = data.muted ?? null;
3935
+ this.muteEndTime = data.mute_config?.end_time ?? null;
3936
+ this.muteWindow = data.mute_config?.selected_time_window ?? null;
3937
+ }
3938
+ };
3939
+ function threadEditFields(options) {
3940
+ const source = options;
3941
+ return {
3942
+ name: typeof source.name === "string" ? source.name : void 0,
3943
+ archived: source.archived,
3944
+ autoArchiveDuration: source.autoArchiveDuration,
3945
+ locked: source.locked,
3946
+ rateLimitPerUser: source.rateLimitPerUser,
3947
+ flags: source.flags,
3948
+ appliedTags: source.appliedTags,
3949
+ invitable: source.invitable,
3950
+ reason: source.reason
3951
+ };
3952
+ }
3953
+ function readMetadata(data) {
3954
+ return {
3955
+ archived: data?.archived ?? false,
3956
+ autoArchiveDuration: data?.auto_archive_duration ?? 0,
3957
+ archiveTimestamp: data?.archive_timestamp ?? null,
3958
+ locked: data?.locked ?? false,
3959
+ invitable: data?.invitable ?? null
3960
+ };
3961
+ }
3962
+ var ThreadChannel = class extends TextCapable(GuildChannel) {
3963
+ /** User who created the thread. */
3964
+ ownerId;
3965
+ /** Whether the thread is archived. */
3966
+ archived;
3967
+ /** Minutes of inactivity before the thread archives. */
3968
+ autoArchiveDuration;
3969
+ /** ISO-8601 timestamp when the archive status last changed. */
3970
+ archiveTimestamp;
3971
+ /** Whether only moderators can unarchive the thread. */
3972
+ locked;
3973
+ /** Whether non-moderators can add other non-moderators. Private threads only. */
3974
+ invitable;
3975
+ /** Slowmode in seconds. */
3976
+ rateLimitPerUser;
3977
+ /** ID of the last message sent in this thread. */
3978
+ lastMessageId;
3979
+ /** Messages in the thread, excluding the starter and deleted messages. */
3980
+ messageCount;
3981
+ /** Messages ever sent in the thread. This count is never decremented. */
3982
+ totalMessageSent;
3983
+ /** Approximate member count, capped at 50. */
3984
+ memberCount;
3985
+ /** Tag IDs applied to a forum or media post. */
3986
+ appliedTags;
3987
+ /** Channel flags bitfield. */
3988
+ flags;
3989
+ /** The current user's membership, when the payload included it. */
3990
+ member;
3991
+ /** Add, remove, and list members of this thread. */
3992
+ members;
3993
+ constructor(client, data) {
3994
+ super(client, data);
3995
+ const metadata = readMetadata(data.thread_metadata);
3996
+ this.ownerId = data.owner_id ?? null;
3997
+ this.archived = metadata.archived;
3998
+ this.autoArchiveDuration = metadata.autoArchiveDuration;
3999
+ this.archiveTimestamp = metadata.archiveTimestamp;
4000
+ this.locked = metadata.locked;
4001
+ this.invitable = metadata.invitable;
4002
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
4003
+ this.lastMessageId = data.last_message_id ?? null;
4004
+ this.messageCount = data.message_count ?? 0;
4005
+ this.totalMessageSent = data.total_message_sent ?? 0;
4006
+ this.memberCount = data.member_count ?? 0;
4007
+ this.appliedTags = data.applied_tags ?? [];
4008
+ this.flags = data.flags ?? 0;
4009
+ this.member = data.member ? new ThreadMember(data.member) : null;
4010
+ this.members = new ThreadMemberManager(this);
4011
+ }
4012
+ /** @internal */
4013
+ _patch(data) {
4014
+ super._patch(data);
4015
+ if (data.owner_id !== void 0) this.ownerId = data.owner_id ?? null;
4016
+ if (data.thread_metadata) {
4017
+ const metadata = readMetadata(data.thread_metadata);
4018
+ this.archived = metadata.archived;
4019
+ this.autoArchiveDuration = metadata.autoArchiveDuration;
4020
+ this.archiveTimestamp = metadata.archiveTimestamp;
4021
+ this.locked = metadata.locked;
4022
+ this.invitable = metadata.invitable;
4023
+ }
4024
+ if ("rate_limit_per_user" in data && data.rate_limit_per_user !== void 0) {
4025
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
4026
+ }
4027
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
4028
+ if (data.message_count !== void 0) this.messageCount = data.message_count;
4029
+ if (data.total_message_sent !== void 0) this.totalMessageSent = data.total_message_sent;
4030
+ if (data.member_count !== void 0) this.memberCount = data.member_count;
4031
+ if (data.applied_tags !== void 0) this.appliedTags = data.applied_tags ?? [];
4032
+ if (data.flags !== void 0) this.flags = data.flags;
4033
+ if (data.member !== void 0) this.member = data.member ? new ThreadMember(data.member) : null;
4034
+ }
4035
+ /**
4036
+ * Edit this thread. Requires Manage Threads on public threads, or ownership on private ones.
4037
+ * `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
4038
+ */
4039
+ async edit(options) {
4040
+ const data = await this.client.rest.patch(import_types17.Routes.channel(this.id), {
4041
+ body: toThreadEditBody(this.type, threadEditFields(options)),
4042
+ auth: true,
4043
+ ...auditReasonHeaders(options.reason)
4044
+ });
4045
+ this._patch(data);
4046
+ return this;
4047
+ }
4048
+ /** Archive or unarchive this thread. */
4049
+ async setArchived(archived, reason) {
4050
+ return this.edit({ archived, reason });
4051
+ }
4052
+ /** Lock or unlock this thread. Locked threads can only be unarchived by moderators. */
4053
+ async setLocked(locked, reason) {
4054
+ return this.edit({ locked, reason });
4055
+ }
4056
+ /** Join this thread. */
4057
+ async join() {
4058
+ await this.client.rest.put(import_types17.Routes.channelThreadMemberMe(this.id), { auth: true });
4059
+ }
4060
+ /** Leave this thread. */
4061
+ async leave() {
4062
+ await this.client.rest.delete(import_types17.Routes.channelThreadMemberMe(this.id), { auth: true });
4063
+ }
4064
+ /** Update the current user's notification settings for this thread. */
4065
+ async editSelf(options) {
4066
+ const data = await this.client.rest.patch(
4067
+ import_types17.Routes.channelThreadMemberMeSettings(this.id),
4068
+ { body: toThreadMemberSettingsBody(options), auth: true }
4069
+ );
4070
+ this.member = data ? new ThreadMember(data) : null;
4071
+ return this.member;
4072
+ }
4073
+ };
4074
+ var ThreadMemberManager = class {
4075
+ constructor(thread) {
4076
+ this.thread = thread;
4077
+ }
4078
+ /** List members of this thread. */
4079
+ async fetch(options) {
4080
+ const data = await this.thread.client.rest.get(
4081
+ withQuery(import_types17.Routes.channelThreadMembers(this.thread.id), {
4082
+ with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
4083
+ after: options?.after,
4084
+ limit: options?.limit
4085
+ })
4086
+ );
4087
+ return data.map((member) => new ThreadMember(member));
4088
+ }
4089
+ /** Fetch one member of this thread. */
4090
+ async fetchOne(userId, options) {
4091
+ const data = await this.thread.client.rest.get(
4092
+ withQuery(import_types17.Routes.channelThreadMember(this.thread.id, userId), {
4093
+ with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
4094
+ })
4095
+ );
4096
+ return new ThreadMember(data);
4097
+ }
4098
+ /** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
4099
+ async add(userId) {
4100
+ await this.thread.client.rest.put(import_types17.Routes.channelThreadMember(this.thread.id, userId), {
4101
+ auth: true
4102
+ });
4103
+ }
4104
+ /** Remove a user from this thread. */
4105
+ async remove(userId) {
4106
+ await this.thread.client.rest.delete(import_types17.Routes.channelThreadMember(this.thread.id, userId), {
4107
+ auth: true
4108
+ });
4109
+ }
4110
+ };
4111
+ function isThreadType(type) {
4112
+ return type === import_types17.ChannelType.AnnouncementThread || type === import_types17.ChannelType.PublicThread || type === import_types17.ChannelType.PrivateThread;
4113
+ }
4114
+
4115
+ // src/Domain/Channel/ThreadManager.ts
4116
+ var ThreadManager = class {
4117
+ constructor(channel) {
4118
+ this.channel = channel;
4119
+ }
4120
+ /**
4121
+ * Start a thread in a text or announcement channel.
4122
+ * Forum and media channels must use {@link createPost}.
4123
+ */
4124
+ async create(options) {
4125
+ if (this.channel.type === import_types18.ChannelType.GuildForum || this.channel.type === import_types18.ChannelType.GuildMedia) {
4126
+ throw new import_util4.FluxerError("Forum and media channels start posts with createPost", {
4127
+ code: import_util3.ErrorCodes.InvalidChannelType
4128
+ });
4129
+ }
4130
+ const data = await this.channel.client.rest.post(
4131
+ import_types18.Routes.channelThreads(this.channel.id),
4132
+ {
4133
+ body: toStartThreadBody(this.channel.type, options),
4134
+ auth: true,
4135
+ ...auditReasonHeaders(options.reason)
4136
+ }
4137
+ );
4138
+ return cacheThread(this.channel.client, data);
4139
+ }
4140
+ /**
4141
+ * Start a post in a forum or media channel.
4142
+ * The post is a public thread. `message` is its first message.
4143
+ */
4144
+ async createPost(options) {
4145
+ if (this.channel.type !== import_types18.ChannelType.GuildForum && this.channel.type !== import_types18.ChannelType.GuildMedia) {
4146
+ throw new import_util4.FluxerError("createPost is for forum and media channels", {
4147
+ code: import_util3.ErrorCodes.InvalidChannelType
4148
+ });
4149
+ }
4150
+ const prepared = await prepareMessagePostPayload(options.message, {
4151
+ defaultAllowedMentions: this.channel.client.options.defaultAllowedMentions
4152
+ });
4153
+ const body = {
4154
+ name: options.name,
4155
+ type: import_types18.ChannelType.PublicThread,
4156
+ message: toForumThreadMessage(prepared.body)
4157
+ };
4158
+ if (options.autoArchiveDuration !== void 0) {
4159
+ body.auto_archive_duration = options.autoArchiveDuration;
4160
+ }
4161
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
4162
+ if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
4163
+ const data = await this.channel.client.rest.post(
4164
+ import_types18.Routes.channelThreads(this.channel.id),
4165
+ {
4166
+ body,
4167
+ files: prepared.files,
4168
+ auth: true,
4169
+ ...auditReasonHeaders(options.reason)
4170
+ }
4171
+ );
4172
+ const thread = cacheThread(this.channel.client, data);
4173
+ if (data.message) {
4174
+ this.channel.client._addMessageToCache(data.message.channel_id, data.message);
4175
+ }
4176
+ return thread;
4177
+ }
4178
+ /**
4179
+ * List archived threads in this channel.
4180
+ * `before` is an ISO-8601 archive timestamp.
4181
+ */
4182
+ async fetchArchived(options) {
4183
+ const path = options.type === "private" ? import_types18.Routes.channelThreadsArchivedPrivate(this.channel.id) : import_types18.Routes.channelThreadsArchivedPublic(this.channel.id);
4184
+ const data = await this.channel.client.rest.get(
4185
+ withQuery(path, { before: options.before, limit: options.limit })
4186
+ );
4187
+ return fetchedThreadsFrom(this.channel.client, data);
4188
+ }
4189
+ /**
4190
+ * List private archived threads in this channel that the current user has joined.
4191
+ * `before` is a thread snowflake.
4192
+ */
4193
+ async fetchJoinedPrivateArchived(options) {
4194
+ const data = await this.channel.client.rest.get(
4195
+ withQuery(import_types18.Routes.channelJoinedArchivedPrivateThreads(this.channel.id), {
4196
+ before: options?.before,
4197
+ limit: options?.limit
4198
+ })
4199
+ );
4200
+ return fetchedThreadsFrom(this.channel.client, data);
4201
+ }
4202
+ /**
4203
+ * Search threads in this channel.
4204
+ * Returns `{ indexing: true }` while the search index is still building.
4205
+ */
4206
+ async search(options) {
4207
+ const data = await this.channel.client.rest.get(
4208
+ withQuery(import_types18.Routes.channelThreadSearch(this.channel.id), {
4209
+ name: options?.name,
4210
+ tag: options?.tag,
4211
+ tag_setting: options?.tagSetting,
4212
+ archived: options?.archived === void 0 ? void 0 : String(options.archived),
4213
+ sort_by: options?.sortBy,
4214
+ sort_order: options?.sortOrder,
4215
+ limit: options?.limit,
4216
+ offset: options?.offset,
4217
+ max_id: options?.maxId,
4218
+ min_id: options?.minId
4219
+ })
4220
+ );
4221
+ if (isSearchNotReady(data)) {
4222
+ return { indexing: true, retryAfter: data.retry_after, message: data.message };
4223
+ }
4224
+ const page = fetchedThreadsFrom(this.channel.client, data);
4225
+ return {
4226
+ ...page,
4227
+ hasMore: data.has_more,
4228
+ totalResults: data.total_results,
4229
+ firstMessages: (data.first_messages ?? []).map(
4230
+ (message) => new Message(this.channel.client, message)
4231
+ )
4232
+ };
4233
+ }
4234
+ /** Set the auto-archive and slowmode defaults copied onto new threads. */
4235
+ async editDefaults(options) {
4236
+ return this.channel.client.rest.patch(import_types18.Routes.channel(this.channel.id), {
4237
+ body: toThreadParentEditBody(options),
4238
+ auth: true,
4239
+ ...auditReasonHeaders(options.reason)
4240
+ });
4241
+ }
4242
+ };
4243
+ function fetchedThreadsFrom(client, data) {
4244
+ return {
4245
+ threads: (data.threads ?? []).map((thread) => cacheThread(client, thread)),
4246
+ members: (data.members ?? []).map((member) => new ThreadMember(member)),
4247
+ hasMore: data.has_more ?? false
4248
+ };
4249
+ }
4250
+ function isSearchNotReady(data) {
4251
+ return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
4252
+ }
4253
+ async function fetchActiveThreads(client, guildId) {
4254
+ const data = await client.rest.get(import_types18.Routes.guildActiveThreads(guildId));
4255
+ return fetchedThreadsFrom(client, data);
4256
+ }
4257
+
4258
+ // src/Domain/Channel/Forum.ts
4259
+ function tagsFrom(data) {
4260
+ return data ?? [];
4261
+ }
4262
+ var ThreadOnlyChannel = class extends GuildChannel {
4263
+ /** Tags that can be applied to posts. */
4264
+ availableTags;
4265
+ /** Default reaction for new posts. */
4266
+ defaultReactionEmoji;
4267
+ /** Default sort order for posts. */
4268
+ defaultSortOrder;
4269
+ /** How posts are filtered when searching by several tags. */
4270
+ defaultTagSetting;
4271
+ /** Default auto-archive duration in minutes for new posts. */
4272
+ defaultAutoArchiveDuration;
4273
+ /** Slowmode in seconds copied onto new posts. */
4274
+ defaultThreadRateLimitPerUser;
4275
+ /** Channel flags bitfield. */
4276
+ flags;
4277
+ /** Create, list, and search posts in this channel. */
4278
+ threads;
4279
+ constructor(client, data) {
4280
+ super(client, data);
4281
+ this.availableTags = tagsFrom(data.available_tags);
4282
+ this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
4283
+ this.defaultSortOrder = data.default_sort_order ?? null;
4284
+ this.defaultTagSetting = data.default_tag_setting ?? null;
4285
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
4286
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
4287
+ this.flags = data.flags ?? 0;
4288
+ this.threads = new ThreadManager(this);
4289
+ }
4290
+ /** @internal */
4291
+ _patch(data) {
4292
+ super._patch(data);
4293
+ if (data.available_tags !== void 0) this.availableTags = tagsFrom(data.available_tags);
4294
+ if ("default_reaction_emoji" in data) {
4295
+ this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
4296
+ }
4297
+ if ("default_sort_order" in data) this.defaultSortOrder = data.default_sort_order ?? null;
4298
+ if ("default_tag_setting" in data) this.defaultTagSetting = data.default_tag_setting ?? null;
4299
+ if ("default_auto_archive_duration" in data) {
4300
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
4301
+ }
4302
+ if ("default_thread_rate_limit_per_user" in data) {
4303
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
4304
+ }
4305
+ if (data.flags !== void 0) this.flags = data.flags;
4306
+ }
4307
+ /**
4308
+ * Edit this channel.
4309
+ * Tag, sort, reaction, and thread-default fields are sent with the usual channel fields.
4310
+ * `defaultForumLayout` is sent only for forum channels.
4311
+ */
4312
+ async edit(options) {
4313
+ const data = await this.client.rest.patch(import_types19.Routes.channel(this.id), {
4314
+ body: {
4315
+ ...toChannelEditBody(options),
4316
+ ...forumParentWire(options, this.type === import_types19.ChannelType.GuildForum)
4317
+ },
4318
+ auth: true,
4319
+ ...auditReasonHeaders(options.reason)
4320
+ });
4321
+ this._patch(data);
4322
+ return this;
4323
+ }
4324
+ /** Replace the tags that can be applied to posts (max 20). */
4325
+ async setAvailableTags(tags, reason) {
4326
+ return this.edit({ availableTags: tags, reason });
4327
+ }
4328
+ /** Set or clear the default reaction on new posts. */
4329
+ async setDefaultReactionEmoji(emoji, reason) {
4330
+ return this.edit({ defaultReactionEmoji: emoji, reason });
4331
+ }
4332
+ /** Set or clear the default post sort order. */
4333
+ async setDefaultSortOrder(order, reason) {
4334
+ return this.edit({ defaultSortOrder: order, reason });
4335
+ }
4336
+ /** Set or clear how posts match when several tags are selected. */
4337
+ async setDefaultTagSetting(setting, reason) {
4338
+ return this.edit({ defaultTagSetting: setting, reason });
4339
+ }
4340
+ /** Set the auto-archive and slowmode defaults copied onto new posts. */
4341
+ async editThreadDefaults(options) {
4342
+ const data = await this.client.rest.patch(import_types19.Routes.channel(this.id), {
4343
+ body: toThreadParentEditBody(options),
4344
+ auth: true,
4345
+ ...auditReasonHeaders(options.reason)
4346
+ });
4347
+ this._patch(data);
4348
+ return this;
4349
+ }
4350
+ /** Create a tag. The response replaces {@link availableTags}. */
4351
+ async createTag(options) {
4352
+ const data = await this.client.rest.post(import_types19.Routes.channelTags(this.id), {
4353
+ body: toForumTagBody(options),
4354
+ auth: true,
4355
+ ...auditReasonHeaders(options.reason)
4356
+ });
4357
+ this._patch(data);
4358
+ return this;
4359
+ }
4360
+ /** Replace a tag. The response replaces {@link availableTags}. */
4361
+ async editTag(tagId, options) {
4362
+ const data = await this.client.rest.put(import_types19.Routes.channelTag(this.id, tagId), {
4363
+ body: toForumTagBody(options),
4364
+ auth: true,
4365
+ ...auditReasonHeaders(options.reason)
4366
+ });
4367
+ this._patch(data);
4368
+ return this;
4369
+ }
4370
+ /** Delete a tag. The response replaces {@link availableTags}. */
4371
+ async deleteTag(tagId, reason) {
4372
+ const data = await this.client.rest.delete(import_types19.Routes.channelTag(this.id, tagId), {
4373
+ auth: true,
4374
+ ...auditReasonHeaders(reason)
4375
+ });
4376
+ this._patch(data);
4377
+ return this;
3487
4378
  }
3488
4379
  };
3489
- var LinkChannel = class extends GuildChannel {
3490
- /** External URL this channel links to. */
3491
- url;
4380
+ var ForumChannel = class extends ThreadOnlyChannel {
4381
+ /** Default layout for posts. */
4382
+ defaultForumLayout;
4383
+ /** Set or clear the default post layout. */
4384
+ async setDefaultForumLayout(layout, reason) {
4385
+ return this.edit({ defaultForumLayout: layout, reason });
4386
+ }
3492
4387
  constructor(client, data) {
3493
4388
  super(client, data);
3494
- this.url = data.url ?? null;
4389
+ this.defaultForumLayout = data.default_forum_layout ?? null;
3495
4390
  }
3496
- applyEditPatch(data) {
3497
- if ("url" in data) this.url = data.url ?? null;
4391
+ /** @internal */
4392
+ _patch(data) {
4393
+ super._patch(data);
4394
+ if ("default_forum_layout" in data) this.defaultForumLayout = data.default_forum_layout ?? null;
3498
4395
  }
3499
4396
  };
4397
+ var MediaChannel = class extends ThreadOnlyChannel {
4398
+ };
3500
4399
 
3501
4400
  // src/Domain/Channel/Factory.ts
3502
- var import_types15 = require("@fluxerjs/types");
4401
+ var import_types20 = require("@fluxerjs/types");
3503
4402
  var GUILD_FACTORIES = {
3504
- [import_types15.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
3505
- [import_types15.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
3506
- [import_types15.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3507
- [import_types15.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
3508
- [import_types15.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
4403
+ [import_types20.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
4404
+ [import_types20.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
4405
+ [import_types20.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
4406
+ [import_types20.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
4407
+ [import_types20.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d),
4408
+ [import_types20.ChannelType.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
4409
+ [import_types20.ChannelType.PublicThread]: (c, d) => new ThreadChannel(c, d),
4410
+ [import_types20.ChannelType.PrivateThread]: (c, d) => new ThreadChannel(c, d),
4411
+ [import_types20.ChannelType.GuildForum]: (c, d) => new ForumChannel(c, d),
4412
+ [import_types20.ChannelType.GuildMedia]: (c, d) => new MediaChannel(c, d)
3509
4413
  };
3510
4414
  var DM_TYPES = /* @__PURE__ */ new Set([
3511
- import_types15.ChannelType.DM,
3512
- import_types15.ChannelType.GroupDM,
3513
- import_types15.ChannelType.DMPersonalNotes
4415
+ import_types20.ChannelType.DM,
4416
+ import_types20.ChannelType.GroupDM,
4417
+ import_types20.ChannelType.DMPersonalNotes
3514
4418
  ]);
3515
4419
  function createDM(client, data) {
3516
4420
  return new DMChannel(client, data);
3517
4421
  }
3518
4422
  function channelFrom(client, data) {
3519
- const factory = GUILD_FACTORIES[data.type ?? 0];
3520
- return factory ? factory(client, data) : new GuildChannel(client, data);
4423
+ const factory2 = GUILD_FACTORIES[data.type ?? 0];
4424
+ return factory2 ? factory2(client, data) : new GuildChannel(client, data);
3521
4425
  }
3522
4426
  function channelFromOrCreate(client, data) {
3523
4427
  return DM_TYPES.has(data.type ?? 0) ? createDM(client, data) : channelFrom(client, data);
@@ -3527,9 +4431,13 @@ function channelFromOrCreate(client, data) {
3527
4431
  Channel.from = channelFrom;
3528
4432
  Channel.fromOrCreate = channelFromOrCreate;
3529
4433
  Channel.createDM = createDM;
4434
+ bindThreadManager((channel) => new ThreadManager(channel));
4435
+
4436
+ // src/Domain/Guild/Cache.ts
4437
+ var import_types27 = require("@fluxerjs/types");
3530
4438
 
3531
4439
  // src/Domain/Guild/GuildEmoji.ts
3532
- var import_types16 = require("@fluxerjs/types");
4440
+ var import_types21 = require("@fluxerjs/types");
3533
4441
  var import_util14 = require("@fluxerjs/util");
3534
4442
  var GuildEmoji = class extends Base {
3535
4443
  client;
@@ -3578,7 +4486,7 @@ var GuildEmoji = class extends Base {
3578
4486
  }
3579
4487
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
3580
4488
  async delete(reason) {
3581
- await this.client.rest.delete(import_types16.Routes.guildEmoji(this.guildId, this.id), {
4489
+ await this.client.rest.delete(import_types21.Routes.guildEmoji(this.guildId, this.id), {
3582
4490
  auth: true,
3583
4491
  ...auditReasonHeaders(reason)
3584
4492
  });
@@ -3591,7 +4499,7 @@ var GuildEmoji = class extends Base {
3591
4499
  */
3592
4500
  async edit(options) {
3593
4501
  const { reason, name } = options;
3594
- const data = await this.client.rest.patch(import_types16.Routes.guildEmoji(this.guildId, this.id), {
4502
+ const data = await this.client.rest.patch(import_types21.Routes.guildEmoji(this.guildId, this.id), {
3595
4503
  body: { name },
3596
4504
  auth: true,
3597
4505
  ...auditReasonHeaders(reason)
@@ -3602,11 +4510,11 @@ var GuildEmoji = class extends Base {
3602
4510
  };
3603
4511
 
3604
4512
  // src/Domain/Guild/GuildMember.ts
3605
- var import_types19 = require("@fluxerjs/types");
4513
+ var import_types24 = require("@fluxerjs/types");
3606
4514
  var import_util16 = require("@fluxerjs/util");
3607
4515
 
3608
4516
  // src/Helpers/Permissions.ts
3609
- var import_types17 = require("@fluxerjs/types");
4517
+ var import_types22 = require("@fluxerjs/types");
3610
4518
  var import_util15 = require("@fluxerjs/util");
3611
4519
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
3612
4520
  if (isOwner) return import_util15.ALL_PERMISSIONS_BIGINT;
@@ -3615,7 +4523,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
3615
4523
  }
3616
4524
  let perms = basePermissions;
3617
4525
  for (const overwrite of overwrites ?? []) {
3618
- const applies = overwrite.type === import_types17.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types17.OverwriteType.Member && overwrite.id === memberId;
4526
+ const applies = overwrite.type === import_types22.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types22.OverwriteType.Member && overwrite.id === memberId;
3619
4527
  if (!applies) continue;
3620
4528
  const allow = BigInt(overwrite.allow || "0");
3621
4529
  const deny = BigInt(overwrite.deny || "0");
@@ -3626,7 +4534,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
3626
4534
 
3627
4535
  // src/Domain/Guild/GuildMemberRoleManager.ts
3628
4536
  var import_collection7 = require("@fluxerjs/collection");
3629
- var import_types18 = require("@fluxerjs/types");
4537
+ var import_types23 = require("@fluxerjs/types");
3630
4538
  function roleId(roleOrId) {
3631
4539
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
3632
4540
  }
@@ -3655,7 +4563,7 @@ var GuildMemberRoleManager = class {
3655
4563
  const id = roleId(roleOrId);
3656
4564
  if (this.ids.includes(id)) return;
3657
4565
  await this.member.client.rest.put(
3658
- import_types18.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
4566
+ import_types23.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
3659
4567
  );
3660
4568
  this.ids.push(id);
3661
4569
  }
@@ -3664,13 +4572,13 @@ var GuildMemberRoleManager = class {
3664
4572
  const idx = this.ids.indexOf(id);
3665
4573
  if (idx === -1) return;
3666
4574
  await this.member.client.rest.delete(
3667
- import_types18.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
4575
+ import_types23.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
3668
4576
  );
3669
4577
  this.ids.splice(idx, 1);
3670
4578
  }
3671
4579
  async set(roleIds) {
3672
4580
  const data = await this.member.client.rest.patch(
3673
- import_types18.Routes.guildMember(this.member.guild.id, this.member.id),
4581
+ import_types23.Routes.guildMember(this.member.guild.id, this.member.id),
3674
4582
  { body: { roles: roleIds }, auth: true }
3675
4583
  );
3676
4584
  this.ids = data.roles ? [...data.roles] : [];
@@ -3824,7 +4732,7 @@ var GuildMember = class _GuildMember extends Base {
3824
4732
  */
3825
4733
  async edit(options) {
3826
4734
  const isMe = this.client.user?.id === this.id;
3827
- const route = isMe ? import_types19.Routes.guildMemberMe(this.guild.id) : import_types19.Routes.guildMember(this.guild.id, this.id);
4735
+ const route = isMe ? import_types24.Routes.guildMemberMe(this.guild.id) : import_types24.Routes.guildMember(this.guild.id, this.id);
3828
4736
  const data = await this.client.rest.patch(route, {
3829
4737
  body: toMemberEditBody(options),
3830
4738
  auth: true,
@@ -3937,7 +4845,7 @@ var GuildMember = class _GuildMember extends Base {
3937
4845
  };
3938
4846
 
3939
4847
  // src/Domain/Guild/GuildSticker.ts
3940
- var import_types20 = require("@fluxerjs/types");
4848
+ var import_types25 = require("@fluxerjs/types");
3941
4849
  var import_util17 = require("@fluxerjs/util");
3942
4850
  var GuildSticker = class extends Base {
3943
4851
  client;
@@ -3988,7 +4896,7 @@ var GuildSticker = class extends Base {
3988
4896
  }
3989
4897
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3990
4898
  async delete(reason) {
3991
- await this.client.rest.delete(import_types20.Routes.guildSticker(this.guildId, this.id), {
4899
+ await this.client.rest.delete(import_types25.Routes.guildSticker(this.guildId, this.id), {
3992
4900
  auth: true,
3993
4901
  ...auditReasonHeaders(reason)
3994
4902
  });
@@ -4001,7 +4909,7 @@ var GuildSticker = class extends Base {
4001
4909
  */
4002
4910
  async edit(options) {
4003
4911
  const { reason, ...body } = options;
4004
- const data = await this.client.rest.patch(import_types20.Routes.guildSticker(this.guildId, this.id), {
4912
+ const data = await this.client.rest.patch(import_types25.Routes.guildSticker(this.guildId, this.id), {
4005
4913
  body,
4006
4914
  auth: true,
4007
4915
  ...auditReasonHeaders(reason)
@@ -4014,7 +4922,7 @@ var GuildSticker = class extends Base {
4014
4922
  };
4015
4923
 
4016
4924
  // src/Domain/Guild/Role.ts
4017
- var import_types21 = require("@fluxerjs/types");
4925
+ var import_types26 = require("@fluxerjs/types");
4018
4926
  var import_util18 = require("@fluxerjs/util");
4019
4927
  var Role = class _Role extends Base {
4020
4928
  /** Parent client instance. */
@@ -4037,6 +4945,8 @@ var Role = class _Role extends Base {
4037
4945
  mentionable;
4038
4946
  /** Unicode emoji for this role (null = none). */
4039
4947
  unicodeEmoji;
4948
+ /** Role icon image hash (null = none). */
4949
+ icon;
4040
4950
  /** Hoist position (null = not hoisted). */
4041
4951
  hoistPosition;
4042
4952
  constructor(client, data, guildId) {
@@ -4044,20 +4954,26 @@ var Role = class _Role extends Base {
4044
4954
  this.client = client;
4045
4955
  this.id = data.id;
4046
4956
  this.guildId = guildId;
4047
- this.name = data.name;
4048
- this.color = data.color;
4049
- this.position = data.position;
4050
- this._permissions = data.permissions;
4957
+ this.name = data.name ?? "";
4958
+ this.color = data.color ?? 0;
4959
+ this.position = data.position ?? 0;
4960
+ this._permissions = data.permissions ?? "0";
4051
4961
  this.hoist = !!data.hoist;
4052
4962
  this.mentionable = !!data.mentionable;
4053
4963
  this.unicodeEmoji = data.unicode_emoji ?? null;
4964
+ this.icon = data.icon ?? null;
4054
4965
  this.hoistPosition = data.hoist_position ?? null;
4055
4966
  }
4056
4967
  /**
4057
4968
  * Permissions bitfield (Administrator grants all permissions).
4058
4969
  */
4059
4970
  get permissions() {
4060
- const bits = BigInt(this._permissions);
4971
+ let bits;
4972
+ try {
4973
+ bits = BigInt(this._permissions ?? "0");
4974
+ } catch {
4975
+ bits = 0n;
4976
+ }
4061
4977
  return new import_util18.PermissionsBitField(
4062
4978
  (bits & import_util18.PermissionFlags.Administrator) !== 0n ? import_util18.ALL_PERMISSIONS_BIGINT : bits
4063
4979
  );
@@ -4087,14 +5003,15 @@ var Role = class _Role extends Base {
4087
5003
  }
4088
5004
  /** @internal */
4089
5005
  _patch(data) {
4090
- this.name = data.name;
4091
- this.color = data.color;
4092
- this.position = data.position;
4093
- this._permissions = data.permissions;
4094
- this.hoist = !!data.hoist;
4095
- this.mentionable = !!data.mentionable;
4096
- this.unicodeEmoji = data.unicode_emoji ?? null;
4097
- this.hoistPosition = data.hoist_position ?? null;
5006
+ if (data.name !== void 0) this.name = data.name;
5007
+ if (data.color !== void 0) this.color = data.color;
5008
+ if (data.position !== void 0) this.position = data.position;
5009
+ if (data.permissions !== void 0) this._permissions = data.permissions;
5010
+ if (data.hoist !== void 0) this.hoist = !!data.hoist;
5011
+ if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
5012
+ if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
5013
+ if (data.icon !== void 0) this.icon = data.icon ?? null;
5014
+ if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
4098
5015
  }
4099
5016
  /**
4100
5017
  * Snapshot for role-update events (before in-place patch).
@@ -4112,6 +5029,7 @@ var Role = class _Role extends Base {
4112
5029
  hoist: this.hoist,
4113
5030
  mentionable: this.mentionable,
4114
5031
  unicode_emoji: this.unicodeEmoji,
5032
+ icon: this.icon,
4115
5033
  hoist_position: this.hoistPosition
4116
5034
  },
4117
5035
  this.guildId
@@ -4124,7 +5042,7 @@ var Role = class _Role extends Base {
4124
5042
  */
4125
5043
  async edit(options) {
4126
5044
  const body = toRoleEditBody(options);
4127
- const data = await this.client.rest.patch(import_types21.Routes.guildRole(this.guildId, this.id), {
5045
+ const data = await this.client.rest.patch(import_types26.Routes.guildRole(this.guildId, this.id), {
4128
5046
  body: Object.keys(body).length ? body : void 0,
4129
5047
  auth: true,
4130
5048
  ...auditReasonHeaders(options.reason)
@@ -4137,7 +5055,7 @@ var Role = class _Role extends Base {
4137
5055
  * @param reason - Audit log reason (`X-Audit-Log-Reason`)
4138
5056
  */
4139
5057
  async delete(reason) {
4140
- await this.client.rest.delete(import_types21.Routes.guildRole(this.guildId, this.id), {
5058
+ await this.client.rest.delete(import_types26.Routes.guildRole(this.guildId, this.id), {
4141
5059
  auth: true,
4142
5060
  ...auditReasonHeaders(reason)
4143
5061
  });
@@ -4232,11 +5150,30 @@ function syncChannels(guild, channels) {
4232
5150
  const keep = new Set(channels.map((c) => c.id));
4233
5151
  for (const data of channels) cacheChannel(guild, data);
4234
5152
  for (const [id, channel] of [...guild.channels.entries()]) {
4235
- if (keep.has(id)) continue;
5153
+ if (keep.has(id) || channel.isThread()) continue;
4236
5154
  Map.prototype.delete.call(guild.channels, id);
4237
5155
  guild.client.cache.cascadeChannel(channel, "guild");
4238
5156
  }
4239
5157
  }
5158
+ function isThreadChannelType(type) {
5159
+ return type === import_types27.ChannelType.AnnouncementThread || type === import_types27.ChannelType.PublicThread || type === import_types27.ChannelType.PrivateThread;
5160
+ }
5161
+ function syncThreads(guild, threads, alsoKeep = /* @__PURE__ */ new Set()) {
5162
+ const keep = new Set(alsoKeep);
5163
+ for (const data of threads) {
5164
+ if (!isThreadChannelType(data.type)) continue;
5165
+ const withGuild = data.guild_id ? data : { ...data, guild_id: guild.id };
5166
+ cacheThread(guild.client, withGuild);
5167
+ keep.add(data.id);
5168
+ }
5169
+ const seen = /* @__PURE__ */ new Set();
5170
+ for (const channel of [...guild.channels.values(), ...guild.client.channels.values()]) {
5171
+ if (seen.has(channel.id)) continue;
5172
+ seen.add(channel.id);
5173
+ if (!channel.isThread() || channel.guildId !== guild.id || keep.has(channel.id)) continue;
5174
+ guild.client.cache.cascadeChannel(channel);
5175
+ }
5176
+ }
4240
5177
  function mergeMembers(guild, members) {
4241
5178
  for (const m of members) {
4242
5179
  if (!m.user?.id) continue;
@@ -4270,6 +5207,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
4270
5207
  });
4271
5208
  this.client = client;
4272
5209
  }
5210
+ pendingFetches = /* @__PURE__ */ new Map();
4273
5211
  /**
4274
5212
  * Remove a channel from cache. Does not delete it on the API.
4275
5213
  * Use {@link Channel.delete} after {@link fetch} to delete the channel.
@@ -4282,9 +5220,11 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
4282
5220
  }
4283
5221
  return deleted;
4284
5222
  }
4285
- /** Retrieve from cache, otherwise {@link fetch}. */
5223
+ /** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
4286
5224
  async resolve(channelId) {
4287
- return this.get(channelId) ?? this.fetch(channelId);
5225
+ const id = normalizeSnowflakeId(channelId, "channels.resolve()");
5226
+ const cached = this.get(id);
5227
+ return cached && !cached.partial ? cached : this.fetch(id);
4288
5228
  }
4289
5229
  /**
4290
5230
  * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
@@ -4297,10 +5237,23 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
4297
5237
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
4298
5238
  */
4299
5239
  async fetch(channelId, options) {
4300
- const cached = this.get(channelId);
4301
- if (cached && !options?.force) return cached;
5240
+ const id = normalizeSnowflakeId(channelId, "channels.fetch()");
5241
+ const cached = this.get(id);
5242
+ if (cached && !cached.partial && !options?.force) return cached;
5243
+ return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
5244
+ }
5245
+ async fetchFresh(channelId) {
4302
5246
  try {
4303
- const data = await this.client.rest.get(import_types22.Routes.channel(channelId));
5247
+ const data = assertApiObjectWithId(
5248
+ await this.client.rest.get(import_types28.Routes.channel(channelId)),
5249
+ "channels.fetch()"
5250
+ );
5251
+ const existing = this.get(channelId);
5252
+ if (existing && existing.type === data.type) {
5253
+ existing._patch(data);
5254
+ putChannel(this.client, existing);
5255
+ return existing;
5256
+ }
4304
5257
  const guildId = "guild_id" in data ? data.guild_id : void 0;
4305
5258
  if (guildId) {
4306
5259
  const guild = this.client.guilds.get(guildId);
@@ -4345,7 +5298,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
4345
5298
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
4346
5299
  });
4347
5300
  const data = await this.client.rest.post(
4348
- import_types22.Routes.channelMessages(channelId),
5301
+ import_types28.Routes.channelMessages(channelId),
4349
5302
  postPayload
4350
5303
  );
4351
5304
  this.client._addMessageToCache(channelId, data);
@@ -4356,11 +5309,11 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
4356
5309
  // src/ClientCore/Client.ts
4357
5310
  var import_node_events3 = require("events");
4358
5311
  var import_rest3 = require("@fluxerjs/rest");
4359
- var import_types39 = require("@fluxerjs/types");
5312
+ var import_types45 = require("@fluxerjs/types");
4360
5313
  var import_util26 = require("@fluxerjs/util");
4361
5314
 
4362
5315
  // src/Domain/User.ts
4363
- var import_types23 = require("@fluxerjs/types");
5316
+ var import_types29 = require("@fluxerjs/types");
4364
5317
  var import_util19 = require("@fluxerjs/util");
4365
5318
  var User = class extends Base {
4366
5319
  /** Parent client instance. */
@@ -4385,12 +5338,15 @@ var User = class extends Base {
4385
5338
  system;
4386
5339
  /** Banner hash for profile. */
4387
5340
  banner;
5341
+ /** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
5342
+ partial;
4388
5343
  constructor(client, data) {
4389
5344
  super();
4390
5345
  this.client = client;
4391
5346
  this.id = data.id;
4392
- this.username = data.username;
4393
- this.discriminator = data.discriminator;
5347
+ this.partial = typeof data.username !== "string" || data.username.length === 0;
5348
+ this.username = data.username ?? "Unknown";
5349
+ this.discriminator = data.discriminator ?? "0";
4394
5350
  this.globalName = data.global_name ?? null;
4395
5351
  this.avatar = data.avatar ?? null;
4396
5352
  this.bot = !!data.bot;
@@ -4401,13 +5357,18 @@ var User = class extends Base {
4401
5357
  }
4402
5358
  /** @internal */
4403
5359
  _patch(data) {
4404
- this.username = data.username;
4405
- this.discriminator = data.discriminator;
4406
- this.globalName = data.global_name ?? null;
4407
- this.avatar = data.avatar ?? null;
5360
+ if (data.username !== void 0) this.username = data.username;
5361
+ if (data.discriminator !== void 0) this.discriminator = data.discriminator;
5362
+ if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
5363
+ if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
4408
5364
  if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
4409
5365
  if (data.flags !== void 0) this.flags = data.flags;
4410
5366
  if (data.banner !== void 0) this.banner = data.banner;
5367
+ if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
5368
+ }
5369
+ /** Fetch the full user from REST when this instance is a partial stub. */
5370
+ async fetch() {
5371
+ return this.client.users.fetch(this.id, { force: true });
4411
5372
  }
4412
5373
  cdnOpts() {
4413
5374
  return {
@@ -4459,7 +5420,7 @@ var User = class extends Base {
4459
5420
  * @returns DM channel instance (cached if already open)
4460
5421
  */
4461
5422
  async createDM() {
4462
- const data = await this.client.rest.post(import_types23.Routes.userMeChannels(), {
5423
+ const data = await this.client.rest.post(import_types29.Routes.userMeChannels(), {
4463
5424
  body: { recipient_id: this.id },
4464
5425
  auth: true
4465
5426
  });
@@ -4537,7 +5498,7 @@ function resolveCacheLimits(input) {
4537
5498
 
4538
5499
  // src/ClientCore/ClientEmoji.ts
4539
5500
  var import_collection9 = require("@fluxerjs/collection");
4540
- var import_types24 = require("@fluxerjs/types");
5501
+ var import_types30 = require("@fluxerjs/types");
4541
5502
  var import_util20 = require("@fluxerjs/util");
4542
5503
  async function resolveClientEmoji(client, emoji, guildId) {
4543
5504
  if (typeof emoji === "object" && emoji.id) {
@@ -4556,7 +5517,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
4556
5517
  const unicodeFromShortcode = (0, import_util20.getUnicodeFromShortcode)(parsed.name);
4557
5518
  if (unicodeFromShortcode) return unicodeFromShortcode;
4558
5519
  if (guildId) {
4559
- const emojis = await client.rest.get(import_types24.Routes.guildEmojis(guildId));
5520
+ const emojis = await client.rest.get(import_types30.Routes.guildEmojis(guildId));
4560
5521
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
4561
5522
  if (found) return (0, import_util20.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
4562
5523
  throw new import_util4.FluxerError(
@@ -4573,26 +5534,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
4573
5534
  return parsed.name;
4574
5535
  }
4575
5536
  async function fetchInstance(client) {
4576
- const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
5537
+ const raw = await client.rest.get(import_types30.Routes.instanceDiscovery(), {
4577
5538
  auth: false,
4578
5539
  unversioned: true
4579
5540
  });
4580
5541
  return parseInstanceDiscovery(raw);
4581
5542
  }
4582
5543
  function fetchGatewayInfo(client) {
4583
- return client.rest.get(import_types24.Routes.gatewayBot());
5544
+ return client.rest.get(import_types30.Routes.gatewayBot());
4584
5545
  }
4585
5546
  function fetchEmojiMetadata(client, emojiId) {
4586
- return client.rest.get(import_types24.Routes.emojiMetadata(emojiId), { auth: true });
5547
+ return client.rest.get(import_types30.Routes.emojiMetadata(emojiId), { auth: true });
4587
5548
  }
4588
5549
  function fetchStickerMetadata(client, stickerId) {
4589
- return client.rest.get(import_types24.Routes.stickerMetadata(stickerId), { auth: true });
5550
+ return client.rest.get(import_types30.Routes.stickerMetadata(stickerId), { auth: true });
4590
5551
  }
4591
5552
  function fetchApplication(client) {
4592
- return client.rest.get(import_types24.Routes.applicationsMe(), { auth: true });
5553
+ return client.rest.get(import_types30.Routes.applicationsMe(), { auth: true });
4593
5554
  }
4594
5555
  async function fetchOAuthApplications(client) {
4595
- const data = await client.rest.get(import_types24.Routes.oauth2ApplicationsMe(), { auth: true });
5556
+ const data = await client.rest.get(import_types30.Routes.oauth2ApplicationsMe(), { auth: true });
4596
5557
  if (Array.isArray(data)) return data;
4597
5558
  if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
4598
5559
  return data.applications;
@@ -4611,14 +5572,14 @@ function assertChannelIdBatch(name, channelIds) {
4611
5572
  }
4612
5573
  function preloadMessages(client, channelIds) {
4613
5574
  assertChannelIdBatch("preloadMessages", channelIds);
4614
- return client.rest.post(import_types24.Routes.preloadMessages(), {
5575
+ return client.rest.post(import_types30.Routes.preloadMessages(), {
4615
5576
  body: { channels: channelIds },
4616
5577
  auth: true
4617
5578
  });
4618
5579
  }
4619
5580
  function preloadMessagesAlt(client, channelIds) {
4620
5581
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
4621
- return client.rest.post(import_types24.Routes.preloadMessagesAlt(), {
5582
+ return client.rest.post(import_types30.Routes.preloadMessagesAlt(), {
4622
5583
  body: { channels: channelIds },
4623
5584
  auth: true
4624
5585
  });
@@ -4626,7 +5587,7 @@ function preloadMessagesAlt(client, channelIds) {
4626
5587
  async function bulkFetchMessages(client, requests, options = {}) {
4627
5588
  validateBulkMessageFetchRequests(requests);
4628
5589
  const wire = toBulkFetchWire(requests);
4629
- const data = await client.rest.post(import_types24.Routes.channelsMessagesBulk(), {
5590
+ const data = await client.rest.post(import_types30.Routes.channelsMessagesBulk(), {
4630
5591
  body: { requests: wire },
4631
5592
  auth: true
4632
5593
  });
@@ -4643,12 +5604,74 @@ async function bulkFetchMessages(client, requests, options = {}) {
4643
5604
  };
4644
5605
  }
4645
5606
  async function searchMessages(client, options = {}) {
4646
- const data = await client.rest.post(import_types24.Routes.searchMessages(), {
5607
+ const data = await client.rest.post(import_types30.Routes.searchMessages(), {
4647
5608
  body: toMessageSearchBody(options),
4648
5609
  auth: true
4649
5610
  });
4650
5611
  return toMessageSearchResponse(data);
4651
5612
  }
5613
+ function fetchEmojiSource(client, emojiId) {
5614
+ return client.rest.get(
5615
+ import_types30.Routes.emojiSource(emojiId),
5616
+ { auth: true }
5617
+ );
5618
+ }
5619
+ function fetchStickerSource(client, stickerId) {
5620
+ return client.rest.get(
5621
+ import_types30.Routes.stickerSource(stickerId),
5622
+ { auth: true }
5623
+ );
5624
+ }
5625
+ function fetchDiscoveryCategories(client) {
5626
+ return client.rest.get(
5627
+ import_types30.Routes.discoveryCategories(),
5628
+ { auth: true }
5629
+ );
5630
+ }
5631
+ function searchDiscoveryGuilds(client, options = {}) {
5632
+ const params = new URLSearchParams();
5633
+ if (options.query !== void 0) params.set("query", options.query);
5634
+ if (options.category !== void 0) params.set("category", String(options.category));
5635
+ if (options.language !== void 0) params.set("language", options.language);
5636
+ if (options.tag !== void 0) params.set("tag", options.tag);
5637
+ if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
5638
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5639
+ if (options.offset !== void 0) params.set("offset", String(options.offset));
5640
+ const qs2 = params.toString();
5641
+ return client.rest.get(
5642
+ qs2 ? `${import_types30.Routes.discoveryGuilds()}?${qs2}` : import_types30.Routes.discoveryGuilds(),
5643
+ { auth: true }
5644
+ );
5645
+ }
5646
+ function fetchExperiments(client) {
5647
+ return client.rest.get(import_types30.Routes.experiments(), {
5648
+ auth: true
5649
+ });
5650
+ }
5651
+ function refreshAttachmentUrls(client, attachmentUrls) {
5652
+ return client.rest.post(
5653
+ import_types30.Routes.attachmentsRefreshUrls(),
5654
+ { body: { attachment_urls: attachmentUrls }, auth: true }
5655
+ );
5656
+ }
5657
+ function fetchInstanceBadges(client, options = {}) {
5658
+ const params = new URLSearchParams();
5659
+ if (options.ids !== void 0) params.set("ids", options.ids);
5660
+ if (options.after !== void 0) params.set("after", options.after);
5661
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5662
+ if (options.version !== void 0) params.set("version", options.version);
5663
+ const qs2 = params.toString();
5664
+ return client.rest.get(
5665
+ qs2 ? `${import_types30.Routes.instanceBadges()}?${qs2}` : import_types30.Routes.instanceBadges(),
5666
+ { auth: false }
5667
+ );
5668
+ }
5669
+ function fetchChannelPostData(client, channelId, threadIds) {
5670
+ return client.rest.post(
5671
+ import_types30.Routes.channelPostData(channelId),
5672
+ { body: { thread_ids: threadIds }, auth: true }
5673
+ );
5674
+ }
4652
5675
 
4653
5676
  // src/ClientCore/ClientEvents.ts
4654
5677
  function createEventMethods(client) {
@@ -4668,17 +5691,18 @@ var import_ws = require("@fluxerjs/ws");
4668
5691
 
4669
5692
  // src/Domain/Guild/Guild.ts
4670
5693
  var import_collection12 = require("@fluxerjs/collection");
4671
- var import_types34 = require("@fluxerjs/types");
5694
+ var import_types40 = require("@fluxerjs/types");
4672
5695
  var import_util22 = require("@fluxerjs/util");
4673
5696
 
4674
5697
  // src/ClientCore/GuildMemberManager.ts
4675
5698
  var import_collection10 = require("@fluxerjs/collection");
4676
- var import_types25 = require("@fluxerjs/types");
5699
+ var import_types31 = require("@fluxerjs/types");
4677
5700
  var GuildMemberManager = class extends import_collection10.LimitedCollection {
4678
5701
  constructor(guild) {
4679
5702
  super({ maxSize: guild.client.cache.limits.members });
4680
5703
  this.guild = guild;
4681
5704
  }
5705
+ pendingFetches = /* @__PURE__ */ new Map();
4682
5706
  /**
4683
5707
  * Get a guild member from cache or fetch from the API if not present.
4684
5708
  * Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
@@ -4690,7 +5714,9 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
4690
5714
  * console.log(member.displayName);
4691
5715
  */
4692
5716
  async resolve(userId) {
4693
- return this.get(userId) ?? this.fetch(userId);
5717
+ const id = normalizeSnowflakeId(userId, "members.resolve()");
5718
+ const cached = this.get(id);
5719
+ return cached && !cached.user.partial ? cached : this.fetch(id);
4694
5720
  }
4695
5721
  /**
4696
5722
  * The current bot user as a GuildMember in this guild.
@@ -4718,10 +5744,11 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
4718
5744
  return this.guild.fetchMe();
4719
5745
  }
4720
5746
  async fetch(userIdOrOptions, options) {
4721
- if (typeof userIdOrOptions === "string") {
4722
- const cached = this.get(userIdOrOptions);
4723
- if (cached && !options?.force) return cached;
4724
- return this.guild.fetchMember(userIdOrOptions);
5747
+ if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
5748
+ const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
5749
+ const cached = this.get(id);
5750
+ if (cached && !cached.user.partial && !options?.force) return cached;
5751
+ return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
4725
5752
  }
4726
5753
  return this.fetchMany(userIdOrOptions);
4727
5754
  }
@@ -4730,10 +5757,14 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
4730
5757
  if (options?.limit != null) params.set("limit", String(options.limit));
4731
5758
  if (options?.after) params.set("after", options.after);
4732
5759
  const qs2 = params.toString();
4733
- const url = import_types25.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
4734
- const data = await this.guild.client.rest.get(url, { auth: true });
5760
+ const url = import_types31.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5761
+ const data = assertApiArray(
5762
+ await this.guild.client.rest.get(url, { auth: true }),
5763
+ "members.fetch()"
5764
+ );
4735
5765
  const members = [];
4736
5766
  for (const m of data) {
5767
+ if (!m?.user?.id) continue;
4737
5768
  const member = new GuildMember(
4738
5769
  this.guild.client,
4739
5770
  { ...m, guild_id: this.guild.id },
@@ -4753,7 +5784,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
4753
5784
  */
4754
5785
  async search(options = {}) {
4755
5786
  const data = await this.guild.client.rest.post(
4756
- import_types25.Routes.guildMembersSearch(this.guild.id),
5787
+ import_types31.Routes.guildMembersSearch(this.guild.id),
4757
5788
  { body: toMemberSearchBody(options), auth: true }
4758
5789
  );
4759
5790
  const offset = options.offset ?? 0;
@@ -4779,7 +5810,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
4779
5810
  };
4780
5811
 
4781
5812
  // src/Domain/Guild/Admin.ts
4782
- var import_types26 = require("@fluxerjs/types");
5813
+ var import_types32 = require("@fluxerjs/types");
4783
5814
  function toAuditLogEntryPayload(entry, guildId) {
4784
5815
  return {
4785
5816
  id: entry.id,
@@ -4800,7 +5831,7 @@ function toVanityPayload(data) {
4800
5831
  return { code: data.code ?? null, uses: data.uses };
4801
5832
  }
4802
5833
  async function fetchAuditLogs(guild, options) {
4803
- const url = import_types26.Routes.guildAuditLogs(guild.id) + qs({
5834
+ const url = import_types32.Routes.guildAuditLogs(guild.id) + qs({
4804
5835
  limit: options?.limit,
4805
5836
  before: options?.before,
4806
5837
  after: options?.after,
@@ -4824,7 +5855,7 @@ async function fetchAuditLogs(guild, options) {
4824
5855
  };
4825
5856
  }
4826
5857
  async function editGuild(guild, options) {
4827
- const data = await guild.client.rest.patch(import_types26.Routes.guild(guild.id), {
5858
+ const data = await guild.client.rest.patch(import_types32.Routes.guild(guild.id), {
4828
5859
  body: toGuildEditBody(options),
4829
5860
  auth: true
4830
5861
  });
@@ -4832,13 +5863,13 @@ async function editGuild(guild, options) {
4832
5863
  return guild;
4833
5864
  }
4834
5865
  async function fetchVanityURL(guild) {
4835
- const data = await guild.client.rest.get(import_types26.Routes.guildVanityUrl(guild.id), {
5866
+ const data = await guild.client.rest.get(import_types32.Routes.guildVanityUrl(guild.id), {
4836
5867
  auth: true
4837
5868
  });
4838
5869
  return toVanityPayload(data);
4839
5870
  }
4840
5871
  async function editVanityURL(guild, code) {
4841
- const data = await guild.client.rest.patch(import_types26.Routes.guildVanityUrl(guild.id), {
5872
+ const data = await guild.client.rest.patch(import_types32.Routes.guildVanityUrl(guild.id), {
4842
5873
  body: { code },
4843
5874
  auth: true
4844
5875
  });
@@ -4846,14 +5877,14 @@ async function editVanityURL(guild, code) {
4846
5877
  return toVanityPayload(data);
4847
5878
  }
4848
5879
  async function fetchDiscoveryStatus(guild) {
4849
- const data = await guild.client.rest.get(import_types26.Routes.guildDiscovery(guild.id), {
5880
+ const data = await guild.client.rest.get(import_types32.Routes.guildDiscovery(guild.id), {
4850
5881
  auth: true
4851
5882
  });
4852
5883
  return toDiscoveryStatusPayload(data);
4853
5884
  }
4854
5885
  async function applyForDiscovery(guild, options) {
4855
5886
  const data = await guild.client.rest.post(
4856
- import_types26.Routes.guildDiscovery(guild.id),
5887
+ import_types32.Routes.guildDiscovery(guild.id),
4857
5888
  {
4858
5889
  body: toDiscoveryBody(options),
4859
5890
  auth: true
@@ -4863,7 +5894,7 @@ async function applyForDiscovery(guild, options) {
4863
5894
  }
4864
5895
  async function editDiscoveryApplication(guild, options) {
4865
5896
  const data = await guild.client.rest.patch(
4866
- import_types26.Routes.guildDiscovery(guild.id),
5897
+ import_types32.Routes.guildDiscovery(guild.id),
4867
5898
  {
4868
5899
  body: toDiscoveryBody(options),
4869
5900
  auth: true
@@ -4872,34 +5903,39 @@ async function editDiscoveryApplication(guild, options) {
4872
5903
  return toDiscoveryApplicationPayload(data);
4873
5904
  }
4874
5905
  async function withdrawDiscoveryApplication(guild) {
4875
- await guild.client.rest.delete(import_types26.Routes.guildDiscovery(guild.id), { auth: true });
5906
+ await guild.client.rest.delete(import_types32.Routes.guildDiscovery(guild.id), { auth: true });
4876
5907
  }
4877
5908
  async function deleteGuild(guild, options) {
4878
5909
  const body = options ? toSudoBody(options) : {};
4879
- await guild.client.rest.post(import_types26.Routes.guildDelete(guild.id), {
5910
+ await guild.client.rest.post(import_types32.Routes.guildDelete(guild.id), {
4880
5911
  body,
4881
5912
  auth: true
4882
5913
  });
4883
5914
  guild.client.guilds.delete(guild.id);
4884
5915
  }
4885
5916
  async function transferOwnership(guild, newOwnerId, password) {
4886
- await guild.client.rest.post(import_types26.Routes.guildTransferOwnership(guild.id), {
5917
+ await guild.client.rest.post(import_types32.Routes.guildTransferOwnership(guild.id), {
4887
5918
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
4888
5919
  auth: true
4889
5920
  });
4890
5921
  }
4891
5922
 
4892
5923
  // src/Domain/Guild/Channels.ts
4893
- var import_types27 = require("@fluxerjs/types");
5924
+ var import_types33 = require("@fluxerjs/types");
4894
5925
  async function createChannel(guild, options) {
4895
- const created = await guild.client.rest.post(import_types27.Routes.guildChannels(guild.id), {
5926
+ const created = await guild.client.rest.post(import_types33.Routes.guildChannels(guild.id), {
4896
5927
  body: toChannelCreateBody(options),
4897
5928
  auth: true
4898
5929
  });
4899
5930
  return cacheChannel(guild, created);
4900
5931
  }
4901
5932
  async function fetchChannels(guild) {
4902
- const data = await guild.client.rest.get(import_types27.Routes.guildChannels(guild.id));
5933
+ const raw = await guild.client.rest.get(import_types33.Routes.guildChannels(guild.id));
5934
+ if (!Array.isArray(raw))
5935
+ throw new TypeError(
5936
+ "guild.fetchChannels() received an invalid API payload (expected an array)"
5937
+ );
5938
+ const data = raw;
4903
5939
  const channels = [];
4904
5940
  for (const ch of data) {
4905
5941
  const channel = cacheChannel(guild, ch);
@@ -4908,17 +5944,17 @@ async function fetchChannels(guild) {
4908
5944
  return channels;
4909
5945
  }
4910
5946
  async function setChannelPositions(guild, updates) {
4911
- await guild.client.rest.patch(import_types27.Routes.guildChannels(guild.id), {
5947
+ await guild.client.rest.patch(import_types33.Routes.guildChannels(guild.id), {
4912
5948
  body: toChannelPositionBody(updates),
4913
5949
  auth: true
4914
5950
  });
4915
5951
  }
4916
5952
  async function fetchWebhooks(guild) {
4917
- const data = await guild.client.rest.get(import_types27.Routes.guildWebhooks(guild.id));
5953
+ const data = await guild.client.rest.get(import_types33.Routes.guildWebhooks(guild.id));
4918
5954
  return data.map((w) => new Webhook(guild.client, w));
4919
5955
  }
4920
5956
  async function fetchInvites(guild) {
4921
- const data = await guild.client.rest.get(import_types27.Routes.guildInvites(guild.id));
5957
+ const data = await guild.client.rest.get(import_types33.Routes.guildInvites(guild.id));
4922
5958
  return data.map((invite) => new Invite(guild.client, invite));
4923
5959
  }
4924
5960
  async function fetchInvite(guild, codeOrUrl) {
@@ -4938,14 +5974,14 @@ function resolveGuildOnlineCount(data) {
4938
5974
  }
4939
5975
 
4940
5976
  // src/Domain/Guild/Emojis.ts
4941
- var import_types28 = require("@fluxerjs/types");
5977
+ var import_types34 = require("@fluxerjs/types");
4942
5978
  async function fetchEmojis(guild) {
4943
- const data = await guild.client.rest.get(import_types28.Routes.guildEmojis(guild.id));
5979
+ const data = await guild.client.rest.get(import_types34.Routes.guildEmojis(guild.id));
4944
5980
  return data.map((e) => cacheEmoji(guild, e));
4945
5981
  }
4946
5982
  async function fetchEmoji(guild, emojiId) {
4947
5983
  try {
4948
- const data = await guild.client.rest.get(import_types28.Routes.guildEmoji(guild.id, emojiId));
5984
+ const data = await guild.client.rest.get(import_types34.Routes.guildEmoji(guild.id, emojiId));
4949
5985
  return cacheEmoji(guild, data);
4950
5986
  } catch (err) {
4951
5987
  rethrowMapped(err, {
@@ -4956,7 +5992,7 @@ async function fetchEmoji(guild, emojiId) {
4956
5992
  }
4957
5993
  async function createEmoji(guild, options) {
4958
5994
  const { reason, ...body } = options;
4959
- const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
5995
+ const data = await guild.client.rest.post(import_types34.Routes.guildEmojis(guild.id), {
4960
5996
  body,
4961
5997
  auth: true,
4962
5998
  ...auditReasonHeaders(reason)
@@ -4964,7 +6000,7 @@ async function createEmoji(guild, options) {
4964
6000
  return cacheEmoji(guild, data);
4965
6001
  }
4966
6002
  async function cloneEmoji(guild, sourceEmojiId) {
4967
- const data = await guild.client.rest.post(import_types28.Routes.guildEmojisClone(guild.id), {
6003
+ const data = await guild.client.rest.post(import_types34.Routes.guildEmojisClone(guild.id), {
4968
6004
  body: { source_emoji_id: sourceEmojiId },
4969
6005
  auth: true
4970
6006
  });
@@ -4972,7 +6008,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
4972
6008
  }
4973
6009
  async function createEmojisBulk(guild, emojis) {
4974
6010
  const data = await guild.client.rest.post(
4975
- import_types28.Routes.guildEmojisBulk(guild.id),
6011
+ import_types34.Routes.guildEmojisBulk(guild.id),
4976
6012
  { body: { emojis }, auth: true }
4977
6013
  );
4978
6014
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
@@ -4992,18 +6028,22 @@ var GuildRoleManager = class extends import_collection11.LimitedCollection {
4992
6028
  };
4993
6029
 
4994
6030
  // src/Domain/Guild/MemberHttp.ts
4995
- var import_types29 = require("@fluxerjs/types");
6031
+ var import_types35 = require("@fluxerjs/types");
4996
6032
  async function fetchMember(guild, userId) {
6033
+ const id = normalizeSnowflakeId(userId, "members.fetch()");
4997
6034
  try {
4998
6035
  const data = await guild.client.rest.get(
4999
- import_types29.Routes.guildMember(guild.id, userId)
6036
+ import_types35.Routes.guildMember(guild.id, id)
5000
6037
  );
6038
+ if (!data?.user?.id) {
6039
+ throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
6040
+ }
5001
6041
  return cacheMember(guild, data);
5002
6042
  } catch (err) {
5003
6043
  rethrowMapped(err, {
5004
6044
  notFound: {
5005
6045
  code: import_util3.ErrorCodes.MemberNotFound,
5006
- message: `Member ${userId} not found in guild`
6046
+ message: `Member ${id} not found in guild`
5007
6047
  },
5008
6048
  fallback: "Failed to fetch guild member"
5009
6049
  });
@@ -5011,17 +6051,20 @@ async function fetchMember(guild, userId) {
5011
6051
  }
5012
6052
  async function fetchMe(guild) {
5013
6053
  const data = await guild.client.rest.get(
5014
- import_types29.Routes.guildMemberMe(guild.id),
6054
+ import_types35.Routes.guildMemberMe(guild.id),
5015
6055
  { auth: true }
5016
6056
  );
6057
+ if (!data?.user?.id) {
6058
+ throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
6059
+ }
5017
6060
  return cacheMember(guild, data);
5018
6061
  }
5019
6062
 
5020
6063
  // src/Domain/Guild/Moderation.ts
5021
- var import_types31 = require("@fluxerjs/types");
6064
+ var import_types37 = require("@fluxerjs/types");
5022
6065
 
5023
6066
  // src/Domain/Guild/GuildBan.ts
5024
- var import_types30 = require("@fluxerjs/types");
6067
+ var import_types36 = require("@fluxerjs/types");
5025
6068
  function parseOptionalDate2(value) {
5026
6069
  if (value == null || value === "") return null;
5027
6070
  const date = new Date(value);
@@ -5048,7 +6091,7 @@ var GuildBan = class extends Base {
5048
6091
  * Requires Ban Members permission.
5049
6092
  */
5050
6093
  async unban(reason) {
5051
- await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
6094
+ await this.client.rest.delete(import_types36.Routes.guildBan(this.guildId, this.user.id), {
5052
6095
  auth: true,
5053
6096
  ...auditReasonHeaders(reason)
5054
6097
  });
@@ -5058,35 +6101,39 @@ var GuildBan = class extends Base {
5058
6101
  // src/Domain/Guild/Moderation.ts
5059
6102
  async function ban(guild, userId, options) {
5060
6103
  const body = options ? toGuildBanBody(options) : {};
5061
- await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
6104
+ await guild.client.rest.put(import_types37.Routes.guildBan(guild.id, userId), {
5062
6105
  body: Object.keys(body).length ? body : void 0,
5063
6106
  auth: true,
5064
6107
  ...auditReasonHeaders(options?.reason)
5065
6108
  });
5066
6109
  }
6110
+ async function fetchBan(guild, userId) {
6111
+ const data = await guild.client.rest.get(import_types37.Routes.guildBan(guild.id, userId));
6112
+ return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
6113
+ }
5067
6114
  async function fetchBans(guild) {
5068
- const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
6115
+ const data = await guild.client.rest.get(import_types37.Routes.guildBans(guild.id));
5069
6116
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
5070
6117
  }
5071
6118
  async function unban(guild, userId, reason) {
5072
- await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
6119
+ await guild.client.rest.delete(import_types37.Routes.guildBan(guild.id, userId), {
5073
6120
  auth: true,
5074
6121
  ...auditReasonHeaders(reason)
5075
6122
  });
5076
6123
  }
5077
6124
  async function kick(guild, userId, reason) {
5078
- await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
6125
+ await guild.client.rest.delete(import_types37.Routes.guildMember(guild.id, userId), {
5079
6126
  auth: true,
5080
6127
  ...auditReasonHeaders(reason)
5081
6128
  });
5082
6129
  }
5083
6130
 
5084
6131
  // src/Domain/Guild/Roles.ts
5085
- var import_types32 = require("@fluxerjs/types");
6132
+ var import_types38 = require("@fluxerjs/types");
5086
6133
  var import_util21 = require("@fluxerjs/util");
5087
6134
  async function createRole(guild, options = {}) {
5088
6135
  const body = toRoleCreateBody(options);
5089
- const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
6136
+ const data = await guild.client.rest.post(import_types38.Routes.guildRoles(guild.id), {
5090
6137
  body: Object.keys(body).length ? body : void 0,
5091
6138
  auth: true,
5092
6139
  ...auditReasonHeaders(options.reason)
@@ -5094,12 +6141,14 @@ async function createRole(guild, options = {}) {
5094
6141
  return cacheRole(guild, data);
5095
6142
  }
5096
6143
  async function fetchRoles(guild) {
5097
- const data = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
6144
+ const data = await guild.client.rest.get(import_types38.Routes.guildRoles(guild.id));
6145
+ if (!Array.isArray(data))
6146
+ throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
5098
6147
  return data.map((r) => cacheRole(guild, r));
5099
6148
  }
5100
6149
  async function fetchRole(guild, roleId2) {
5101
6150
  try {
5102
- const data = await guild.client.rest.get(import_types32.Routes.guildRole(guild.id, roleId2));
6151
+ const data = await guild.client.rest.get(import_types38.Routes.guildRole(guild.id, roleId2));
5103
6152
  return cacheRole(guild, data);
5104
6153
  } catch (err) {
5105
6154
  rethrowMapped(err, {
@@ -5116,7 +6165,7 @@ async function resolveRoleId(guild, arg) {
5116
6165
  const needle = trimmed.toLowerCase();
5117
6166
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
5118
6167
  if (cached) return cached.id;
5119
- const roles = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
6168
+ const roles = await guild.client.rest.get(import_types38.Routes.guildRoles(guild.id));
5120
6169
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
5121
6170
  if (!role) return null;
5122
6171
  cacheRole(guild, role);
@@ -5125,7 +6174,7 @@ async function resolveRoleId(guild, arg) {
5125
6174
  async function setRolePositions(guild, updates) {
5126
6175
  return replaceRoles(
5127
6176
  guild,
5128
- await guild.client.rest.patch(import_types32.Routes.guildRoles(guild.id), {
6177
+ await guild.client.rest.patch(import_types38.Routes.guildRoles(guild.id), {
5129
6178
  body: updates,
5130
6179
  auth: true
5131
6180
  })
@@ -5134,7 +6183,7 @@ async function setRolePositions(guild, updates) {
5134
6183
  async function setRoleHoistPositions(guild, updates) {
5135
6184
  return replaceRoles(
5136
6185
  guild,
5137
- await guild.client.rest.patch(import_types32.Routes.guildRolesHoistPositions(guild.id), {
6186
+ await guild.client.rest.patch(import_types38.Routes.guildRolesHoistPositions(guild.id), {
5138
6187
  body: updates.map((u) => ({
5139
6188
  id: u.id,
5140
6189
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -5146,17 +6195,17 @@ async function setRoleHoistPositions(guild, updates) {
5146
6195
  async function resetRoleHoistPositions(guild) {
5147
6196
  return replaceRoles(
5148
6197
  guild,
5149
- await guild.client.rest.delete(import_types32.Routes.guildRolesHoistPositions(guild.id), {
6198
+ await guild.client.rest.delete(import_types38.Routes.guildRolesHoistPositions(guild.id), {
5150
6199
  auth: true
5151
6200
  })
5152
6201
  );
5153
6202
  }
5154
6203
 
5155
6204
  // src/Domain/Guild/Stickers.ts
5156
- var import_types33 = require("@fluxerjs/types");
6205
+ var import_types39 = require("@fluxerjs/types");
5157
6206
  async function createSticker(guild, options) {
5158
6207
  const { reason, ...body } = options;
5159
- const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
6208
+ const data = await guild.client.rest.post(import_types39.Routes.guildStickers(guild.id), {
5160
6209
  body,
5161
6210
  auth: true,
5162
6211
  ...auditReasonHeaders(reason)
@@ -5164,7 +6213,7 @@ async function createSticker(guild, options) {
5164
6213
  return cacheSticker(guild, data);
5165
6214
  }
5166
6215
  async function cloneSticker(guild, sourceStickerId) {
5167
- const data = await guild.client.rest.post(import_types33.Routes.guildStickersClone(guild.id), {
6216
+ const data = await guild.client.rest.post(import_types39.Routes.guildStickersClone(guild.id), {
5168
6217
  body: { source_sticker_id: sourceStickerId },
5169
6218
  auth: true
5170
6219
  });
@@ -5172,17 +6221,17 @@ async function cloneSticker(guild, sourceStickerId) {
5172
6221
  }
5173
6222
  async function createStickersBulk(guild, stickers) {
5174
6223
  const data = await guild.client.rest.post(
5175
- import_types33.Routes.guildStickersBulk(guild.id),
6224
+ import_types39.Routes.guildStickersBulk(guild.id),
5176
6225
  { body: { stickers }, auth: true }
5177
6226
  );
5178
6227
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
5179
6228
  }
5180
6229
  async function fetchStickers(guild) {
5181
- const data = await guild.client.rest.get(import_types33.Routes.guildStickers(guild.id));
6230
+ const data = await guild.client.rest.get(import_types39.Routes.guildStickers(guild.id));
5182
6231
  return data.map((s) => cacheSticker(guild, s));
5183
6232
  }
5184
6233
  async function fetchSticker(guild, stickerId) {
5185
- const data = await guild.client.rest.get(import_types33.Routes.guildSticker(guild.id, stickerId));
6234
+ const data = await guild.client.rest.get(import_types39.Routes.guildSticker(guild.id, stickerId));
5186
6235
  return cacheSticker(guild, data);
5187
6236
  }
5188
6237
 
@@ -5194,6 +6243,11 @@ var Guild = class extends Base {
5194
6243
  id;
5195
6244
  /** Whether the guild is currently available through the gateway. */
5196
6245
  available = true;
6246
+ /**
6247
+ * True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
6248
+ * and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
6249
+ */
6250
+ partial = true;
5197
6251
  /** Guild name. */
5198
6252
  name;
5199
6253
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -5299,7 +6353,7 @@ var Guild = class extends Base {
5299
6353
  this.systemChannelFlags = data.system_channel_flags ?? 0;
5300
6354
  this.splashCardAlignment = data.splash_card_alignment ?? 0;
5301
6355
  this.embedSplash = data.embed_splash ?? null;
5302
- this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
6356
+ this.nsfwLevel = data.nsfw_level ?? import_types40.GuildNSFWLevel.Safe;
5303
6357
  this.nsfw = data.nsfw ?? false;
5304
6358
  this.contentWarningLevel = data.content_warning_level ?? 0;
5305
6359
  this.contentWarningText = data.content_warning_text ?? null;
@@ -5347,7 +6401,7 @@ var Guild = class extends Base {
5347
6401
  this.splashCardAlignment = data.splash_card_alignment ?? 0;
5348
6402
  }
5349
6403
  if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
5350
- if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
6404
+ if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types40.GuildNSFWLevel.Safe;
5351
6405
  if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
5352
6406
  if (data.content_warning_level !== void 0) {
5353
6407
  this.contentWarningLevel = data.content_warning_level ?? 0;
@@ -5414,7 +6468,7 @@ var Guild = class extends Base {
5414
6468
  });
5415
6469
  }
5416
6470
  /**
5417
- * Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
6471
+ * Create a channel. `type`: 0=text, 2=voice, 4=category, 5=announcement, 15=forum, 16=media, 998=link (set `url`).
5418
6472
  * Requires Manage Channels.
5419
6473
  */
5420
6474
  createChannel(options) {
@@ -5424,6 +6478,10 @@ var Guild = class extends Base {
5424
6478
  fetchChannels() {
5425
6479
  return fetchChannels(this);
5426
6480
  }
6481
+ /** Fetch active threads in this guild. */
6482
+ fetchActiveThreads() {
6483
+ return fetchActiveThreads(this.client, this.id);
6484
+ }
5427
6485
  /** Update channel positions (reordering). */
5428
6486
  setChannelPositions(updates) {
5429
6487
  return setChannelPositions(this, updates);
@@ -5484,6 +6542,10 @@ var Guild = class extends Base {
5484
6542
  ban(userId, options) {
5485
6543
  return ban(this, userId, options);
5486
6544
  }
6545
+ /** Fetch a single ban by user ID. Requires Ban Members. */
6546
+ fetchBan(userId) {
6547
+ return fetchBan(this, userId);
6548
+ }
5487
6549
  /** Fetch all bans in this guild. Requires Ban Members. */
5488
6550
  fetchBans() {
5489
6551
  return fetchBans(this);
@@ -5654,9 +6716,17 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
5654
6716
  client.guilds.set(guild.id, guild);
5655
6717
  if (resources.roles !== void 0) syncRoles(guild, resources.roles);
5656
6718
  if (resources.channels !== void 0) syncChannels(guild, resources.channels);
6719
+ if (resources.threads !== void 0) {
6720
+ syncThreads(
6721
+ guild,
6722
+ resources.threads,
6723
+ new Set((resources.channels ?? []).map((channel) => channel.id))
6724
+ );
6725
+ }
5657
6726
  if (resources.members !== void 0) mergeMembers(guild, resources.members);
5658
6727
  if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
5659
6728
  if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
6729
+ if (resources.channels !== void 0) guild.partial = false;
5660
6730
  return { guild, created, recovered };
5661
6731
  }
5662
6732
  function applyGuildSnapshotFromGateway(client, raw) {
@@ -5668,7 +6738,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
5668
6738
  channels: g.channels,
5669
6739
  members: g.members,
5670
6740
  emojis: g.emojis,
5671
- stickers: g.stickers
6741
+ stickers: g.stickers,
6742
+ // A channel list without `threads` means this session has no viewable threads.
6743
+ threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
5672
6744
  });
5673
6745
  if (g.voice_states?.length) {
5674
6746
  client.emit(Events.VoiceStatesSync, {
@@ -5680,23 +6752,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
5680
6752
  }
5681
6753
 
5682
6754
  // src/ClientCore/ClientUser.ts
5683
- var import_types35 = require("@fluxerjs/types");
6755
+ var import_types41 = require("@fluxerjs/types");
5684
6756
  var ClientUser = class extends User {
5685
6757
  /** Broadcast presence (gateway opcode 3) on all shards. */
5686
6758
  setPresence(presence) {
5687
6759
  this.client.options.presence = presence;
5688
6760
  const wire = toPresenceWire(presence);
5689
- this.client._sendToAllShards({ op: import_types35.GatewayOpcodes.PresenceUpdate, d: wire });
6761
+ this.client._sendToAllShards({ op: import_types41.GatewayOpcodes.PresenceUpdate, d: wire });
5690
6762
  }
5691
6763
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
5692
6764
  async fetch() {
5693
- const data = await this.client.rest.get(import_types35.Routes.currentUser(), { auth: true });
6765
+ const data = await this.client.rest.get(import_types41.Routes.currentUser(), { auth: true });
5694
6766
  this._patch(data);
5695
6767
  return this;
5696
6768
  }
5697
6769
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
5698
6770
  async fetchGuilds(options) {
5699
- const path = import_types35.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6771
+ const path = import_types41.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
5700
6772
  const data = await this.client.rest.get(path, { auth: true });
5701
6773
  return data.map((g) => ({
5702
6774
  id: g.id,
@@ -5720,7 +6792,7 @@ var ClientUser = class extends User {
5720
6792
  */
5721
6793
  async leaveGuild(guildId, options) {
5722
6794
  const body = options ? toSudoBody(options) : void 0;
5723
- await this.client.rest.delete(import_types35.Routes.leaveGuild(guildId), {
6795
+ await this.client.rest.delete(import_types41.Routes.leaveGuild(guildId), {
5724
6796
  body: body && Object.keys(body).length ? body : void 0,
5725
6797
  auth: true
5726
6798
  });
@@ -5728,7 +6800,7 @@ var ClientUser = class extends User {
5728
6800
  /** Delete every message authored by the caller across a guild (sudo). */
5729
6801
  async bulkDeleteMyMessagesInGuild(guildId, options) {
5730
6802
  const body = options ? toSudoBody(options) : void 0;
5731
- await this.client.rest.post(import_types35.Routes.guildBulkDeleteMine(guildId), {
6803
+ await this.client.rest.post(import_types41.Routes.guildBulkDeleteMine(guildId), {
5732
6804
  body: body && Object.keys(body).length ? body : void 0,
5733
6805
  auth: true
5734
6806
  });
@@ -5738,15 +6810,7 @@ var ClientUser = class extends User {
5738
6810
  // src/ClientCore/EventHandlers/Helpers.ts
5739
6811
  var import_util24 = require("@fluxerjs/util");
5740
6812
  function unknownUser(id) {
5741
- return {
5742
- id,
5743
- username: "Unknown",
5744
- discriminator: "0",
5745
- global_name: null,
5746
- avatar: null,
5747
- avatar_color: null,
5748
- flags: 0
5749
- };
6813
+ return { id };
5750
6814
  }
5751
6815
  function indexMember(_client, guild, data) {
5752
6816
  if (!data.user?.id) return null;
@@ -5763,6 +6827,7 @@ var channelHandlers = {
5763
6827
  if (!ch) return;
5764
6828
  indexChannel(client, ch);
5765
6829
  client.emit(Events.ChannelCreate, ch);
6830
+ if (ch.isThread()) client.emit(Events.ThreadCreate, ch);
5766
6831
  },
5767
6832
  CHANNEL_UPDATE(client, d) {
5768
6833
  const data = d;
@@ -5775,12 +6840,14 @@ var channelHandlers = {
5775
6840
  existing._patch(data);
5776
6841
  indexChannel(client, existing);
5777
6842
  client.emit(Events.ChannelUpdate, oldCh, existing);
6843
+ if (existing.isThread()) client.emit(Events.ThreadUpdate, oldCh, existing);
5778
6844
  return;
5779
6845
  }
5780
6846
  const newCh = Channel.from(client, data);
5781
6847
  if (!newCh) return;
5782
6848
  indexChannel(client, newCh);
5783
6849
  client.emit(Events.ChannelUpdate, existing ?? newCh, newCh);
6850
+ if (newCh.isThread()) client.emit(Events.ThreadUpdate, existing ?? newCh, newCh);
5784
6851
  },
5785
6852
  CHANNEL_UPDATE_BULK(client, d) {
5786
6853
  const data = d;
@@ -5802,7 +6869,11 @@ var channelHandlers = {
5802
6869
  }
5803
6870
  if (!channel) return;
5804
6871
  client.channels.delete(id);
6872
+ if (channel.isGuild() && channel.guildId) {
6873
+ client.guilds.get(channel.guildId)?.channels.delete(id);
6874
+ }
5805
6875
  client.emit(Events.ChannelDelete, channel);
6876
+ if (channel.isThread()) client.emit(Events.ThreadDelete, channel);
5806
6877
  },
5807
6878
  CHANNEL_PINS_UPDATE(client, d) {
5808
6879
  const data = d;
@@ -5992,6 +7063,10 @@ var guildHandlers = {
5992
7063
  }
5993
7064
  client._onGuildReceived(guild.id);
5994
7065
  },
7066
+ /** Same snapshot as Guild Create, including `threads`. Cache only: this is not a join. */
7067
+ GUILD_SYNC(client, d) {
7068
+ applyGuildSnapshotFromGateway(client, d);
7069
+ },
5995
7070
  GUILD_UPDATE(client, d) {
5996
7071
  const guildData = normalizeGuildUpdatePayload(d);
5997
7072
  if (!guildData) return;
@@ -6040,13 +7115,13 @@ var guildHandlers = {
6040
7115
  };
6041
7116
 
6042
7117
  // src/ClientCore/EventHandlers/Invites.ts
6043
- var import_types36 = require("@fluxerjs/types");
7118
+ var import_types42 = require("@fluxerjs/types");
6044
7119
  function normalizeInviteCreate(client, payload) {
6045
7120
  const raw = (0, import_util24.asRecord)(payload);
6046
7121
  const code = (0, import_util24.str)(raw?.code);
6047
7122
  if (!raw || !code) return null;
6048
7123
  const typeNum = (0, import_util24.num)(raw.type);
6049
- const type = typeNum === import_types36.InviteType.GroupDM ? import_types36.InviteType.GroupDM : import_types36.InviteType.Guild;
7124
+ const type = typeNum === import_types42.InviteType.GroupDM ? import_types42.InviteType.GroupDM : import_types42.InviteType.Guild;
6050
7125
  const shared = {
6051
7126
  code,
6052
7127
  inviter: raw.inviter ?? null,
@@ -6063,17 +7138,17 @@ function normalizeInviteCreate(client, payload) {
6063
7138
  const guildId = (0, import_util24.str)(guildObj?.id) ?? (0, import_util24.str)(raw.guild_id) ?? "0";
6064
7139
  const channelId = (0, import_util24.str)(channelObj?.id) ?? (0, import_util24.str)(raw.channel_id) ?? "0";
6065
7140
  const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
6066
- const cachedChannel = channelId !== "0" ? client.channels.get(channelId) : null;
7141
+ const cachedChannel2 = channelId !== "0" ? client.channels.get(channelId) : null;
6067
7142
  const channel = {
6068
7143
  id: channelId,
6069
- type: (0, import_util24.num)(channelObj?.type) ?? cachedChannel?.type ?? import_types36.ChannelType.GuildText,
6070
- name: (0, import_util24.str)(channelObj?.name) ?? cachedChannel?.name ?? null,
7144
+ type: (0, import_util24.num)(channelObj?.type) ?? cachedChannel2?.type ?? import_types42.ChannelType.GuildText,
7145
+ name: (0, import_util24.str)(channelObj?.name) ?? cachedChannel2?.name ?? null,
6071
7146
  icon: channelObj?.icon ?? null
6072
7147
  };
6073
- if (type === import_types36.InviteType.GroupDM) return { ...shared, type, channel };
7148
+ if (type === import_types42.InviteType.GroupDM) return { ...shared, type, channel };
6074
7149
  return {
6075
7150
  ...shared,
6076
- type: import_types36.InviteType.Guild,
7151
+ type: import_types42.InviteType.Guild,
6077
7152
  guild: {
6078
7153
  id: guildId,
6079
7154
  name: (0, import_util24.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
@@ -6416,6 +7491,9 @@ var passthroughHandlers = {
6416
7491
  VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
6417
7492
  VOICE_STATE_ACK: pass(Events.VoiceStateAck),
6418
7493
  ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
7494
+ VOICE_SIGNAL: pass(Events.VoiceSignal),
7495
+ GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
7496
+ OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
6419
7497
  TYPING_START(client, d) {
6420
7498
  const data = d;
6421
7499
  const payload = {
@@ -6471,6 +7549,107 @@ var passthroughHandlers = {
6471
7549
  WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
6472
7550
  };
6473
7551
 
7552
+ // src/ClientCore/EventHandlers/Threads.ts
7553
+ function cachedChannel(client, id) {
7554
+ const direct = client.channels.get(id);
7555
+ if (direct) return direct;
7556
+ for (const guild of client.guilds.values()) {
7557
+ const nested = guild.channels.get(id);
7558
+ if (nested) return nested;
7559
+ }
7560
+ return null;
7561
+ }
7562
+ var threadHandlers = {
7563
+ THREAD_CREATE(client, d) {
7564
+ channelHandlers.CHANNEL_CREATE(client, d);
7565
+ },
7566
+ THREAD_UPDATE(client, d) {
7567
+ channelHandlers.CHANNEL_UPDATE(client, d);
7568
+ },
7569
+ THREAD_DELETE(client, d) {
7570
+ const data = d;
7571
+ const existing = data.id ? cachedChannel(client, data.id) : null;
7572
+ if (existing?.isThread()) {
7573
+ channelHandlers.CHANNEL_DELETE(client, data);
7574
+ return;
7575
+ }
7576
+ if (!data.id || !isThreadType(data.type)) return;
7577
+ const thread = Channel.from(client, {
7578
+ id: data.id,
7579
+ type: data.type,
7580
+ guild_id: data.guild_id,
7581
+ parent_id: data.parent_id
7582
+ });
7583
+ if (!thread.isThread()) return;
7584
+ client.emit(Events.ChannelDelete, thread);
7585
+ client.emit(Events.ThreadDelete, thread);
7586
+ },
7587
+ THREAD_LIST_SYNC(client, d) {
7588
+ const data = d;
7589
+ const { threads } = fetchedThreadsFrom(client, {
7590
+ threads: data.threads ?? [],
7591
+ members: data.members ?? []
7592
+ });
7593
+ const payload = {
7594
+ guildId: data.guild_id,
7595
+ channelIds: data.channel_ids ?? [],
7596
+ threads
7597
+ };
7598
+ client.emit(Events.ThreadListSync, payload);
7599
+ },
7600
+ THREAD_MEMBER_UPDATE(client, d) {
7601
+ const data = d;
7602
+ const member = new ThreadMember(data);
7603
+ const thread = member.id ? client.channels.get(member.id) : void 0;
7604
+ if (thread?.isThread() && member.userId && member.userId === client.user?.id) {
7605
+ thread.member = member;
7606
+ }
7607
+ client.emit(Events.ThreadMemberUpdate, member);
7608
+ },
7609
+ THREAD_MEMBERS_UPDATE(client, d) {
7610
+ const data = d;
7611
+ const thread = client.channels.get(data.id);
7612
+ if (thread?.isThread()) thread.memberCount = data.member_count;
7613
+ const payload = {
7614
+ id: data.id,
7615
+ guildId: data.guild_id,
7616
+ memberCount: data.member_count,
7617
+ addedMembers: (data.added_members ?? []).map((member) => new ThreadMember(member)),
7618
+ removedMemberIds: data.removed_member_ids ?? []
7619
+ };
7620
+ client.emit(Events.ThreadMembersUpdate, payload);
7621
+ },
7622
+ THREAD_MEMBER_LIST_UPDATE(client, d) {
7623
+ const data = d;
7624
+ const guild = data.guild_id ? client.guilds.get(data.guild_id) : void 0;
7625
+ const payload = {
7626
+ guildId: data.guild_id,
7627
+ threadId: data.thread_id,
7628
+ members: (data.members ?? []).map((entry) => ({
7629
+ userId: entry.user_id,
7630
+ joinTimestamp: entry.join_timestamp,
7631
+ flags: entry.flags,
7632
+ member: guild && entry.member?.user?.id ? cacheMember(guild, entry.member) : null,
7633
+ presence: entry.presence ? { status: entry.presence.status ?? null } : null
7634
+ }))
7635
+ };
7636
+ client.emit(Events.ThreadMemberListUpdate, payload);
7637
+ },
7638
+ FORUM_UNREADS(client, d) {
7639
+ const data = d;
7640
+ const payload = {
7641
+ guildId: data.guild_id,
7642
+ channelId: data.channel_id,
7643
+ threads: (data.threads ?? []).map((entry) => ({
7644
+ threadId: entry.thread_id,
7645
+ count: entry.count ?? null,
7646
+ missing: entry.missing === true
7647
+ }))
7648
+ };
7649
+ client.emit(Events.ForumUnreads, payload);
7650
+ }
7651
+ };
7652
+
6474
7653
  // src/ClientCore/EventHandlers/index.ts
6475
7654
  var eventHandlers = buildRegistry(
6476
7655
  messageHandlers,
@@ -6479,7 +7658,8 @@ var eventHandlers = buildRegistry(
6479
7658
  memberHandlers,
6480
7659
  inviteHandlers,
6481
7660
  guildResourceHandlers,
6482
- passthroughHandlers
7661
+ passthroughHandlers,
7662
+ threadHandlers
6483
7663
  );
6484
7664
 
6485
7665
  // src/ClientCore/GatewayDispatch.ts
@@ -6504,29 +7684,63 @@ function handleGatewayDispatch(client, payload, deferred) {
6504
7684
  }
6505
7685
  return dispatchGatewayPayload(client, payload);
6506
7686
  }
6507
- function dispatchGatewayPayload(client, payload) {
7687
+ var dispatchQueues = /* @__PURE__ */ new WeakMap();
7688
+ function queueFor(client) {
7689
+ let queue = dispatchQueues.get(client);
7690
+ if (!queue) {
7691
+ queue = { tail: Promise.resolve(), pending: 0 };
7692
+ dispatchQueues.set(client, queue);
7693
+ }
7694
+ return queue;
7695
+ }
7696
+ async function runGatewayHandler(client, payload) {
6508
7697
  const event = payload.t;
6509
- if (!event) return Promise.resolve();
7698
+ if (!event) return;
6510
7699
  const handler = eventHandlers.get(event);
6511
7700
  if (!handler) {
6512
7701
  client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
6513
- return Promise.resolve();
7702
+ return;
6514
7703
  }
6515
- const run = async () => {
6516
- try {
6517
- await handler(client, payload.d);
6518
- } catch (err) {
6519
- emitClientError(client, err);
6520
- }
6521
- };
6522
- if (client.options.gatewayDeferHandlers === false) return run();
6523
- return new Promise((resolve, reject) => {
6524
- const start = () => {
6525
- void run().then(resolve).catch(reject);
6526
- };
6527
- if (typeof setImmediate === "function") setImmediate(start);
6528
- else setTimeout(start, 0);
7704
+ if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
7705
+ client.emit(
7706
+ Events.Debug,
7707
+ `[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
7708
+ );
7709
+ return;
7710
+ }
7711
+ if (client.options.gatewayDeferHandlers !== false) {
7712
+ await new Promise((resolve) => {
7713
+ if (typeof setImmediate === "function") setImmediate(resolve);
7714
+ else setTimeout(resolve, 0);
7715
+ });
7716
+ }
7717
+ try {
7718
+ await handler(client, payload.d);
7719
+ } catch (err) {
7720
+ emitClientError(client, err);
7721
+ }
7722
+ }
7723
+ function dispatchGatewayPayload(client, payload) {
7724
+ const queue = queueFor(client);
7725
+ if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
7726
+ queue.pending++;
7727
+ const run = runGatewayHandler(client, payload).finally(() => {
7728
+ queue.pending--;
7729
+ });
7730
+ queue.tail = run.catch(() => {
7731
+ });
7732
+ return run;
7733
+ }
7734
+ queue.pending++;
7735
+ const next = queue.tail.then(
7736
+ () => runGatewayHandler(client, payload),
7737
+ () => runGatewayHandler(client, payload)
7738
+ ).finally(() => {
7739
+ queue.pending--;
6529
7740
  });
7741
+ queue.tail = next.catch(() => {
7742
+ });
7743
+ return next;
6530
7744
  }
6531
7745
  async function flushDeferredGatewayDispatches(client, deferred) {
6532
7746
  while (deferred.length > 0) {
@@ -6705,7 +7919,7 @@ async function connectClientGateway(client, token, signal) {
6705
7919
 
6706
7920
  // src/ClientCore/GuildManager.ts
6707
7921
  var import_collection13 = require("@fluxerjs/collection");
6708
- var import_types37 = require("@fluxerjs/types");
7922
+ var import_types43 = require("@fluxerjs/types");
6709
7923
  var GuildManager = class extends import_collection13.LimitedCollection {
6710
7924
  constructor(client) {
6711
7925
  super({
@@ -6714,6 +7928,7 @@ var GuildManager = class extends import_collection13.LimitedCollection {
6714
7928
  });
6715
7929
  this.client = client;
6716
7930
  }
7931
+ pendingFetches = /* @__PURE__ */ new Map();
6717
7932
  /**
6718
7933
  * Remove a guild from cache and cascade its channels / message caches.
6719
7934
  * Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
@@ -6728,35 +7943,73 @@ var GuildManager = class extends import_collection13.LimitedCollection {
6728
7943
  }
6729
7944
  /**
6730
7945
  * Get a guild from cache or fetch from the API if not present.
7946
+ * Partial (metadata-only) cached guilds are hydrated first.
6731
7947
  * @param guildId - Snowflake of the guild
6732
7948
  * @returns The guild
6733
7949
  * @throws FluxerError with GUILD_NOT_FOUND if missing
6734
7950
  */
6735
7951
  async resolve(guildId) {
6736
- return this.get(guildId) ?? this.fetch(guildId);
7952
+ const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
7953
+ const cached = this.get(id);
7954
+ if (cached && !cached.partial) return cached;
7955
+ if (cached) {
7956
+ await dedupeFetch(this.pendingFetches, id, async () => {
7957
+ await this.hydrate(cached);
7958
+ return cached;
7959
+ });
7960
+ return cached;
7961
+ }
7962
+ const guild = await this.fetch(id);
7963
+ await dedupeFetch(this.pendingFetches, id, async () => {
7964
+ await this.hydrate(guild);
7965
+ return guild;
7966
+ });
7967
+ return guild;
6737
7968
  }
6738
7969
  /**
6739
7970
  * Fetch a guild by ID.
6740
- * Returns the cached guild unless `force` is set, in which case REST metadata is applied via `_patch`.
7971
+ * Returns the cached guild unless `force` is set, in which case REST metadata
7972
+ * is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
6741
7973
  * @throws FluxerError with GUILD_NOT_FOUND if missing
6742
7974
  */
6743
7975
  async fetch(guildId, options) {
6744
- const cached = this.get(guildId);
7976
+ const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
7977
+ const cached = this.get(id);
6745
7978
  if (cached && !options?.force) return cached;
6746
- try {
6747
- const data = await this.client.rest.get(import_types37.Routes.guild(guildId));
6748
- if (cached) {
6749
- cached._patch(data);
6750
- return cached;
7979
+ return dedupeFetch(this.pendingFetches, id, async () => {
7980
+ try {
7981
+ const data = assertApiObjectWithId(
7982
+ await this.client.rest.get(import_types43.Routes.guild(id)),
7983
+ "guilds.fetch()"
7984
+ );
7985
+ let guild;
7986
+ const existing = this.get(id);
7987
+ if (existing) {
7988
+ existing._patch(data);
7989
+ guild = existing;
7990
+ } else {
7991
+ guild = new Guild(this.client, data);
7992
+ this.set(guild.id, guild);
7993
+ }
7994
+ return guild;
7995
+ } catch (err) {
7996
+ rethrowMapped(err, {
7997
+ notFound: { code: import_util3.ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
7998
+ fallback: `Failed to fetch guild ${id}`
7999
+ });
6751
8000
  }
6752
- const guild = new Guild(this.client, data);
6753
- this.set(guild.id, guild);
6754
- return guild;
8001
+ });
8002
+ }
8003
+ /** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
8004
+ async hydrate(guild) {
8005
+ try {
8006
+ await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
8007
+ guild.partial = false;
6755
8008
  } catch (err) {
6756
- rethrowMapped(err, {
6757
- notFound: { code: import_util3.ErrorCodes.GuildNotFound, message: `Guild ${guildId} not found` },
6758
- fallback: `Failed to fetch guild ${guildId}`
6759
- });
8009
+ this.client.emit(
8010
+ Events.Debug,
8011
+ `[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
8012
+ );
6760
8013
  }
6761
8014
  }
6762
8015
  };
@@ -6781,6 +8034,10 @@ var MessageCache = class {
6781
8034
  if (limit === false) return;
6782
8035
  if (!this.caches) this.caches = /* @__PURE__ */ new Map();
6783
8036
  let cache = this.caches.get(channelId);
8037
+ if (cache) {
8038
+ this.caches.delete(channelId);
8039
+ this.caches.set(channelId, cache);
8040
+ }
6784
8041
  if (!cache) {
6785
8042
  const channelLimit = this.getChannelLimit();
6786
8043
  if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
@@ -6831,13 +8088,14 @@ var MessageCache = class {
6831
8088
 
6832
8089
  // src/ClientCore/UserManager.ts
6833
8090
  var import_collection14 = require("@fluxerjs/collection");
6834
- var import_types38 = require("@fluxerjs/types");
8091
+ var import_types44 = require("@fluxerjs/types");
6835
8092
  var soft = (p) => p.catch(() => null);
6836
8093
  var UserManager = class extends import_collection14.LimitedCollection {
6837
8094
  constructor(client) {
6838
8095
  super({ maxSize: client.cache.limits.users });
6839
8096
  this.client = client;
6840
8097
  }
8098
+ pendingFetches = /* @__PURE__ */ new Map();
6841
8099
  /** Remove matching users (skips `client.user`). Returns count removed. */
6842
8100
  sweep(filter) {
6843
8101
  let removed = 0;
@@ -6851,16 +8109,30 @@ var UserManager = class extends import_collection14.LimitedCollection {
6851
8109
  }
6852
8110
  return removed;
6853
8111
  }
6854
- /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
8112
+ /**
8113
+ * Fetch a user by ID and update cache. Returns the cached user unless `force` is set
8114
+ * or the cached entry is only a partial stub (e.g. from a reaction event).
8115
+ */
6855
8116
  async fetch(userId, options) {
6856
- const cached = this.get(userId);
6857
- if (cached && !options?.force) return cached;
6858
- const data = await this.client.rest.get(import_types38.Routes.user(userId));
6859
- return this.client.getOrCreateUser(data);
8117
+ const id = normalizeSnowflakeId(userId, "users.fetch()");
8118
+ const cached = this.get(id);
8119
+ if (cached && !cached.partial && !options?.force) return cached;
8120
+ return dedupeFetch(
8121
+ this.pendingFetches,
8122
+ id,
8123
+ async () => this.client.getOrCreateUser(
8124
+ assertApiObjectWithId(
8125
+ await this.client.rest.get(import_types44.Routes.user(id)),
8126
+ "users.fetch()"
8127
+ )
8128
+ )
8129
+ );
6860
8130
  }
6861
- /** Return a cached user, otherwise {@link fetch}. */
8131
+ /** Return a cached (non-partial) user, otherwise {@link fetch}. */
6862
8132
  async resolve(userId) {
6863
- return this.get(userId) ?? this.fetch(userId);
8133
+ const id = normalizeSnowflakeId(userId, "users.resolve()");
8134
+ const cached = this.get(id);
8135
+ return cached && !cached.partial ? cached : this.fetch(id);
6864
8136
  }
6865
8137
  /**
6866
8138
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
@@ -6873,10 +8145,10 @@ var UserManager = class extends import_collection14.LimitedCollection {
6873
8145
  async fetchWithProfile(userId, options) {
6874
8146
  const guildId = options?.guildId ?? void 0;
6875
8147
  const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
6876
- this.client.rest.get(import_types38.Routes.user(userId)),
6877
- soft(this.client.rest.get(import_types38.Routes.userProfile(userId))),
6878
- guildId ? soft(this.client.rest.get(import_types38.Routes.userProfile(userId, guildId))) : null,
6879
- guildId ? soft(this.client.rest.get(import_types38.Routes.guildMember(guildId, userId))) : null
8148
+ this.client.rest.get(import_types44.Routes.user(userId)),
8149
+ soft(this.client.rest.get(import_types44.Routes.userProfile(userId))),
8150
+ guildId ? soft(this.client.rest.get(import_types44.Routes.userProfile(userId, guildId))) : null,
8151
+ guildId ? soft(this.client.rest.get(import_types44.Routes.guildMember(guildId, userId))) : null
6880
8152
  ]);
6881
8153
  const user = this.client.getOrCreateUser(userData);
6882
8154
  let member = null;
@@ -7001,7 +8273,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7001
8273
  * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
7002
8274
  * Does not log in. Call {@link login} with a token afterward.
7003
8275
  *
7004
- * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
8276
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
7005
8277
  * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
7006
8278
  * @param connectOptions - Optional abort signal for the discovery request
7007
8279
  */
@@ -7078,6 +8350,38 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7078
8350
  fetchStickerMetadata(stickerId) {
7079
8351
  return fetchStickerMetadata(this, stickerId);
7080
8352
  }
8353
+ /** Fetch the source guild of a custom emoji. */
8354
+ fetchEmojiSource(emojiId) {
8355
+ return fetchEmojiSource(this, emojiId);
8356
+ }
8357
+ /** Fetch the source guild of a custom sticker. */
8358
+ fetchStickerSource(stickerId) {
8359
+ return fetchStickerSource(this, stickerId);
8360
+ }
8361
+ /** List discovery categories. */
8362
+ fetchDiscoveryCategories() {
8363
+ return fetchDiscoveryCategories(this);
8364
+ }
8365
+ /** Search discoverable guilds. */
8366
+ searchDiscoveryGuilds(options) {
8367
+ return searchDiscoveryGuilds(this, options);
8368
+ }
8369
+ /** Fetch experiment assignments for this account. */
8370
+ fetchExperiments() {
8371
+ return fetchExperiments(this);
8372
+ }
8373
+ /** Refresh expiring attachment CDN URLs. */
8374
+ refreshAttachmentUrls(attachmentUrls) {
8375
+ return refreshAttachmentUrls(this, attachmentUrls);
8376
+ }
8377
+ /** List instance custom guild badges (`GET /instance/badges`). */
8378
+ fetchInstanceBadges(options) {
8379
+ return fetchInstanceBadges(this, options);
8380
+ }
8381
+ /** Fetch forum/media thread post data for a channel. */
8382
+ fetchChannelPostData(channelId, threadIds) {
8383
+ return fetchChannelPostData(this, channelId, threadIds);
8384
+ }
7081
8385
  /**
7082
8386
  * Fetch the current application (`/applications/@me`).
7083
8387
  * @returns Application metadata (owner, flags, RPC origins, etc.)
@@ -7172,6 +8476,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7172
8476
  * @internal
7173
8477
  */
7174
8478
  getOrCreateUser(data) {
8479
+ if (!data || typeof data.id !== "string" || data.id.length === 0) {
8480
+ throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
8481
+ }
7175
8482
  const existing = this.users.get(data.id);
7176
8483
  if (existing) {
7177
8484
  existing._patch(data);
@@ -7222,7 +8529,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7222
8529
  if (options.userIds !== void 0) data.user_ids = [...new Set(options.userIds)];
7223
8530
  if (options.presences !== void 0) data.presences = options.presences;
7224
8531
  if (options.nonce !== void 0) data.nonce = options.nonce;
7225
- this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildMembers, d: data });
8532
+ this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestGuildMembers, d: data });
7226
8533
  }
7227
8534
  /**
7228
8535
  * Request guild member/online counts via gateway opcode 15.
@@ -7237,7 +8544,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7237
8544
  }
7238
8545
  const data = { guild_ids: guildIds };
7239
8546
  if (options.nonce !== void 0) data.nonce = options.nonce;
7240
- this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildCounts, d: data });
8547
+ this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestGuildCounts, d: data });
7241
8548
  }
7242
8549
  /**
7243
8550
  * Request per-channel member counts via gateway opcode 16.
@@ -7253,7 +8560,73 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7253
8560
  if (options.channelId !== void 0) data.channel_id = options.channelId;
7254
8561
  if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
7255
8562
  if (options.nonce !== void 0) data.nonce = options.nonce;
7256
- this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestChannelMemberCounts, d: data });
8563
+ this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestChannelMemberCounts, d: data });
8564
+ }
8565
+ /**
8566
+ * Request unread counts for posts in one forum or media channel (opcode 28).
8567
+ * Listen for `forumUnreads`. The gateway keeps at most 40 posts and ignores a channel the session cannot view.
8568
+ */
8569
+ requestForumUnreads(options) {
8570
+ if (!options.guildId || !options.channelId) {
8571
+ throw new import_util4.FluxerError("requestForumUnreads requires guildId and channelId", {
8572
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
8573
+ });
8574
+ }
8575
+ const threads = [];
8576
+ const seen = /* @__PURE__ */ new Set();
8577
+ for (const thread of options.threads) {
8578
+ if (!thread.threadId || seen.has(thread.threadId)) continue;
8579
+ seen.add(thread.threadId);
8580
+ const entry = { thread_id: thread.threadId };
8581
+ if (thread.ackMessageId !== void 0) entry.ack_message_id = thread.ackMessageId;
8582
+ threads.push(entry);
8583
+ }
8584
+ if (!threads.length) {
8585
+ throw new import_util4.FluxerError("requestForumUnreads requires at least one thread", {
8586
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
8587
+ });
8588
+ }
8589
+ if (threads.length > 40) {
8590
+ throw new import_util4.FluxerError("requestForumUnreads accepts at most 40 threads", {
8591
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
8592
+ });
8593
+ }
8594
+ const data = {
8595
+ guild_id: options.guildId,
8596
+ channel_id: options.channelId,
8597
+ threads
8598
+ };
8599
+ this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestForumUnreads, d: data });
8600
+ }
8601
+ /**
8602
+ * Subscribe to thread traffic in a guild (opcode 14).
8603
+ * `threads: true` receives every thread event in the guild.
8604
+ * `threadIds` (at most 10) subscribes to those member lists. Each one arrives as `threadMemberListUpdate`.
8605
+ */
8606
+ subscribeThreads(options) {
8607
+ if (!options.guildId) {
8608
+ throw new import_util4.FluxerError("subscribeThreads requires guildId", {
8609
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
8610
+ });
8611
+ }
8612
+ if (options.threads === void 0 && options.threadIds === void 0) {
8613
+ throw new import_util4.FluxerError("subscribeThreads requires threads or threadIds", {
8614
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
8615
+ });
8616
+ }
8617
+ const subscription = {};
8618
+ if (options.threads !== void 0) subscription.threads = options.threads;
8619
+ if (options.threadIds !== void 0) {
8620
+ const threadIds = [...new Set(options.threadIds.filter(Boolean))];
8621
+ if (threadIds.length > 10) {
8622
+ throw new import_util4.FluxerError("subscribeThreads accepts at most 10 threadIds", {
8623
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
8624
+ });
8625
+ }
8626
+ subscription.thread_member_lists = threadIds;
8627
+ }
8628
+ const data = { subscriptions: { [options.guildId]: subscription } };
8629
+ this._sendToAllShards({ op: import_types45.GatewayOpcodes.LazyRequest, d: data });
7257
8630
  }
7258
8631
  /**
7259
8632
  * Broadcast a gateway payload to all shards.
@@ -7358,7 +8731,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7358
8731
  * @see {@link Routes}
7359
8732
  */
7360
8733
  static get Routes() {
7361
- return import_types39.Routes;
8734
+ return import_types45.Routes;
7362
8735
  }
7363
8736
  };
7364
8737
 
@@ -7725,6 +9098,10 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
7725
9098
  ErrorCodes,
7726
9099
  Events,
7727
9100
  FluxerError,
9101
+ ForumChannel,
9102
+ ForumLayout,
9103
+ ForumSortOrder,
9104
+ ForumTagSetting,
7728
9105
  GatewayOpcodes,
7729
9106
  Guild,
7730
9107
  GuildBan,
@@ -7743,6 +9120,7 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
7743
9120
  Invite,
7744
9121
  InviteType,
7745
9122
  LinkChannel,
9123
+ MediaChannel,
7746
9124
  Message,
7747
9125
  MessageAttachmentFlags,
7748
9126
  MessageCollector,
@@ -7772,6 +9150,12 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
7772
9150
  SplashCardAlignment,
7773
9151
  SystemChannelFlags,
7774
9152
  TextChannel,
9153
+ ThreadAutoArchiveDuration,
9154
+ ThreadChannel,
9155
+ ThreadManager,
9156
+ ThreadMember,
9157
+ ThreadMemberFlags,
9158
+ ThreadMemberManager,
7775
9159
  User,
7776
9160
  UserFlagsBitField,
7777
9161
  UserFlagsBits,
@@ -7788,6 +9172,7 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
7788
9172
  cdnMemberBannerURL,
7789
9173
  cdnStickerURL,
7790
9174
  createLogger,
9175
+ fetchActiveThreads,
7791
9176
  instanceDiscoveryUrl,
7792
9177
  inviteUrl,
7793
9178
  normalizeApiOrigin,