@fluxerjs/core 3.1.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -7,8 +7,11 @@ import {
7
7
  } from "@fluxerjs/builders";
8
8
  import {
9
9
  AuditLogActionType,
10
- ChannelType as ChannelType5,
10
+ ChannelType as ChannelType11,
11
11
  ContentWarningLevel,
12
+ ForumLayout,
13
+ ForumSortOrder,
14
+ ForumTagSetting,
12
15
  GatewayOpcodes as GatewayOpcodes3,
13
16
  GuildMemberProfileFlags,
14
17
  GuildNSFWLevel as GuildNSFWLevel2,
@@ -21,9 +24,11 @@ import {
21
24
  OverwriteType as OverwriteType2,
22
25
  PublicUserFlags,
23
26
  RelationshipType,
24
- Routes as Routes35,
27
+ Routes as Routes38,
25
28
  SplashCardAlignment,
26
- SystemChannelFlags
29
+ SystemChannelFlags,
30
+ ThreadAutoArchiveDuration,
31
+ ThreadMemberFlags
27
32
  } from "@fluxerjs/types";
28
33
  import {
29
34
  createLogger as createLogger2,
@@ -181,10 +186,10 @@ var CacheController = class {
181
186
 
182
187
  // src/ClientCore/ChannelManager.ts
183
188
  import { LimitedCollection } from "@fluxerjs/collection";
184
- import { Routes as Routes19 } from "@fluxerjs/types";
189
+ import { Routes as Routes22 } from "@fluxerjs/types";
185
190
 
186
191
  // src/Domain/Channel/Base.ts
187
- import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
192
+ import { ChannelType as ChannelType3, Routes as Routes7 } from "@fluxerjs/types";
188
193
  import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
189
194
 
190
195
  // src/ClientCore/MessageManager.ts
@@ -265,7 +270,132 @@ function toAttachmentUploadPlanResponse(data) {
265
270
  }
266
271
 
267
272
  // src/ClientCore/SdkOptions/Channels.ts
273
+ import { ChannelType as ChannelType2 } from "@fluxerjs/types";
268
274
  import { resolvePermissionsToBitfield } from "@fluxerjs/util";
275
+
276
+ // src/ClientCore/SdkOptions/Threads.ts
277
+ import {
278
+ ChannelType
279
+ } from "@fluxerjs/types";
280
+ function toThreadEditBody(type, options) {
281
+ const body = {};
282
+ if (options.name !== void 0) body.name = options.name;
283
+ if (options.archived !== void 0) body.archived = options.archived;
284
+ if (options.autoArchiveDuration !== void 0) {
285
+ body.auto_archive_duration = options.autoArchiveDuration;
286
+ }
287
+ if (options.locked !== void 0) body.locked = options.locked;
288
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
289
+ if (options.flags !== void 0) body.flags = options.flags;
290
+ if (options.appliedTags !== void 0 && type !== ChannelType.PrivateThread) {
291
+ body.applied_tags = options.appliedTags;
292
+ }
293
+ if (options.invitable !== void 0 && type === ChannelType.PrivateThread) {
294
+ body.invitable = options.invitable;
295
+ }
296
+ return body;
297
+ }
298
+ function toThreadParentEditBody(options) {
299
+ const body = {};
300
+ if (options.autoArchiveDuration !== void 0) {
301
+ body.default_auto_archive_duration = options.autoArchiveDuration;
302
+ }
303
+ if (options.rateLimitPerUser !== void 0) {
304
+ body.default_thread_rate_limit_per_user = options.rateLimitPerUser;
305
+ }
306
+ return body;
307
+ }
308
+ function toStartThreadBody(channelType, options) {
309
+ const type = options.type ?? (channelType === ChannelType.GuildAnnouncement ? ChannelType.AnnouncementThread : ChannelType.PublicThread);
310
+ const body = { name: options.name, type };
311
+ if (options.autoArchiveDuration !== void 0) {
312
+ body.auto_archive_duration = options.autoArchiveDuration;
313
+ }
314
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
315
+ if (options.invitable !== void 0) body.invitable = options.invitable;
316
+ return body;
317
+ }
318
+ function toStartThreadFromMessageBody(options) {
319
+ const body = { name: options.name };
320
+ if (options.autoArchiveDuration !== void 0) {
321
+ body.auto_archive_duration = options.autoArchiveDuration;
322
+ }
323
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
324
+ return body;
325
+ }
326
+ function toForumThreadMessage(body) {
327
+ const message = {};
328
+ if (body.content !== void 0) message.content = body.content;
329
+ if (body.embeds !== void 0) message.embeds = body.embeds;
330
+ if (body.attachments !== void 0) message.attachments = body.attachments;
331
+ if (body.allowed_mentions !== void 0) message.allowed_mentions = body.allowed_mentions;
332
+ if (body.flags !== void 0) message.flags = body.flags;
333
+ if (body.sticker_ids !== void 0) message.sticker_ids = body.sticker_ids;
334
+ return message;
335
+ }
336
+ function toForumTagBody(options) {
337
+ const body = { name: options.name };
338
+ if ("id" in options && options.id !== void 0) body.id = options.id;
339
+ if (options.moderated !== void 0) body.moderated = options.moderated;
340
+ if (options.emojiId !== void 0) body.emoji_id = options.emojiId;
341
+ if (options.emojiName !== void 0) body.emoji_name = options.emojiName;
342
+ return body;
343
+ }
344
+ function forumParentWire(options, includeLayout) {
345
+ const body = {};
346
+ if (options.availableTags !== void 0) {
347
+ body.available_tags = options.availableTags.map((tag) => toForumTagBody(tag));
348
+ }
349
+ if (options.defaultReactionEmoji !== void 0) {
350
+ body.default_reaction_emoji = options.defaultReactionEmoji === null ? null : reactionEmojiWire(options.defaultReactionEmoji);
351
+ }
352
+ if (options.defaultSortOrder !== void 0) body.default_sort_order = options.defaultSortOrder;
353
+ if (options.defaultTagSetting !== void 0) body.default_tag_setting = options.defaultTagSetting;
354
+ if (options.flags !== void 0) body.flags = options.flags;
355
+ if (options.defaultAutoArchiveDuration !== void 0) {
356
+ body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
357
+ }
358
+ if (options.defaultThreadRateLimitPerUser !== void 0) {
359
+ body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
360
+ }
361
+ if (includeLayout && options.defaultForumLayout !== void 0) {
362
+ body.default_forum_layout = options.defaultForumLayout;
363
+ }
364
+ return body;
365
+ }
366
+ function reactionEmojiWire(emoji) {
367
+ const body = {};
368
+ if (emoji.emojiId !== void 0) body.emoji_id = emoji.emojiId;
369
+ if (emoji.emojiName !== void 0) body.emoji_name = emoji.emojiName;
370
+ return body;
371
+ }
372
+ function toThreadMemberSettingsBody(options) {
373
+ const body = {};
374
+ if (options.flags !== void 0) body.flags = options.flags;
375
+ if (options.muted !== void 0) body.muted = options.muted;
376
+ if (options.muteConfig !== void 0) {
377
+ body.mute_config = options.muteConfig === null ? null : {
378
+ ...options.muteConfig.endTime !== void 0 ? { end_time: options.muteConfig.endTime } : {},
379
+ selected_time_window: options.muteConfig.selectedTimeWindow
380
+ };
381
+ }
382
+ return body;
383
+ }
384
+ function withQuery(path, params) {
385
+ const query = new URLSearchParams();
386
+ for (const [key, value] of Object.entries(params)) {
387
+ if (value === void 0) continue;
388
+ if (Array.isArray(value)) {
389
+ for (const item of value) query.append(key, item);
390
+ continue;
391
+ }
392
+ query.set(key, String(value));
393
+ }
394
+ const text = query.toString();
395
+ return text ? `${path}?${text}` : path;
396
+ }
397
+
398
+ // src/ClientCore/SdkOptions/Channels.ts
269
399
  function toOverwriteWire(overwrite) {
270
400
  return {
271
401
  id: overwrite.id,
@@ -276,6 +406,7 @@ function toOverwriteWire(overwrite) {
276
406
  }
277
407
  function toChannelEditBody(options) {
278
408
  const body = {};
409
+ if (options.type !== void 0) body.type = options.type;
279
410
  if (options.name !== void 0) body.name = options.name;
280
411
  if (options.topic !== void 0) body.topic = options.topic;
281
412
  if (options.url !== void 0) body.url = options.url;
@@ -325,6 +456,16 @@ function toChannelCreateBody(options) {
325
456
  body.content_warning_text = options.contentWarningText;
326
457
  }
327
458
  if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
459
+ if (options.defaultAutoArchiveDuration !== void 0) {
460
+ body.default_auto_archive_duration = options.defaultAutoArchiveDuration;
461
+ }
462
+ if (options.defaultThreadRateLimitPerUser !== void 0) {
463
+ body.default_thread_rate_limit_per_user = options.defaultThreadRateLimitPerUser;
464
+ }
465
+ const forumParent = options.type === ChannelType2.GuildForum || options.type === ChannelType2.GuildMedia;
466
+ if (forumParent) {
467
+ Object.assign(body, forumParentWire(options, options.type === ChannelType2.GuildForum));
468
+ }
328
469
  return body;
329
470
  }
330
471
  function toChannelInviteBody(options) {
@@ -1016,6 +1157,14 @@ var Events = {
1016
1157
  ChannelCreate: "channelCreate",
1017
1158
  ChannelUpdate: "channelUpdate",
1018
1159
  ChannelDelete: "channelDelete",
1160
+ ThreadCreate: "threadCreate",
1161
+ ThreadUpdate: "threadUpdate",
1162
+ ThreadDelete: "threadDelete",
1163
+ ThreadListSync: "threadListSync",
1164
+ ThreadMemberUpdate: "threadMemberUpdate",
1165
+ ThreadMembersUpdate: "threadMembersUpdate",
1166
+ ThreadMemberListUpdate: "threadMemberListUpdate",
1167
+ ForumUnreads: "forumUnreads",
1019
1168
  ChannelPinsUpdate: "channelPinsUpdate",
1020
1169
  ChannelRecipientAdd: "channelRecipientAdd",
1021
1170
  ChannelRecipientRemove: "channelRecipientRemove",
@@ -1153,6 +1302,30 @@ var ReactionCollector = class _ReactionCollector extends EventEmitter {
1153
1302
  }
1154
1303
  };
1155
1304
 
1305
+ // src/Domain/Channel/ThreadCache.ts
1306
+ function cacheThread(client, data) {
1307
+ const existing = client.channels.get(data.id);
1308
+ if (existing?.isThread() && existing.type === data.type) {
1309
+ existing._patch(data);
1310
+ placeThread(client, existing);
1311
+ return existing;
1312
+ }
1313
+ const created = Channel.from(client, data);
1314
+ if (!created.isThread()) {
1315
+ throw new FluxerError(`Channel ${data.id} is not a thread`, {
1316
+ code: ErrorCodes.InvalidChannelType
1317
+ });
1318
+ }
1319
+ placeThread(client, created);
1320
+ return created;
1321
+ }
1322
+ function placeThread(client, thread) {
1323
+ client.channels.set(thread.id, thread);
1324
+ if (!thread.guildId) return;
1325
+ const guild = client.guilds.get(thread.guildId);
1326
+ if (guild) guild.channels.set(thread.id, thread);
1327
+ }
1328
+
1156
1329
  // src/Domain/Message/Attachment.ts
1157
1330
  function toMessageAttachment(data) {
1158
1331
  return {
@@ -1624,6 +1797,8 @@ var Message = class _Message extends Base {
1624
1797
  nonce;
1625
1798
  /** IDs of custom emojis in the message classified as explicit. */
1626
1799
  nsfwEmojis;
1800
+ /** Thread started from this message, when the payload included one. */
1801
+ thread;
1627
1802
  /**
1628
1803
  * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1629
1804
  * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
@@ -1699,6 +1874,7 @@ var Message = class _Message extends Base {
1699
1874
  this.mentionRoles = data.mention_roles ?? [];
1700
1875
  this.nonce = data.nonce ?? null;
1701
1876
  this.nsfwEmojis = data.nsfw_emojis ?? [];
1877
+ this.thread = data.thread ? cacheThread(client, data.thread) : null;
1702
1878
  }
1703
1879
  /**
1704
1880
  * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
@@ -1732,6 +1908,7 @@ var Message = class _Message extends Base {
1732
1908
  this.mentionRoles = data.mention_roles ?? [];
1733
1909
  this.nonce = data.nonce ?? null;
1734
1910
  this.nsfwEmojis = data.nsfw_emojis ?? [];
1911
+ if (data.thread) this.thread = cacheThread(this.client, data.thread);
1735
1912
  }
1736
1913
  /**
1737
1914
  * Send a standalone message in this channel (not a reply).
@@ -1810,6 +1987,23 @@ var Message = class _Message extends Base {
1810
1987
  awaitReactions(options) {
1811
1988
  return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
1812
1989
  }
1990
+ /**
1991
+ * Start a thread from this message.
1992
+ * Fluxer chooses a public or announcement thread from the parent channel.
1993
+ */
1994
+ async startThread(options) {
1995
+ const data = await this.client.rest.post(
1996
+ Routes4.channelMessageThreads(this.channelId, this.id),
1997
+ {
1998
+ body: toStartThreadFromMessageBody(options),
1999
+ auth: true,
2000
+ ...auditReasonHeaders(options.reason)
2001
+ }
2002
+ );
2003
+ const thread = cacheThread(this.client, data);
2004
+ this.thread = thread;
2005
+ return thread;
2006
+ }
1813
2007
  /** Fetch the latest version of this message from the API. */
1814
2008
  async fetch() {
1815
2009
  return this.client.channels.fetchMessage(this.channelId, this.id);
@@ -2277,39 +2471,56 @@ var Channel = class extends Base {
2277
2471
  throw new Error("Channel.createDM not initialized");
2278
2472
  }
2279
2473
  /**
2280
- * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
2474
+ * Whether this channel type can carry messages (text, announcement, voice, threads, DM, group DM, notes).
2475
+ * Forum and media channels contain threads and do not accept `send`.
2281
2476
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
2282
2477
  */
2283
2478
  isTextBased() {
2284
- return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
2479
+ return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
2285
2480
  }
2286
- /** Check if this is a guild channel (text, voice, category, or link). */
2481
+ /** Check if this is a guild channel, including threads, forums, and media channels. */
2287
2482
  isGuild() {
2288
- return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
2483
+ return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildCategory || this.type === ChannelType3.GuildLink || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread || this.type === ChannelType3.GuildForum || this.type === ChannelType3.GuildMedia;
2484
+ }
2485
+ /** Check if this is a thread (public, private, or announcement). */
2486
+ isThread() {
2487
+ return this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
2488
+ }
2489
+ /** Check if this is a forum channel. */
2490
+ isForum() {
2491
+ return this.type === ChannelType3.GuildForum;
2492
+ }
2493
+ /** Check if this is a media channel. */
2494
+ isMedia() {
2495
+ return this.type === ChannelType3.GuildMedia;
2289
2496
  }
2290
2497
  /** Check if this is a guild text channel. */
2291
2498
  isText() {
2292
- return this.type === ChannelType.GuildText;
2499
+ return this.type === ChannelType3.GuildText;
2500
+ }
2501
+ /** Check if this is a guild announcement channel. */
2502
+ isAnnouncement() {
2503
+ return this.type === ChannelType3.GuildAnnouncement;
2293
2504
  }
2294
2505
  /** Check if this is a category channel. */
2295
2506
  isCategory() {
2296
- return this.type === ChannelType.GuildCategory;
2507
+ return this.type === ChannelType3.GuildCategory;
2297
2508
  }
2298
2509
  /** Check if this is a DM, group DM, or personal notes channel. */
2299
2510
  isDM() {
2300
- return this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
2511
+ return this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes;
2301
2512
  }
2302
2513
  /** Check if this is a personal notes channel. */
2303
2514
  isPersonalNotes() {
2304
- return this.type === ChannelType.DMPersonalNotes;
2515
+ return this.type === ChannelType3.DMPersonalNotes;
2305
2516
  }
2306
2517
  /** Check if this is a voice channel. */
2307
2518
  isVoice() {
2308
- return this.type === ChannelType.GuildVoice;
2519
+ return this.type === ChannelType3.GuildVoice;
2309
2520
  }
2310
2521
  /** Check if this is a link channel. */
2311
2522
  isLink() {
2312
- return this.type === ChannelType.GuildLink;
2523
+ return this.type === ChannelType3.GuildLink;
2313
2524
  }
2314
2525
  /**
2315
2526
  * Delete recent messages or an explicit ID list.
@@ -2481,7 +2692,7 @@ var Channel = class extends Base {
2481
2692
  };
2482
2693
 
2483
2694
  // src/Domain/Channel/Dm.ts
2484
- import { ChannelType as ChannelType2, Routes as Routes9 } from "@fluxerjs/types";
2695
+ import { ChannelType as ChannelType4, Routes as Routes9 } from "@fluxerjs/types";
2485
2696
 
2486
2697
  // src/Domain/Channel/TextCapable.ts
2487
2698
  import { Routes as Routes8 } from "@fluxerjs/types";
@@ -2573,7 +2784,7 @@ var DMChannel = class extends TextCapable(Channel) {
2573
2784
  * Notes-only; bots usually skip this.
2574
2785
  */
2575
2786
  async purgeMessages() {
2576
- if (this.type !== ChannelType2.DMPersonalNotes) {
2787
+ if (this.type !== ChannelType4.DMPersonalNotes) {
2577
2788
  throw new FluxerError("purgeMessages is only available on personal notes channels", {
2578
2789
  code: ErrorCodes.InvalidChannelType
2579
2790
  });
@@ -2616,6 +2827,12 @@ var DMChannel = class extends TextCapable(Channel) {
2616
2827
  }
2617
2828
  };
2618
2829
 
2830
+ // src/Domain/Channel/Forum.ts
2831
+ import {
2832
+ ChannelType as ChannelType7,
2833
+ Routes as Routes16
2834
+ } from "@fluxerjs/types";
2835
+
2619
2836
  // src/Domain/Channel/Guild.ts
2620
2837
  import { Routes as Routes13 } from "@fluxerjs/types";
2621
2838
  import { PermissionFlags } from "@fluxerjs/util";
@@ -2927,7 +3144,8 @@ var Invite = class _Invite extends Base {
2927
3144
  // src/Domain/Webhook.ts
2928
3145
  import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
2929
3146
  import {
2930
- Routes as Routes11
3147
+ Routes as Routes11,
3148
+ WebhookType
2931
3149
  } from "@fluxerjs/types";
2932
3150
  import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
2933
3151
  var Webhook = class _Webhook extends Base {
@@ -2947,6 +3165,8 @@ var Webhook = class _Webhook extends Base {
2947
3165
  token;
2948
3166
  /** The user that created this webhook. */
2949
3167
  user;
3168
+ /** Incoming or channel-follower webhook. */
3169
+ type;
2950
3170
  constructor(client, data) {
2951
3171
  super();
2952
3172
  this.client = client;
@@ -2957,6 +3177,7 @@ var Webhook = class _Webhook extends Base {
2957
3177
  this.avatar = data.avatar ?? null;
2958
3178
  this.token = data.token ?? null;
2959
3179
  this.user = client.getOrCreateUser(data.user);
3180
+ this.type = data.type ?? WebhookType.Incoming;
2960
3181
  }
2961
3182
  avatarURL(options) {
2962
3183
  return cdnAvatarURL(this.id, this.avatar, {
@@ -3067,6 +3288,7 @@ var Webhook = class _Webhook extends Base {
3067
3288
  name: options?.name ?? "Webhook",
3068
3289
  avatar: null,
3069
3290
  token,
3291
+ type: WebhookType.Incoming,
3070
3292
  user: {
3071
3293
  id: "",
3072
3294
  username: "webhook",
@@ -3186,6 +3408,23 @@ var PermissionOverwriteManager = class {
3186
3408
  }
3187
3409
  };
3188
3410
 
3411
+ // src/Domain/Channel/ThreadBind.ts
3412
+ var factory;
3413
+ var managers = /* @__PURE__ */ new WeakMap();
3414
+ function bindThreadManager(next) {
3415
+ factory = next;
3416
+ }
3417
+ function threadManagerFor(channel) {
3418
+ const existing = managers.get(channel);
3419
+ if (existing) return existing;
3420
+ if (!factory) {
3421
+ throw new Error("ThreadManager is not initialized");
3422
+ }
3423
+ const created = factory(channel);
3424
+ managers.set(channel, created);
3425
+ return created;
3426
+ }
3427
+
3189
3428
  // src/Domain/Channel/Guild.ts
3190
3429
  var GuildChannel = class extends Channel {
3191
3430
  /** Guild ID this channel belongs to, or null if missing from the payload. */
@@ -3306,6 +3545,10 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3306
3545
  contentWarningLevel;
3307
3546
  /** Custom content warning text. */
3308
3547
  contentWarningText;
3548
+ /** Default auto-archive duration in minutes for new threads. */
3549
+ defaultAutoArchiveDuration;
3550
+ /** Slowmode in seconds copied onto new threads. */
3551
+ defaultThreadRateLimitPerUser;
3309
3552
  constructor(client, data) {
3310
3553
  super(client, data);
3311
3554
  this.topic = data.topic ?? null;
@@ -3315,6 +3558,12 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3315
3558
  this.lastMessageId = data.last_message_id ?? null;
3316
3559
  this.contentWarningLevel = data.content_warning_level ?? null;
3317
3560
  this.contentWarningText = data.content_warning_text ?? null;
3561
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
3562
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
3563
+ }
3564
+ /** Create, list, and search threads in this channel. */
3565
+ get threads() {
3566
+ return threadManagerFor(this);
3318
3567
  }
3319
3568
  /**
3320
3569
  * Set slowmode (seconds between messages). Pass `0` to disable.
@@ -3335,8 +3584,29 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3335
3584
  if ("content_warning_text" in data) {
3336
3585
  this.contentWarningText = data.content_warning_text ?? null;
3337
3586
  }
3587
+ if ("default_auto_archive_duration" in data) {
3588
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
3589
+ }
3590
+ if ("default_thread_rate_limit_per_user" in data) {
3591
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
3592
+ }
3593
+ }
3594
+ /**
3595
+ * Set the auto-archive and slowmode defaults copied onto new threads.
3596
+ * Sends only those fields. The thread-parent update body does not accept a channel rename.
3597
+ */
3598
+ async editThreadDefaults(options) {
3599
+ const data = await this.client.rest.patch(Routes13.channel(this.id), {
3600
+ body: toThreadParentEditBody(options),
3601
+ auth: true,
3602
+ ...auditReasonHeaders(options.reason)
3603
+ });
3604
+ this._patch(data);
3605
+ return this;
3338
3606
  }
3339
3607
  };
3608
+ var AnnouncementChannel = class extends TextChannel {
3609
+ };
3340
3610
  var CategoryChannel = class extends GuildChannel {
3341
3611
  };
3342
3612
  var VoiceChannel = class extends TextCapable(GuildChannel) {
@@ -3415,25 +3685,522 @@ var LinkChannel = class extends GuildChannel {
3415
3685
  }
3416
3686
  };
3417
3687
 
3688
+ // src/Domain/Channel/ThreadManager.ts
3689
+ import { ChannelType as ChannelType6, Routes as Routes15 } from "@fluxerjs/types";
3690
+
3691
+ // src/Domain/Channel/ThreadChannel.ts
3692
+ import { ChannelType as ChannelType5, Routes as Routes14 } from "@fluxerjs/types";
3693
+ var ThreadMember = class {
3694
+ /** Thread ID. */
3695
+ id;
3696
+ /** User ID. */
3697
+ userId;
3698
+ /** When the user last joined the thread. */
3699
+ joinedAt;
3700
+ /** Thread member flags bitfield. */
3701
+ flags;
3702
+ /** Whether the current user has muted the thread. */
3703
+ muted;
3704
+ /** ISO-8601 timestamp when the mute expires, if set. */
3705
+ muteEndTime;
3706
+ /** Selected mute duration in seconds, if set. */
3707
+ muteWindow;
3708
+ constructor(data) {
3709
+ this.id = data.id ?? null;
3710
+ this.userId = data.user_id ?? data.member?.user?.id ?? null;
3711
+ this.joinedAt = new Date(data.join_timestamp);
3712
+ this.flags = data.flags;
3713
+ this.muted = data.muted ?? null;
3714
+ this.muteEndTime = data.mute_config?.end_time ?? null;
3715
+ this.muteWindow = data.mute_config?.selected_time_window ?? null;
3716
+ }
3717
+ };
3718
+ function threadEditFields(options) {
3719
+ const source = options;
3720
+ return {
3721
+ name: typeof source.name === "string" ? source.name : void 0,
3722
+ archived: source.archived,
3723
+ autoArchiveDuration: source.autoArchiveDuration,
3724
+ locked: source.locked,
3725
+ rateLimitPerUser: source.rateLimitPerUser,
3726
+ flags: source.flags,
3727
+ appliedTags: source.appliedTags,
3728
+ invitable: source.invitable,
3729
+ reason: source.reason
3730
+ };
3731
+ }
3732
+ function readMetadata(data) {
3733
+ return {
3734
+ archived: data?.archived ?? false,
3735
+ autoArchiveDuration: data?.auto_archive_duration ?? 0,
3736
+ archiveTimestamp: data?.archive_timestamp ?? null,
3737
+ locked: data?.locked ?? false,
3738
+ invitable: data?.invitable ?? null
3739
+ };
3740
+ }
3741
+ var ThreadChannel = class extends TextCapable(GuildChannel) {
3742
+ /** User who created the thread. */
3743
+ ownerId;
3744
+ /** Whether the thread is archived. */
3745
+ archived;
3746
+ /** Minutes of inactivity before the thread archives. */
3747
+ autoArchiveDuration;
3748
+ /** ISO-8601 timestamp when the archive status last changed. */
3749
+ archiveTimestamp;
3750
+ /** Whether only moderators can unarchive the thread. */
3751
+ locked;
3752
+ /** Whether non-moderators can add other non-moderators. Private threads only. */
3753
+ invitable;
3754
+ /** Slowmode in seconds. */
3755
+ rateLimitPerUser;
3756
+ /** ID of the last message sent in this thread. */
3757
+ lastMessageId;
3758
+ /** Messages in the thread, excluding the starter and deleted messages. */
3759
+ messageCount;
3760
+ /** Messages ever sent in the thread. This count is never decremented. */
3761
+ totalMessageSent;
3762
+ /** Approximate member count, capped at 50. */
3763
+ memberCount;
3764
+ /** Tag IDs applied to a forum or media post. */
3765
+ appliedTags;
3766
+ /** Channel flags bitfield. */
3767
+ flags;
3768
+ /** The current user's membership, when the payload included it. */
3769
+ member;
3770
+ /** Add, remove, and list members of this thread. */
3771
+ members;
3772
+ constructor(client, data) {
3773
+ super(client, data);
3774
+ const metadata = readMetadata(data.thread_metadata);
3775
+ this.ownerId = data.owner_id ?? null;
3776
+ this.archived = metadata.archived;
3777
+ this.autoArchiveDuration = metadata.autoArchiveDuration;
3778
+ this.archiveTimestamp = metadata.archiveTimestamp;
3779
+ this.locked = metadata.locked;
3780
+ this.invitable = metadata.invitable;
3781
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3782
+ this.lastMessageId = data.last_message_id ?? null;
3783
+ this.messageCount = data.message_count ?? 0;
3784
+ this.totalMessageSent = data.total_message_sent ?? 0;
3785
+ this.memberCount = data.member_count ?? 0;
3786
+ this.appliedTags = data.applied_tags ?? [];
3787
+ this.flags = data.flags ?? 0;
3788
+ this.member = data.member ? new ThreadMember(data.member) : null;
3789
+ this.members = new ThreadMemberManager(this);
3790
+ }
3791
+ /** @internal */
3792
+ _patch(data) {
3793
+ super._patch(data);
3794
+ if (data.owner_id !== void 0) this.ownerId = data.owner_id ?? null;
3795
+ if (data.thread_metadata) {
3796
+ const metadata = readMetadata(data.thread_metadata);
3797
+ this.archived = metadata.archived;
3798
+ this.autoArchiveDuration = metadata.autoArchiveDuration;
3799
+ this.archiveTimestamp = metadata.archiveTimestamp;
3800
+ this.locked = metadata.locked;
3801
+ this.invitable = metadata.invitable;
3802
+ }
3803
+ if ("rate_limit_per_user" in data && data.rate_limit_per_user !== void 0) {
3804
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3805
+ }
3806
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3807
+ if (data.message_count !== void 0) this.messageCount = data.message_count;
3808
+ if (data.total_message_sent !== void 0) this.totalMessageSent = data.total_message_sent;
3809
+ if (data.member_count !== void 0) this.memberCount = data.member_count;
3810
+ if (data.applied_tags !== void 0) this.appliedTags = data.applied_tags ?? [];
3811
+ if (data.flags !== void 0) this.flags = data.flags;
3812
+ if (data.member !== void 0) this.member = data.member ? new ThreadMember(data.member) : null;
3813
+ }
3814
+ /**
3815
+ * Edit this thread. Requires Manage Threads on public threads, or ownership on private ones.
3816
+ * `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
3817
+ */
3818
+ async edit(options) {
3819
+ const data = await this.client.rest.patch(Routes14.channel(this.id), {
3820
+ body: toThreadEditBody(this.type, threadEditFields(options)),
3821
+ auth: true,
3822
+ ...auditReasonHeaders(options.reason)
3823
+ });
3824
+ this._patch(data);
3825
+ return this;
3826
+ }
3827
+ /** Archive or unarchive this thread. */
3828
+ async setArchived(archived, reason) {
3829
+ return this.edit({ archived, reason });
3830
+ }
3831
+ /** Lock or unlock this thread. Locked threads can only be unarchived by moderators. */
3832
+ async setLocked(locked, reason) {
3833
+ return this.edit({ locked, reason });
3834
+ }
3835
+ /** Join this thread. */
3836
+ async join() {
3837
+ await this.client.rest.put(Routes14.channelThreadMemberMe(this.id), { auth: true });
3838
+ }
3839
+ /** Leave this thread. */
3840
+ async leave() {
3841
+ await this.client.rest.delete(Routes14.channelThreadMemberMe(this.id), { auth: true });
3842
+ }
3843
+ /** Update the current user's notification settings for this thread. */
3844
+ async editSelf(options) {
3845
+ const data = await this.client.rest.patch(
3846
+ Routes14.channelThreadMemberMeSettings(this.id),
3847
+ { body: toThreadMemberSettingsBody(options), auth: true }
3848
+ );
3849
+ this.member = data ? new ThreadMember(data) : null;
3850
+ return this.member;
3851
+ }
3852
+ };
3853
+ var ThreadMemberManager = class {
3854
+ constructor(thread) {
3855
+ this.thread = thread;
3856
+ }
3857
+ /** List members of this thread. */
3858
+ async fetch(options) {
3859
+ const data = await this.thread.client.rest.get(
3860
+ withQuery(Routes14.channelThreadMembers(this.thread.id), {
3861
+ with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
3862
+ after: options?.after,
3863
+ limit: options?.limit
3864
+ })
3865
+ );
3866
+ return data.map((member) => new ThreadMember(member));
3867
+ }
3868
+ /** Fetch one member of this thread. */
3869
+ async fetchOne(userId, options) {
3870
+ const data = await this.thread.client.rest.get(
3871
+ withQuery(Routes14.channelThreadMember(this.thread.id, userId), {
3872
+ with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
3873
+ })
3874
+ );
3875
+ return new ThreadMember(data);
3876
+ }
3877
+ /** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
3878
+ async add(userId) {
3879
+ await this.thread.client.rest.put(Routes14.channelThreadMember(this.thread.id, userId), {
3880
+ auth: true
3881
+ });
3882
+ }
3883
+ /** Remove a user from this thread. */
3884
+ async remove(userId) {
3885
+ await this.thread.client.rest.delete(Routes14.channelThreadMember(this.thread.id, userId), {
3886
+ auth: true
3887
+ });
3888
+ }
3889
+ };
3890
+ function isThreadType(type) {
3891
+ return type === ChannelType5.AnnouncementThread || type === ChannelType5.PublicThread || type === ChannelType5.PrivateThread;
3892
+ }
3893
+
3894
+ // src/Domain/Channel/ThreadManager.ts
3895
+ var ThreadManager = class {
3896
+ constructor(channel) {
3897
+ this.channel = channel;
3898
+ }
3899
+ /**
3900
+ * Start a thread in a text or announcement channel.
3901
+ * Forum and media channels must use {@link createPost}.
3902
+ */
3903
+ async create(options) {
3904
+ if (this.channel.type === ChannelType6.GuildForum || this.channel.type === ChannelType6.GuildMedia) {
3905
+ throw new FluxerError("Forum and media channels start posts with createPost", {
3906
+ code: ErrorCodes.InvalidChannelType
3907
+ });
3908
+ }
3909
+ const data = await this.channel.client.rest.post(
3910
+ Routes15.channelThreads(this.channel.id),
3911
+ {
3912
+ body: toStartThreadBody(this.channel.type, options),
3913
+ auth: true,
3914
+ ...auditReasonHeaders(options.reason)
3915
+ }
3916
+ );
3917
+ return cacheThread(this.channel.client, data);
3918
+ }
3919
+ /**
3920
+ * Start a post in a forum or media channel.
3921
+ * The post is a public thread. `message` is its first message.
3922
+ */
3923
+ async createPost(options) {
3924
+ if (this.channel.type !== ChannelType6.GuildForum && this.channel.type !== ChannelType6.GuildMedia) {
3925
+ throw new FluxerError("createPost is for forum and media channels", {
3926
+ code: ErrorCodes.InvalidChannelType
3927
+ });
3928
+ }
3929
+ const prepared = await prepareMessagePostPayload(options.message, {
3930
+ defaultAllowedMentions: this.channel.client.options.defaultAllowedMentions
3931
+ });
3932
+ const body = {
3933
+ name: options.name,
3934
+ type: ChannelType6.PublicThread,
3935
+ message: toForumThreadMessage(prepared.body)
3936
+ };
3937
+ if (options.autoArchiveDuration !== void 0) {
3938
+ body.auto_archive_duration = options.autoArchiveDuration;
3939
+ }
3940
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
3941
+ if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
3942
+ const data = await this.channel.client.rest.post(
3943
+ Routes15.channelThreads(this.channel.id),
3944
+ {
3945
+ body,
3946
+ files: prepared.files,
3947
+ auth: true,
3948
+ ...auditReasonHeaders(options.reason)
3949
+ }
3950
+ );
3951
+ const thread = cacheThread(this.channel.client, data);
3952
+ if (data.message) {
3953
+ this.channel.client._addMessageToCache(data.message.channel_id, data.message);
3954
+ }
3955
+ return thread;
3956
+ }
3957
+ /**
3958
+ * List archived threads in this channel.
3959
+ * `before` is an ISO-8601 archive timestamp.
3960
+ */
3961
+ async fetchArchived(options) {
3962
+ const path = options.type === "private" ? Routes15.channelThreadsArchivedPrivate(this.channel.id) : Routes15.channelThreadsArchivedPublic(this.channel.id);
3963
+ const data = await this.channel.client.rest.get(
3964
+ withQuery(path, { before: options.before, limit: options.limit })
3965
+ );
3966
+ return fetchedThreadsFrom(this.channel.client, data);
3967
+ }
3968
+ /**
3969
+ * List private archived threads in this channel that the current user has joined.
3970
+ * `before` is a thread snowflake.
3971
+ */
3972
+ async fetchJoinedPrivateArchived(options) {
3973
+ const data = await this.channel.client.rest.get(
3974
+ withQuery(Routes15.channelJoinedArchivedPrivateThreads(this.channel.id), {
3975
+ before: options?.before,
3976
+ limit: options?.limit
3977
+ })
3978
+ );
3979
+ return fetchedThreadsFrom(this.channel.client, data);
3980
+ }
3981
+ /**
3982
+ * Search threads in this channel.
3983
+ * Returns `{ indexing: true }` while the search index is still building.
3984
+ */
3985
+ async search(options) {
3986
+ const data = await this.channel.client.rest.get(
3987
+ withQuery(Routes15.channelThreadSearch(this.channel.id), {
3988
+ name: options?.name,
3989
+ tag: options?.tag,
3990
+ tag_setting: options?.tagSetting,
3991
+ archived: options?.archived === void 0 ? void 0 : String(options.archived),
3992
+ sort_by: options?.sortBy,
3993
+ sort_order: options?.sortOrder,
3994
+ limit: options?.limit,
3995
+ offset: options?.offset,
3996
+ max_id: options?.maxId,
3997
+ min_id: options?.minId
3998
+ })
3999
+ );
4000
+ if (isSearchNotReady(data)) {
4001
+ return { indexing: true, retryAfter: data.retry_after, message: data.message };
4002
+ }
4003
+ const page = fetchedThreadsFrom(this.channel.client, data);
4004
+ return {
4005
+ ...page,
4006
+ hasMore: data.has_more,
4007
+ totalResults: data.total_results,
4008
+ firstMessages: (data.first_messages ?? []).map(
4009
+ (message) => new Message(this.channel.client, message)
4010
+ )
4011
+ };
4012
+ }
4013
+ /** Set the auto-archive and slowmode defaults copied onto new threads. */
4014
+ async editDefaults(options) {
4015
+ return this.channel.client.rest.patch(Routes15.channel(this.channel.id), {
4016
+ body: toThreadParentEditBody(options),
4017
+ auth: true,
4018
+ ...auditReasonHeaders(options.reason)
4019
+ });
4020
+ }
4021
+ };
4022
+ function fetchedThreadsFrom(client, data) {
4023
+ return {
4024
+ threads: (data.threads ?? []).map((thread) => cacheThread(client, thread)),
4025
+ members: (data.members ?? []).map((member) => new ThreadMember(member)),
4026
+ hasMore: data.has_more ?? false
4027
+ };
4028
+ }
4029
+ function isSearchNotReady(data) {
4030
+ return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
4031
+ }
4032
+ async function fetchActiveThreads(client, guildId) {
4033
+ const data = await client.rest.get(Routes15.guildActiveThreads(guildId));
4034
+ return fetchedThreadsFrom(client, data);
4035
+ }
4036
+
4037
+ // src/Domain/Channel/Forum.ts
4038
+ function tagsFrom(data) {
4039
+ return data ?? [];
4040
+ }
4041
+ var ThreadOnlyChannel = class extends GuildChannel {
4042
+ /** Tags that can be applied to posts. */
4043
+ availableTags;
4044
+ /** Default reaction for new posts. */
4045
+ defaultReactionEmoji;
4046
+ /** Default sort order for posts. */
4047
+ defaultSortOrder;
4048
+ /** How posts are filtered when searching by several tags. */
4049
+ defaultTagSetting;
4050
+ /** Default auto-archive duration in minutes for new posts. */
4051
+ defaultAutoArchiveDuration;
4052
+ /** Slowmode in seconds copied onto new posts. */
4053
+ defaultThreadRateLimitPerUser;
4054
+ /** Channel flags bitfield. */
4055
+ flags;
4056
+ /** Create, list, and search posts in this channel. */
4057
+ threads;
4058
+ constructor(client, data) {
4059
+ super(client, data);
4060
+ this.availableTags = tagsFrom(data.available_tags);
4061
+ this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
4062
+ this.defaultSortOrder = data.default_sort_order ?? null;
4063
+ this.defaultTagSetting = data.default_tag_setting ?? null;
4064
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
4065
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
4066
+ this.flags = data.flags ?? 0;
4067
+ this.threads = new ThreadManager(this);
4068
+ }
4069
+ /** @internal */
4070
+ _patch(data) {
4071
+ super._patch(data);
4072
+ if (data.available_tags !== void 0) this.availableTags = tagsFrom(data.available_tags);
4073
+ if ("default_reaction_emoji" in data) {
4074
+ this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
4075
+ }
4076
+ if ("default_sort_order" in data) this.defaultSortOrder = data.default_sort_order ?? null;
4077
+ if ("default_tag_setting" in data) this.defaultTagSetting = data.default_tag_setting ?? null;
4078
+ if ("default_auto_archive_duration" in data) {
4079
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
4080
+ }
4081
+ if ("default_thread_rate_limit_per_user" in data) {
4082
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
4083
+ }
4084
+ if (data.flags !== void 0) this.flags = data.flags;
4085
+ }
4086
+ /**
4087
+ * Edit this channel.
4088
+ * Tag, sort, reaction, and thread-default fields are sent with the usual channel fields.
4089
+ * `defaultForumLayout` is sent only for forum channels.
4090
+ */
4091
+ async edit(options) {
4092
+ const data = await this.client.rest.patch(Routes16.channel(this.id), {
4093
+ body: {
4094
+ ...toChannelEditBody(options),
4095
+ ...forumParentWire(options, this.type === ChannelType7.GuildForum)
4096
+ },
4097
+ auth: true,
4098
+ ...auditReasonHeaders(options.reason)
4099
+ });
4100
+ this._patch(data);
4101
+ return this;
4102
+ }
4103
+ /** Replace the tags that can be applied to posts (max 20). */
4104
+ async setAvailableTags(tags, reason) {
4105
+ return this.edit({ availableTags: tags, reason });
4106
+ }
4107
+ /** Set or clear the default reaction on new posts. */
4108
+ async setDefaultReactionEmoji(emoji, reason) {
4109
+ return this.edit({ defaultReactionEmoji: emoji, reason });
4110
+ }
4111
+ /** Set or clear the default post sort order. */
4112
+ async setDefaultSortOrder(order, reason) {
4113
+ return this.edit({ defaultSortOrder: order, reason });
4114
+ }
4115
+ /** Set or clear how posts match when several tags are selected. */
4116
+ async setDefaultTagSetting(setting, reason) {
4117
+ return this.edit({ defaultTagSetting: setting, reason });
4118
+ }
4119
+ /** Set the auto-archive and slowmode defaults copied onto new posts. */
4120
+ async editThreadDefaults(options) {
4121
+ const data = await this.client.rest.patch(Routes16.channel(this.id), {
4122
+ body: toThreadParentEditBody(options),
4123
+ auth: true,
4124
+ ...auditReasonHeaders(options.reason)
4125
+ });
4126
+ this._patch(data);
4127
+ return this;
4128
+ }
4129
+ /** Create a tag. The response replaces {@link availableTags}. */
4130
+ async createTag(options) {
4131
+ const data = await this.client.rest.post(Routes16.channelTags(this.id), {
4132
+ body: toForumTagBody(options),
4133
+ auth: true,
4134
+ ...auditReasonHeaders(options.reason)
4135
+ });
4136
+ this._patch(data);
4137
+ return this;
4138
+ }
4139
+ /** Replace a tag. The response replaces {@link availableTags}. */
4140
+ async editTag(tagId, options) {
4141
+ const data = await this.client.rest.put(Routes16.channelTag(this.id, tagId), {
4142
+ body: toForumTagBody(options),
4143
+ auth: true,
4144
+ ...auditReasonHeaders(options.reason)
4145
+ });
4146
+ this._patch(data);
4147
+ return this;
4148
+ }
4149
+ /** Delete a tag. The response replaces {@link availableTags}. */
4150
+ async deleteTag(tagId, reason) {
4151
+ const data = await this.client.rest.delete(Routes16.channelTag(this.id, tagId), {
4152
+ auth: true,
4153
+ ...auditReasonHeaders(reason)
4154
+ });
4155
+ this._patch(data);
4156
+ return this;
4157
+ }
4158
+ };
4159
+ var ForumChannel = class extends ThreadOnlyChannel {
4160
+ /** Default layout for posts. */
4161
+ defaultForumLayout;
4162
+ /** Set or clear the default post layout. */
4163
+ async setDefaultForumLayout(layout, reason) {
4164
+ return this.edit({ defaultForumLayout: layout, reason });
4165
+ }
4166
+ constructor(client, data) {
4167
+ super(client, data);
4168
+ this.defaultForumLayout = data.default_forum_layout ?? null;
4169
+ }
4170
+ /** @internal */
4171
+ _patch(data) {
4172
+ super._patch(data);
4173
+ if ("default_forum_layout" in data) this.defaultForumLayout = data.default_forum_layout ?? null;
4174
+ }
4175
+ };
4176
+ var MediaChannel = class extends ThreadOnlyChannel {
4177
+ };
4178
+
3418
4179
  // src/Domain/Channel/Factory.ts
3419
- import { ChannelType as ChannelType3 } from "@fluxerjs/types";
4180
+ import { ChannelType as ChannelType8 } from "@fluxerjs/types";
3420
4181
  var GUILD_FACTORIES = {
3421
- [ChannelType3.GuildText]: (c, d) => new TextChannel(c, d),
3422
- [ChannelType3.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3423
- [ChannelType3.GuildVoice]: (c, d) => new VoiceChannel(c, d),
3424
- [ChannelType3.GuildLink]: (c, d) => new LinkChannel(c, d)
4182
+ [ChannelType8.GuildText]: (c, d) => new TextChannel(c, d),
4183
+ [ChannelType8.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
4184
+ [ChannelType8.GuildCategory]: (c, d) => new CategoryChannel(c, d),
4185
+ [ChannelType8.GuildVoice]: (c, d) => new VoiceChannel(c, d),
4186
+ [ChannelType8.GuildLink]: (c, d) => new LinkChannel(c, d),
4187
+ [ChannelType8.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
4188
+ [ChannelType8.PublicThread]: (c, d) => new ThreadChannel(c, d),
4189
+ [ChannelType8.PrivateThread]: (c, d) => new ThreadChannel(c, d),
4190
+ [ChannelType8.GuildForum]: (c, d) => new ForumChannel(c, d),
4191
+ [ChannelType8.GuildMedia]: (c, d) => new MediaChannel(c, d)
3425
4192
  };
3426
4193
  var DM_TYPES = /* @__PURE__ */ new Set([
3427
- ChannelType3.DM,
3428
- ChannelType3.GroupDM,
3429
- ChannelType3.DMPersonalNotes
4194
+ ChannelType8.DM,
4195
+ ChannelType8.GroupDM,
4196
+ ChannelType8.DMPersonalNotes
3430
4197
  ]);
3431
4198
  function createDM(client, data) {
3432
4199
  return new DMChannel(client, data);
3433
4200
  }
3434
4201
  function channelFrom(client, data) {
3435
- const factory = GUILD_FACTORIES[data.type ?? 0];
3436
- return factory ? factory(client, data) : new GuildChannel(client, data);
4202
+ const factory2 = GUILD_FACTORIES[data.type ?? 0];
4203
+ return factory2 ? factory2(client, data) : new GuildChannel(client, data);
3437
4204
  }
3438
4205
  function channelFromOrCreate(client, data) {
3439
4206
  return DM_TYPES.has(data.type ?? 0) ? createDM(client, data) : channelFrom(client, data);
@@ -3443,9 +4210,13 @@ function channelFromOrCreate(client, data) {
3443
4210
  Channel.from = channelFrom;
3444
4211
  Channel.fromOrCreate = channelFromOrCreate;
3445
4212
  Channel.createDM = createDM;
4213
+ bindThreadManager((channel) => new ThreadManager(channel));
4214
+
4215
+ // src/Domain/Guild/Cache.ts
4216
+ import { ChannelType as ChannelType9 } from "@fluxerjs/types";
3446
4217
 
3447
4218
  // src/Domain/Guild/GuildEmoji.ts
3448
- import { Routes as Routes14 } from "@fluxerjs/types";
4219
+ import { Routes as Routes17 } from "@fluxerjs/types";
3449
4220
  import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
3450
4221
  var GuildEmoji = class extends Base {
3451
4222
  client;
@@ -3494,7 +4265,7 @@ var GuildEmoji = class extends Base {
3494
4265
  }
3495
4266
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
3496
4267
  async delete(reason) {
3497
- await this.client.rest.delete(Routes14.guildEmoji(this.guildId, this.id), {
4268
+ await this.client.rest.delete(Routes17.guildEmoji(this.guildId, this.id), {
3498
4269
  auth: true,
3499
4270
  ...auditReasonHeaders(reason)
3500
4271
  });
@@ -3507,7 +4278,7 @@ var GuildEmoji = class extends Base {
3507
4278
  */
3508
4279
  async edit(options) {
3509
4280
  const { reason, name } = options;
3510
- const data = await this.client.rest.patch(Routes14.guildEmoji(this.guildId, this.id), {
4281
+ const data = await this.client.rest.patch(Routes17.guildEmoji(this.guildId, this.id), {
3511
4282
  body: { name },
3512
4283
  auth: true,
3513
4284
  ...auditReasonHeaders(reason)
@@ -3518,7 +4289,7 @@ var GuildEmoji = class extends Base {
3518
4289
  };
3519
4290
 
3520
4291
  // src/Domain/Guild/GuildMember.ts
3521
- import { Routes as Routes16 } from "@fluxerjs/types";
4292
+ import { Routes as Routes19 } from "@fluxerjs/types";
3522
4293
  import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
3523
4294
 
3524
4295
  // src/Helpers/Permissions.ts
@@ -3542,7 +4313,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
3542
4313
 
3543
4314
  // src/Domain/Guild/GuildMemberRoleManager.ts
3544
4315
  import { Collection as Collection7 } from "@fluxerjs/collection";
3545
- import { Routes as Routes15 } from "@fluxerjs/types";
4316
+ import { Routes as Routes18 } from "@fluxerjs/types";
3546
4317
  function roleId(roleOrId) {
3547
4318
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
3548
4319
  }
@@ -3571,7 +4342,7 @@ var GuildMemberRoleManager = class {
3571
4342
  const id = roleId(roleOrId);
3572
4343
  if (this.ids.includes(id)) return;
3573
4344
  await this.member.client.rest.put(
3574
- Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
4345
+ Routes18.guildMemberRole(this.member.guild.id, this.member.id, id)
3575
4346
  );
3576
4347
  this.ids.push(id);
3577
4348
  }
@@ -3580,13 +4351,13 @@ var GuildMemberRoleManager = class {
3580
4351
  const idx = this.ids.indexOf(id);
3581
4352
  if (idx === -1) return;
3582
4353
  await this.member.client.rest.delete(
3583
- Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
4354
+ Routes18.guildMemberRole(this.member.guild.id, this.member.id, id)
3584
4355
  );
3585
4356
  this.ids.splice(idx, 1);
3586
4357
  }
3587
4358
  async set(roleIds) {
3588
4359
  const data = await this.member.client.rest.patch(
3589
- Routes15.guildMember(this.member.guild.id, this.member.id),
4360
+ Routes18.guildMember(this.member.guild.id, this.member.id),
3590
4361
  { body: { roles: roleIds }, auth: true }
3591
4362
  );
3592
4363
  this.ids = data.roles ? [...data.roles] : [];
@@ -3740,7 +4511,7 @@ var GuildMember = class _GuildMember extends Base {
3740
4511
  */
3741
4512
  async edit(options) {
3742
4513
  const isMe = this.client.user?.id === this.id;
3743
- const route = isMe ? Routes16.guildMemberMe(this.guild.id) : Routes16.guildMember(this.guild.id, this.id);
4514
+ const route = isMe ? Routes19.guildMemberMe(this.guild.id) : Routes19.guildMember(this.guild.id, this.id);
3744
4515
  const data = await this.client.rest.patch(route, {
3745
4516
  body: toMemberEditBody(options),
3746
4517
  auth: true,
@@ -3853,7 +4624,7 @@ var GuildMember = class _GuildMember extends Base {
3853
4624
  };
3854
4625
 
3855
4626
  // src/Domain/Guild/GuildSticker.ts
3856
- import { Routes as Routes17 } from "@fluxerjs/types";
4627
+ import { Routes as Routes20 } from "@fluxerjs/types";
3857
4628
  import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
3858
4629
  var GuildSticker = class extends Base {
3859
4630
  client;
@@ -3904,7 +4675,7 @@ var GuildSticker = class extends Base {
3904
4675
  }
3905
4676
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3906
4677
  async delete(reason) {
3907
- await this.client.rest.delete(Routes17.guildSticker(this.guildId, this.id), {
4678
+ await this.client.rest.delete(Routes20.guildSticker(this.guildId, this.id), {
3908
4679
  auth: true,
3909
4680
  ...auditReasonHeaders(reason)
3910
4681
  });
@@ -3917,7 +4688,7 @@ var GuildSticker = class extends Base {
3917
4688
  */
3918
4689
  async edit(options) {
3919
4690
  const { reason, ...body } = options;
3920
- const data = await this.client.rest.patch(Routes17.guildSticker(this.guildId, this.id), {
4691
+ const data = await this.client.rest.patch(Routes20.guildSticker(this.guildId, this.id), {
3921
4692
  body,
3922
4693
  auth: true,
3923
4694
  ...auditReasonHeaders(reason)
@@ -3930,7 +4701,7 @@ var GuildSticker = class extends Base {
3930
4701
  };
3931
4702
 
3932
4703
  // src/Domain/Guild/Role.ts
3933
- import { Routes as Routes18 } from "@fluxerjs/types";
4704
+ import { Routes as Routes21 } from "@fluxerjs/types";
3934
4705
  import {
3935
4706
  ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
3936
4707
  PermissionFlags as PermissionFlags4,
@@ -4045,7 +4816,7 @@ var Role = class _Role extends Base {
4045
4816
  */
4046
4817
  async edit(options) {
4047
4818
  const body = toRoleEditBody(options);
4048
- const data = await this.client.rest.patch(Routes18.guildRole(this.guildId, this.id), {
4819
+ const data = await this.client.rest.patch(Routes21.guildRole(this.guildId, this.id), {
4049
4820
  body: Object.keys(body).length ? body : void 0,
4050
4821
  auth: true,
4051
4822
  ...auditReasonHeaders(options.reason)
@@ -4058,7 +4829,7 @@ var Role = class _Role extends Base {
4058
4829
  * @param reason - Audit log reason (`X-Audit-Log-Reason`)
4059
4830
  */
4060
4831
  async delete(reason) {
4061
- await this.client.rest.delete(Routes18.guildRole(this.guildId, this.id), {
4832
+ await this.client.rest.delete(Routes21.guildRole(this.guildId, this.id), {
4062
4833
  auth: true,
4063
4834
  ...auditReasonHeaders(reason)
4064
4835
  });
@@ -4153,11 +4924,30 @@ function syncChannels(guild, channels) {
4153
4924
  const keep = new Set(channels.map((c) => c.id));
4154
4925
  for (const data of channels) cacheChannel(guild, data);
4155
4926
  for (const [id, channel] of [...guild.channels.entries()]) {
4156
- if (keep.has(id)) continue;
4927
+ if (keep.has(id) || channel.isThread()) continue;
4157
4928
  Map.prototype.delete.call(guild.channels, id);
4158
4929
  guild.client.cache.cascadeChannel(channel, "guild");
4159
4930
  }
4160
4931
  }
4932
+ function isThreadChannelType(type) {
4933
+ return type === ChannelType9.AnnouncementThread || type === ChannelType9.PublicThread || type === ChannelType9.PrivateThread;
4934
+ }
4935
+ function syncThreads(guild, threads, alsoKeep = /* @__PURE__ */ new Set()) {
4936
+ const keep = new Set(alsoKeep);
4937
+ for (const data of threads) {
4938
+ if (!isThreadChannelType(data.type)) continue;
4939
+ const withGuild = data.guild_id ? data : { ...data, guild_id: guild.id };
4940
+ cacheThread(guild.client, withGuild);
4941
+ keep.add(data.id);
4942
+ }
4943
+ const seen = /* @__PURE__ */ new Set();
4944
+ for (const channel of [...guild.channels.values(), ...guild.client.channels.values()]) {
4945
+ if (seen.has(channel.id)) continue;
4946
+ seen.add(channel.id);
4947
+ if (!channel.isThread() || channel.guildId !== guild.id || keep.has(channel.id)) continue;
4948
+ guild.client.cache.cascadeChannel(channel);
4949
+ }
4950
+ }
4161
4951
  function mergeMembers(guild, members) {
4162
4952
  for (const m of members) {
4163
4953
  if (!m.user?.id) continue;
@@ -4221,7 +5011,7 @@ var ChannelManager = class extends LimitedCollection {
4221
5011
  const cached = this.get(channelId);
4222
5012
  if (cached && !options?.force) return cached;
4223
5013
  try {
4224
- const data = await this.client.rest.get(Routes19.channel(channelId));
5014
+ const data = await this.client.rest.get(Routes22.channel(channelId));
4225
5015
  const guildId = "guild_id" in data ? data.guild_id : void 0;
4226
5016
  if (guildId) {
4227
5017
  const guild = this.client.guilds.get(guildId);
@@ -4266,7 +5056,7 @@ var ChannelManager = class extends LimitedCollection {
4266
5056
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
4267
5057
  });
4268
5058
  const data = await this.client.rest.post(
4269
- Routes19.channelMessages(channelId),
5059
+ Routes22.channelMessages(channelId),
4270
5060
  postPayload
4271
5061
  );
4272
5062
  this.client._addMessageToCache(channelId, data);
@@ -4277,11 +5067,11 @@ var ChannelManager = class extends LimitedCollection {
4277
5067
  // src/ClientCore/Client.ts
4278
5068
  import { EventEmitter as EventEmitter3 } from "events";
4279
5069
  import { REST } from "@fluxerjs/rest";
4280
- import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes34 } from "@fluxerjs/types";
5070
+ import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes37 } from "@fluxerjs/types";
4281
5071
  import { createLogger } from "@fluxerjs/util";
4282
5072
 
4283
5073
  // src/Domain/User.ts
4284
- import { Routes as Routes20 } from "@fluxerjs/types";
5074
+ import { Routes as Routes23 } from "@fluxerjs/types";
4285
5075
  import { SnowflakeUtil as SnowflakeUtil8 } from "@fluxerjs/util";
4286
5076
  var User = class extends Base {
4287
5077
  /** Parent client instance. */
@@ -4380,7 +5170,7 @@ var User = class extends Base {
4380
5170
  * @returns DM channel instance (cached if already open)
4381
5171
  */
4382
5172
  async createDM() {
4383
- const data = await this.client.rest.post(Routes20.userMeChannels(), {
5173
+ const data = await this.client.rest.post(Routes23.userMeChannels(), {
4384
5174
  body: { recipient_id: this.id },
4385
5175
  auth: true
4386
5176
  });
@@ -4458,7 +5248,7 @@ function resolveCacheLimits(input) {
4458
5248
 
4459
5249
  // src/ClientCore/ClientEmoji.ts
4460
5250
  import { Collection as Collection8 } from "@fluxerjs/collection";
4461
- import { Routes as Routes21 } from "@fluxerjs/types";
5251
+ import { Routes as Routes24 } from "@fluxerjs/types";
4462
5252
  import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
4463
5253
  async function resolveClientEmoji(client, emoji, guildId) {
4464
5254
  if (typeof emoji === "object" && emoji.id) {
@@ -4477,7 +5267,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
4477
5267
  const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
4478
5268
  if (unicodeFromShortcode) return unicodeFromShortcode;
4479
5269
  if (guildId) {
4480
- const emojis = await client.rest.get(Routes21.guildEmojis(guildId));
5270
+ const emojis = await client.rest.get(Routes24.guildEmojis(guildId));
4481
5271
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
4482
5272
  if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
4483
5273
  throw new FluxerError(
@@ -4494,26 +5284,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
4494
5284
  return parsed.name;
4495
5285
  }
4496
5286
  async function fetchInstance(client) {
4497
- const raw = await client.rest.get(Routes21.instanceDiscovery(), {
5287
+ const raw = await client.rest.get(Routes24.instanceDiscovery(), {
4498
5288
  auth: false,
4499
5289
  unversioned: true
4500
5290
  });
4501
5291
  return parseInstanceDiscovery(raw);
4502
5292
  }
4503
5293
  function fetchGatewayInfo(client) {
4504
- return client.rest.get(Routes21.gatewayBot());
5294
+ return client.rest.get(Routes24.gatewayBot());
4505
5295
  }
4506
5296
  function fetchEmojiMetadata(client, emojiId) {
4507
- return client.rest.get(Routes21.emojiMetadata(emojiId), { auth: true });
5297
+ return client.rest.get(Routes24.emojiMetadata(emojiId), { auth: true });
4508
5298
  }
4509
5299
  function fetchStickerMetadata(client, stickerId) {
4510
- return client.rest.get(Routes21.stickerMetadata(stickerId), { auth: true });
5300
+ return client.rest.get(Routes24.stickerMetadata(stickerId), { auth: true });
4511
5301
  }
4512
5302
  function fetchApplication(client) {
4513
- return client.rest.get(Routes21.applicationsMe(), { auth: true });
5303
+ return client.rest.get(Routes24.applicationsMe(), { auth: true });
4514
5304
  }
4515
5305
  async function fetchOAuthApplications(client) {
4516
- const data = await client.rest.get(Routes21.oauth2ApplicationsMe(), { auth: true });
5306
+ const data = await client.rest.get(Routes24.oauth2ApplicationsMe(), { auth: true });
4517
5307
  if (Array.isArray(data)) return data;
4518
5308
  if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
4519
5309
  return data.applications;
@@ -4532,14 +5322,14 @@ function assertChannelIdBatch(name, channelIds) {
4532
5322
  }
4533
5323
  function preloadMessages(client, channelIds) {
4534
5324
  assertChannelIdBatch("preloadMessages", channelIds);
4535
- return client.rest.post(Routes21.preloadMessages(), {
5325
+ return client.rest.post(Routes24.preloadMessages(), {
4536
5326
  body: { channels: channelIds },
4537
5327
  auth: true
4538
5328
  });
4539
5329
  }
4540
5330
  function preloadMessagesAlt(client, channelIds) {
4541
5331
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
4542
- return client.rest.post(Routes21.preloadMessagesAlt(), {
5332
+ return client.rest.post(Routes24.preloadMessagesAlt(), {
4543
5333
  body: { channels: channelIds },
4544
5334
  auth: true
4545
5335
  });
@@ -4547,7 +5337,7 @@ function preloadMessagesAlt(client, channelIds) {
4547
5337
  async function bulkFetchMessages(client, requests, options = {}) {
4548
5338
  validateBulkMessageFetchRequests(requests);
4549
5339
  const wire = toBulkFetchWire(requests);
4550
- const data = await client.rest.post(Routes21.channelsMessagesBulk(), {
5340
+ const data = await client.rest.post(Routes24.channelsMessagesBulk(), {
4551
5341
  body: { requests: wire },
4552
5342
  auth: true
4553
5343
  });
@@ -4564,7 +5354,7 @@ async function bulkFetchMessages(client, requests, options = {}) {
4564
5354
  };
4565
5355
  }
4566
5356
  async function searchMessages(client, options = {}) {
4567
- const data = await client.rest.post(Routes21.searchMessages(), {
5357
+ const data = await client.rest.post(Routes24.searchMessages(), {
4568
5358
  body: toMessageSearchBody(options),
4569
5359
  auth: true
4570
5360
  });
@@ -4594,7 +5384,7 @@ import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
4594
5384
 
4595
5385
  // src/ClientCore/GuildMemberManager.ts
4596
5386
  import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
4597
- import { Routes as Routes22 } from "@fluxerjs/types";
5387
+ import { Routes as Routes25 } from "@fluxerjs/types";
4598
5388
  var GuildMemberManager = class extends LimitedCollection2 {
4599
5389
  constructor(guild) {
4600
5390
  super({ maxSize: guild.client.cache.limits.members });
@@ -4651,7 +5441,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
4651
5441
  if (options?.limit != null) params.set("limit", String(options.limit));
4652
5442
  if (options?.after) params.set("after", options.after);
4653
5443
  const qs2 = params.toString();
4654
- const url = Routes22.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5444
+ const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
4655
5445
  const data = await this.guild.client.rest.get(url, { auth: true });
4656
5446
  const members = [];
4657
5447
  for (const m of data) {
@@ -4674,7 +5464,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
4674
5464
  */
4675
5465
  async search(options = {}) {
4676
5466
  const data = await this.guild.client.rest.post(
4677
- Routes22.guildMembersSearch(this.guild.id),
5467
+ Routes25.guildMembersSearch(this.guild.id),
4678
5468
  { body: toMemberSearchBody(options), auth: true }
4679
5469
  );
4680
5470
  const offset = options.offset ?? 0;
@@ -4700,7 +5490,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
4700
5490
  };
4701
5491
 
4702
5492
  // src/Domain/Guild/Admin.ts
4703
- import { Routes as Routes23 } from "@fluxerjs/types";
5493
+ import { Routes as Routes26 } from "@fluxerjs/types";
4704
5494
  function toAuditLogEntryPayload(entry, guildId) {
4705
5495
  return {
4706
5496
  id: entry.id,
@@ -4721,7 +5511,7 @@ function toVanityPayload(data) {
4721
5511
  return { code: data.code ?? null, uses: data.uses };
4722
5512
  }
4723
5513
  async function fetchAuditLogs(guild, options) {
4724
- const url = Routes23.guildAuditLogs(guild.id) + qs({
5514
+ const url = Routes26.guildAuditLogs(guild.id) + qs({
4725
5515
  limit: options?.limit,
4726
5516
  before: options?.before,
4727
5517
  after: options?.after,
@@ -4745,7 +5535,7 @@ async function fetchAuditLogs(guild, options) {
4745
5535
  };
4746
5536
  }
4747
5537
  async function editGuild(guild, options) {
4748
- const data = await guild.client.rest.patch(Routes23.guild(guild.id), {
5538
+ const data = await guild.client.rest.patch(Routes26.guild(guild.id), {
4749
5539
  body: toGuildEditBody(options),
4750
5540
  auth: true
4751
5541
  });
@@ -4753,13 +5543,13 @@ async function editGuild(guild, options) {
4753
5543
  return guild;
4754
5544
  }
4755
5545
  async function fetchVanityURL(guild) {
4756
- const data = await guild.client.rest.get(Routes23.guildVanityUrl(guild.id), {
5546
+ const data = await guild.client.rest.get(Routes26.guildVanityUrl(guild.id), {
4757
5547
  auth: true
4758
5548
  });
4759
5549
  return toVanityPayload(data);
4760
5550
  }
4761
5551
  async function editVanityURL(guild, code) {
4762
- const data = await guild.client.rest.patch(Routes23.guildVanityUrl(guild.id), {
5552
+ const data = await guild.client.rest.patch(Routes26.guildVanityUrl(guild.id), {
4763
5553
  body: { code },
4764
5554
  auth: true
4765
5555
  });
@@ -4767,14 +5557,14 @@ async function editVanityURL(guild, code) {
4767
5557
  return toVanityPayload(data);
4768
5558
  }
4769
5559
  async function fetchDiscoveryStatus(guild) {
4770
- const data = await guild.client.rest.get(Routes23.guildDiscovery(guild.id), {
5560
+ const data = await guild.client.rest.get(Routes26.guildDiscovery(guild.id), {
4771
5561
  auth: true
4772
5562
  });
4773
5563
  return toDiscoveryStatusPayload(data);
4774
5564
  }
4775
5565
  async function applyForDiscovery(guild, options) {
4776
5566
  const data = await guild.client.rest.post(
4777
- Routes23.guildDiscovery(guild.id),
5567
+ Routes26.guildDiscovery(guild.id),
4778
5568
  {
4779
5569
  body: toDiscoveryBody(options),
4780
5570
  auth: true
@@ -4784,7 +5574,7 @@ async function applyForDiscovery(guild, options) {
4784
5574
  }
4785
5575
  async function editDiscoveryApplication(guild, options) {
4786
5576
  const data = await guild.client.rest.patch(
4787
- Routes23.guildDiscovery(guild.id),
5577
+ Routes26.guildDiscovery(guild.id),
4788
5578
  {
4789
5579
  body: toDiscoveryBody(options),
4790
5580
  auth: true
@@ -4793,34 +5583,34 @@ async function editDiscoveryApplication(guild, options) {
4793
5583
  return toDiscoveryApplicationPayload(data);
4794
5584
  }
4795
5585
  async function withdrawDiscoveryApplication(guild) {
4796
- await guild.client.rest.delete(Routes23.guildDiscovery(guild.id), { auth: true });
5586
+ await guild.client.rest.delete(Routes26.guildDiscovery(guild.id), { auth: true });
4797
5587
  }
4798
5588
  async function deleteGuild(guild, options) {
4799
5589
  const body = options ? toSudoBody(options) : {};
4800
- await guild.client.rest.post(Routes23.guildDelete(guild.id), {
5590
+ await guild.client.rest.post(Routes26.guildDelete(guild.id), {
4801
5591
  body,
4802
5592
  auth: true
4803
5593
  });
4804
5594
  guild.client.guilds.delete(guild.id);
4805
5595
  }
4806
5596
  async function transferOwnership(guild, newOwnerId, password) {
4807
- await guild.client.rest.post(Routes23.guildTransferOwnership(guild.id), {
5597
+ await guild.client.rest.post(Routes26.guildTransferOwnership(guild.id), {
4808
5598
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
4809
5599
  auth: true
4810
5600
  });
4811
5601
  }
4812
5602
 
4813
5603
  // src/Domain/Guild/Channels.ts
4814
- import { Routes as Routes24 } from "@fluxerjs/types";
5604
+ import { Routes as Routes27 } from "@fluxerjs/types";
4815
5605
  async function createChannel(guild, options) {
4816
- const created = await guild.client.rest.post(Routes24.guildChannels(guild.id), {
5606
+ const created = await guild.client.rest.post(Routes27.guildChannels(guild.id), {
4817
5607
  body: toChannelCreateBody(options),
4818
5608
  auth: true
4819
5609
  });
4820
5610
  return cacheChannel(guild, created);
4821
5611
  }
4822
5612
  async function fetchChannels(guild) {
4823
- const data = await guild.client.rest.get(Routes24.guildChannels(guild.id));
5613
+ const data = await guild.client.rest.get(Routes27.guildChannels(guild.id));
4824
5614
  const channels = [];
4825
5615
  for (const ch of data) {
4826
5616
  const channel = cacheChannel(guild, ch);
@@ -4829,17 +5619,17 @@ async function fetchChannels(guild) {
4829
5619
  return channels;
4830
5620
  }
4831
5621
  async function setChannelPositions(guild, updates) {
4832
- await guild.client.rest.patch(Routes24.guildChannels(guild.id), {
5622
+ await guild.client.rest.patch(Routes27.guildChannels(guild.id), {
4833
5623
  body: toChannelPositionBody(updates),
4834
5624
  auth: true
4835
5625
  });
4836
5626
  }
4837
5627
  async function fetchWebhooks(guild) {
4838
- const data = await guild.client.rest.get(Routes24.guildWebhooks(guild.id));
5628
+ const data = await guild.client.rest.get(Routes27.guildWebhooks(guild.id));
4839
5629
  return data.map((w) => new Webhook(guild.client, w));
4840
5630
  }
4841
5631
  async function fetchInvites(guild) {
4842
- const data = await guild.client.rest.get(Routes24.guildInvites(guild.id));
5632
+ const data = await guild.client.rest.get(Routes27.guildInvites(guild.id));
4843
5633
  return data.map((invite) => new Invite(guild.client, invite));
4844
5634
  }
4845
5635
  async function fetchInvite(guild, codeOrUrl) {
@@ -4859,14 +5649,14 @@ function resolveGuildOnlineCount(data) {
4859
5649
  }
4860
5650
 
4861
5651
  // src/Domain/Guild/Emojis.ts
4862
- import { Routes as Routes25 } from "@fluxerjs/types";
5652
+ import { Routes as Routes28 } from "@fluxerjs/types";
4863
5653
  async function fetchEmojis(guild) {
4864
- const data = await guild.client.rest.get(Routes25.guildEmojis(guild.id));
5654
+ const data = await guild.client.rest.get(Routes28.guildEmojis(guild.id));
4865
5655
  return data.map((e) => cacheEmoji(guild, e));
4866
5656
  }
4867
5657
  async function fetchEmoji(guild, emojiId) {
4868
5658
  try {
4869
- const data = await guild.client.rest.get(Routes25.guildEmoji(guild.id, emojiId));
5659
+ const data = await guild.client.rest.get(Routes28.guildEmoji(guild.id, emojiId));
4870
5660
  return cacheEmoji(guild, data);
4871
5661
  } catch (err) {
4872
5662
  rethrowMapped(err, {
@@ -4877,7 +5667,7 @@ async function fetchEmoji(guild, emojiId) {
4877
5667
  }
4878
5668
  async function createEmoji(guild, options) {
4879
5669
  const { reason, ...body } = options;
4880
- const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
5670
+ const data = await guild.client.rest.post(Routes28.guildEmojis(guild.id), {
4881
5671
  body,
4882
5672
  auth: true,
4883
5673
  ...auditReasonHeaders(reason)
@@ -4885,7 +5675,7 @@ async function createEmoji(guild, options) {
4885
5675
  return cacheEmoji(guild, data);
4886
5676
  }
4887
5677
  async function cloneEmoji(guild, sourceEmojiId) {
4888
- const data = await guild.client.rest.post(Routes25.guildEmojisClone(guild.id), {
5678
+ const data = await guild.client.rest.post(Routes28.guildEmojisClone(guild.id), {
4889
5679
  body: { source_emoji_id: sourceEmojiId },
4890
5680
  auth: true
4891
5681
  });
@@ -4893,7 +5683,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
4893
5683
  }
4894
5684
  async function createEmojisBulk(guild, emojis) {
4895
5685
  const data = await guild.client.rest.post(
4896
- Routes25.guildEmojisBulk(guild.id),
5686
+ Routes28.guildEmojisBulk(guild.id),
4897
5687
  { body: { emojis }, auth: true }
4898
5688
  );
4899
5689
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
@@ -4913,11 +5703,11 @@ var GuildRoleManager = class extends LimitedCollection3 {
4913
5703
  };
4914
5704
 
4915
5705
  // src/Domain/Guild/MemberHttp.ts
4916
- import { Routes as Routes26 } from "@fluxerjs/types";
5706
+ import { Routes as Routes29 } from "@fluxerjs/types";
4917
5707
  async function fetchMember(guild, userId) {
4918
5708
  try {
4919
5709
  const data = await guild.client.rest.get(
4920
- Routes26.guildMember(guild.id, userId)
5710
+ Routes29.guildMember(guild.id, userId)
4921
5711
  );
4922
5712
  return cacheMember(guild, data);
4923
5713
  } catch (err) {
@@ -4932,17 +5722,17 @@ async function fetchMember(guild, userId) {
4932
5722
  }
4933
5723
  async function fetchMe(guild) {
4934
5724
  const data = await guild.client.rest.get(
4935
- Routes26.guildMemberMe(guild.id),
5725
+ Routes29.guildMemberMe(guild.id),
4936
5726
  { auth: true }
4937
5727
  );
4938
5728
  return cacheMember(guild, data);
4939
5729
  }
4940
5730
 
4941
5731
  // src/Domain/Guild/Moderation.ts
4942
- import { Routes as Routes28 } from "@fluxerjs/types";
5732
+ import { Routes as Routes31 } from "@fluxerjs/types";
4943
5733
 
4944
5734
  // src/Domain/Guild/GuildBan.ts
4945
- import { Routes as Routes27 } from "@fluxerjs/types";
5735
+ import { Routes as Routes30 } from "@fluxerjs/types";
4946
5736
  function parseOptionalDate2(value) {
4947
5737
  if (value == null || value === "") return null;
4948
5738
  const date = new Date(value);
@@ -4969,7 +5759,7 @@ var GuildBan = class extends Base {
4969
5759
  * Requires Ban Members permission.
4970
5760
  */
4971
5761
  async unban(reason) {
4972
- await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
5762
+ await this.client.rest.delete(Routes30.guildBan(this.guildId, this.user.id), {
4973
5763
  auth: true,
4974
5764
  ...auditReasonHeaders(reason)
4975
5765
  });
@@ -4979,35 +5769,35 @@ var GuildBan = class extends Base {
4979
5769
  // src/Domain/Guild/Moderation.ts
4980
5770
  async function ban(guild, userId, options) {
4981
5771
  const body = options ? toGuildBanBody(options) : {};
4982
- await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
5772
+ await guild.client.rest.put(Routes31.guildBan(guild.id, userId), {
4983
5773
  body: Object.keys(body).length ? body : void 0,
4984
5774
  auth: true,
4985
5775
  ...auditReasonHeaders(options?.reason)
4986
5776
  });
4987
5777
  }
4988
5778
  async function fetchBans(guild) {
4989
- const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
5779
+ const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
4990
5780
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
4991
5781
  }
4992
5782
  async function unban(guild, userId, reason) {
4993
- await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
5783
+ await guild.client.rest.delete(Routes31.guildBan(guild.id, userId), {
4994
5784
  auth: true,
4995
5785
  ...auditReasonHeaders(reason)
4996
5786
  });
4997
5787
  }
4998
5788
  async function kick(guild, userId, reason) {
4999
- await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
5789
+ await guild.client.rest.delete(Routes31.guildMember(guild.id, userId), {
5000
5790
  auth: true,
5001
5791
  ...auditReasonHeaders(reason)
5002
5792
  });
5003
5793
  }
5004
5794
 
5005
5795
  // src/Domain/Guild/Roles.ts
5006
- import { Routes as Routes29 } from "@fluxerjs/types";
5796
+ import { Routes as Routes32 } from "@fluxerjs/types";
5007
5797
  import { parseRoleMention } from "@fluxerjs/util";
5008
5798
  async function createRole(guild, options = {}) {
5009
5799
  const body = toRoleCreateBody(options);
5010
- const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
5800
+ const data = await guild.client.rest.post(Routes32.guildRoles(guild.id), {
5011
5801
  body: Object.keys(body).length ? body : void 0,
5012
5802
  auth: true,
5013
5803
  ...auditReasonHeaders(options.reason)
@@ -5015,12 +5805,12 @@ async function createRole(guild, options = {}) {
5015
5805
  return cacheRole(guild, data);
5016
5806
  }
5017
5807
  async function fetchRoles(guild) {
5018
- const data = await guild.client.rest.get(Routes29.guildRoles(guild.id));
5808
+ const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
5019
5809
  return data.map((r) => cacheRole(guild, r));
5020
5810
  }
5021
5811
  async function fetchRole(guild, roleId2) {
5022
5812
  try {
5023
- const data = await guild.client.rest.get(Routes29.guildRole(guild.id, roleId2));
5813
+ const data = await guild.client.rest.get(Routes32.guildRole(guild.id, roleId2));
5024
5814
  return cacheRole(guild, data);
5025
5815
  } catch (err) {
5026
5816
  rethrowMapped(err, {
@@ -5037,7 +5827,7 @@ async function resolveRoleId(guild, arg) {
5037
5827
  const needle = trimmed.toLowerCase();
5038
5828
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
5039
5829
  if (cached) return cached.id;
5040
- const roles = await guild.client.rest.get(Routes29.guildRoles(guild.id));
5830
+ const roles = await guild.client.rest.get(Routes32.guildRoles(guild.id));
5041
5831
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
5042
5832
  if (!role) return null;
5043
5833
  cacheRole(guild, role);
@@ -5046,7 +5836,7 @@ async function resolveRoleId(guild, arg) {
5046
5836
  async function setRolePositions(guild, updates) {
5047
5837
  return replaceRoles(
5048
5838
  guild,
5049
- await guild.client.rest.patch(Routes29.guildRoles(guild.id), {
5839
+ await guild.client.rest.patch(Routes32.guildRoles(guild.id), {
5050
5840
  body: updates,
5051
5841
  auth: true
5052
5842
  })
@@ -5055,7 +5845,7 @@ async function setRolePositions(guild, updates) {
5055
5845
  async function setRoleHoistPositions(guild, updates) {
5056
5846
  return replaceRoles(
5057
5847
  guild,
5058
- await guild.client.rest.patch(Routes29.guildRolesHoistPositions(guild.id), {
5848
+ await guild.client.rest.patch(Routes32.guildRolesHoistPositions(guild.id), {
5059
5849
  body: updates.map((u) => ({
5060
5850
  id: u.id,
5061
5851
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -5067,17 +5857,17 @@ async function setRoleHoistPositions(guild, updates) {
5067
5857
  async function resetRoleHoistPositions(guild) {
5068
5858
  return replaceRoles(
5069
5859
  guild,
5070
- await guild.client.rest.delete(Routes29.guildRolesHoistPositions(guild.id), {
5860
+ await guild.client.rest.delete(Routes32.guildRolesHoistPositions(guild.id), {
5071
5861
  auth: true
5072
5862
  })
5073
5863
  );
5074
5864
  }
5075
5865
 
5076
5866
  // src/Domain/Guild/Stickers.ts
5077
- import { Routes as Routes30 } from "@fluxerjs/types";
5867
+ import { Routes as Routes33 } from "@fluxerjs/types";
5078
5868
  async function createSticker(guild, options) {
5079
5869
  const { reason, ...body } = options;
5080
- const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
5870
+ const data = await guild.client.rest.post(Routes33.guildStickers(guild.id), {
5081
5871
  body,
5082
5872
  auth: true,
5083
5873
  ...auditReasonHeaders(reason)
@@ -5085,7 +5875,7 @@ async function createSticker(guild, options) {
5085
5875
  return cacheSticker(guild, data);
5086
5876
  }
5087
5877
  async function cloneSticker(guild, sourceStickerId) {
5088
- const data = await guild.client.rest.post(Routes30.guildStickersClone(guild.id), {
5878
+ const data = await guild.client.rest.post(Routes33.guildStickersClone(guild.id), {
5089
5879
  body: { source_sticker_id: sourceStickerId },
5090
5880
  auth: true
5091
5881
  });
@@ -5093,17 +5883,17 @@ async function cloneSticker(guild, sourceStickerId) {
5093
5883
  }
5094
5884
  async function createStickersBulk(guild, stickers) {
5095
5885
  const data = await guild.client.rest.post(
5096
- Routes30.guildStickersBulk(guild.id),
5886
+ Routes33.guildStickersBulk(guild.id),
5097
5887
  { body: { stickers }, auth: true }
5098
5888
  );
5099
5889
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
5100
5890
  }
5101
5891
  async function fetchStickers(guild) {
5102
- const data = await guild.client.rest.get(Routes30.guildStickers(guild.id));
5892
+ const data = await guild.client.rest.get(Routes33.guildStickers(guild.id));
5103
5893
  return data.map((s) => cacheSticker(guild, s));
5104
5894
  }
5105
5895
  async function fetchSticker(guild, stickerId) {
5106
- const data = await guild.client.rest.get(Routes30.guildSticker(guild.id, stickerId));
5896
+ const data = await guild.client.rest.get(Routes33.guildSticker(guild.id, stickerId));
5107
5897
  return cacheSticker(guild, data);
5108
5898
  }
5109
5899
 
@@ -5335,7 +6125,7 @@ var Guild = class extends Base {
5335
6125
  });
5336
6126
  }
5337
6127
  /**
5338
- * Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
6128
+ * Create a channel. `type`: 0=text, 2=voice, 4=category, 5=announcement, 15=forum, 16=media, 998=link (set `url`).
5339
6129
  * Requires Manage Channels.
5340
6130
  */
5341
6131
  createChannel(options) {
@@ -5345,6 +6135,10 @@ var Guild = class extends Base {
5345
6135
  fetchChannels() {
5346
6136
  return fetchChannels(this);
5347
6137
  }
6138
+ /** Fetch active threads in this guild. */
6139
+ fetchActiveThreads() {
6140
+ return fetchActiveThreads(this.client, this.id);
6141
+ }
5348
6142
  /** Update channel positions (reordering). */
5349
6143
  setChannelPositions(updates) {
5350
6144
  return setChannelPositions(this, updates);
@@ -5575,6 +6369,13 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
5575
6369
  client.guilds.set(guild.id, guild);
5576
6370
  if (resources.roles !== void 0) syncRoles(guild, resources.roles);
5577
6371
  if (resources.channels !== void 0) syncChannels(guild, resources.channels);
6372
+ if (resources.threads !== void 0) {
6373
+ syncThreads(
6374
+ guild,
6375
+ resources.threads,
6376
+ new Set((resources.channels ?? []).map((channel) => channel.id))
6377
+ );
6378
+ }
5578
6379
  if (resources.members !== void 0) mergeMembers(guild, resources.members);
5579
6380
  if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
5580
6381
  if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
@@ -5589,7 +6390,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
5589
6390
  channels: g.channels,
5590
6391
  members: g.members,
5591
6392
  emojis: g.emojis,
5592
- stickers: g.stickers
6393
+ stickers: g.stickers,
6394
+ // A channel list without `threads` means this session has no viewable threads.
6395
+ threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
5593
6396
  });
5594
6397
  if (g.voice_states?.length) {
5595
6398
  client.emit(Events.VoiceStatesSync, {
@@ -5601,7 +6404,7 @@ function applyGuildSnapshotFromGateway(client, raw) {
5601
6404
  }
5602
6405
 
5603
6406
  // src/ClientCore/ClientUser.ts
5604
- import { GatewayOpcodes, Routes as Routes31 } from "@fluxerjs/types";
6407
+ import { GatewayOpcodes, Routes as Routes34 } from "@fluxerjs/types";
5605
6408
  var ClientUser = class extends User {
5606
6409
  /** Broadcast presence (gateway opcode 3) on all shards. */
5607
6410
  setPresence(presence) {
@@ -5611,13 +6414,13 @@ var ClientUser = class extends User {
5611
6414
  }
5612
6415
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
5613
6416
  async fetch() {
5614
- const data = await this.client.rest.get(Routes31.currentUser(), { auth: true });
6417
+ const data = await this.client.rest.get(Routes34.currentUser(), { auth: true });
5615
6418
  this._patch(data);
5616
6419
  return this;
5617
6420
  }
5618
6421
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
5619
6422
  async fetchGuilds(options) {
5620
- const path = Routes31.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6423
+ const path = Routes34.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
5621
6424
  const data = await this.client.rest.get(path, { auth: true });
5622
6425
  return data.map((g) => ({
5623
6426
  id: g.id,
@@ -5641,7 +6444,7 @@ var ClientUser = class extends User {
5641
6444
  */
5642
6445
  async leaveGuild(guildId, options) {
5643
6446
  const body = options ? toSudoBody(options) : void 0;
5644
- await this.client.rest.delete(Routes31.leaveGuild(guildId), {
6447
+ await this.client.rest.delete(Routes34.leaveGuild(guildId), {
5645
6448
  body: body && Object.keys(body).length ? body : void 0,
5646
6449
  auth: true
5647
6450
  });
@@ -5649,7 +6452,7 @@ var ClientUser = class extends User {
5649
6452
  /** Delete every message authored by the caller across a guild (sudo). */
5650
6453
  async bulkDeleteMyMessagesInGuild(guildId, options) {
5651
6454
  const body = options ? toSudoBody(options) : void 0;
5652
- await this.client.rest.post(Routes31.guildBulkDeleteMine(guildId), {
6455
+ await this.client.rest.post(Routes34.guildBulkDeleteMine(guildId), {
5653
6456
  body: body && Object.keys(body).length ? body : void 0,
5654
6457
  auth: true
5655
6458
  });
@@ -5684,6 +6487,7 @@ var channelHandlers = {
5684
6487
  if (!ch) return;
5685
6488
  indexChannel(client, ch);
5686
6489
  client.emit(Events.ChannelCreate, ch);
6490
+ if (ch.isThread()) client.emit(Events.ThreadCreate, ch);
5687
6491
  },
5688
6492
  CHANNEL_UPDATE(client, d) {
5689
6493
  const data = d;
@@ -5696,12 +6500,14 @@ var channelHandlers = {
5696
6500
  existing._patch(data);
5697
6501
  indexChannel(client, existing);
5698
6502
  client.emit(Events.ChannelUpdate, oldCh, existing);
6503
+ if (existing.isThread()) client.emit(Events.ThreadUpdate, oldCh, existing);
5699
6504
  return;
5700
6505
  }
5701
6506
  const newCh = Channel.from(client, data);
5702
6507
  if (!newCh) return;
5703
6508
  indexChannel(client, newCh);
5704
6509
  client.emit(Events.ChannelUpdate, existing ?? newCh, newCh);
6510
+ if (newCh.isThread()) client.emit(Events.ThreadUpdate, existing ?? newCh, newCh);
5705
6511
  },
5706
6512
  CHANNEL_UPDATE_BULK(client, d) {
5707
6513
  const data = d;
@@ -5723,7 +6529,11 @@ var channelHandlers = {
5723
6529
  }
5724
6530
  if (!channel) return;
5725
6531
  client.channels.delete(id);
6532
+ if (channel.isGuild() && channel.guildId) {
6533
+ client.guilds.get(channel.guildId)?.channels.delete(id);
6534
+ }
5726
6535
  client.emit(Events.ChannelDelete, channel);
6536
+ if (channel.isThread()) client.emit(Events.ThreadDelete, channel);
5727
6537
  },
5728
6538
  CHANNEL_PINS_UPDATE(client, d) {
5729
6539
  const data = d;
@@ -5913,6 +6723,10 @@ var guildHandlers = {
5913
6723
  }
5914
6724
  client._onGuildReceived(guild.id);
5915
6725
  },
6726
+ /** Same snapshot as Guild Create, including `threads`. Cache only: this is not a join. */
6727
+ GUILD_SYNC(client, d) {
6728
+ applyGuildSnapshotFromGateway(client, d);
6729
+ },
5916
6730
  GUILD_UPDATE(client, d) {
5917
6731
  const guildData = normalizeGuildUpdatePayload(d);
5918
6732
  if (!guildData) return;
@@ -5962,7 +6776,7 @@ var guildHandlers = {
5962
6776
 
5963
6777
  // src/ClientCore/EventHandlers/Invites.ts
5964
6778
  import {
5965
- ChannelType as ChannelType4,
6779
+ ChannelType as ChannelType10,
5966
6780
  InviteType as InviteType2
5967
6781
  } from "@fluxerjs/types";
5968
6782
  function normalizeInviteCreate(client, payload) {
@@ -5987,11 +6801,11 @@ function normalizeInviteCreate(client, payload) {
5987
6801
  const guildId = str(guildObj?.id) ?? str(raw.guild_id) ?? "0";
5988
6802
  const channelId = str(channelObj?.id) ?? str(raw.channel_id) ?? "0";
5989
6803
  const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
5990
- const cachedChannel = channelId !== "0" ? client.channels.get(channelId) : null;
6804
+ const cachedChannel2 = channelId !== "0" ? client.channels.get(channelId) : null;
5991
6805
  const channel = {
5992
6806
  id: channelId,
5993
- type: num(channelObj?.type) ?? cachedChannel?.type ?? ChannelType4.GuildText,
5994
- name: str(channelObj?.name) ?? cachedChannel?.name ?? null,
6807
+ type: num(channelObj?.type) ?? cachedChannel2?.type ?? ChannelType10.GuildText,
6808
+ name: str(channelObj?.name) ?? cachedChannel2?.name ?? null,
5995
6809
  icon: channelObj?.icon ?? null
5996
6810
  };
5997
6811
  if (type === InviteType2.GroupDM) return { ...shared, type, channel };
@@ -6395,6 +7209,107 @@ var passthroughHandlers = {
6395
7209
  WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
6396
7210
  };
6397
7211
 
7212
+ // src/ClientCore/EventHandlers/Threads.ts
7213
+ function cachedChannel(client, id) {
7214
+ const direct = client.channels.get(id);
7215
+ if (direct) return direct;
7216
+ for (const guild of client.guilds.values()) {
7217
+ const nested = guild.channels.get(id);
7218
+ if (nested) return nested;
7219
+ }
7220
+ return null;
7221
+ }
7222
+ var threadHandlers = {
7223
+ THREAD_CREATE(client, d) {
7224
+ channelHandlers.CHANNEL_CREATE(client, d);
7225
+ },
7226
+ THREAD_UPDATE(client, d) {
7227
+ channelHandlers.CHANNEL_UPDATE(client, d);
7228
+ },
7229
+ THREAD_DELETE(client, d) {
7230
+ const data = d;
7231
+ const existing = data.id ? cachedChannel(client, data.id) : null;
7232
+ if (existing?.isThread()) {
7233
+ channelHandlers.CHANNEL_DELETE(client, data);
7234
+ return;
7235
+ }
7236
+ if (!data.id || !isThreadType(data.type)) return;
7237
+ const thread = Channel.from(client, {
7238
+ id: data.id,
7239
+ type: data.type,
7240
+ guild_id: data.guild_id,
7241
+ parent_id: data.parent_id
7242
+ });
7243
+ if (!thread.isThread()) return;
7244
+ client.emit(Events.ChannelDelete, thread);
7245
+ client.emit(Events.ThreadDelete, thread);
7246
+ },
7247
+ THREAD_LIST_SYNC(client, d) {
7248
+ const data = d;
7249
+ const { threads } = fetchedThreadsFrom(client, {
7250
+ threads: data.threads ?? [],
7251
+ members: data.members ?? []
7252
+ });
7253
+ const payload = {
7254
+ guildId: data.guild_id,
7255
+ channelIds: data.channel_ids ?? [],
7256
+ threads
7257
+ };
7258
+ client.emit(Events.ThreadListSync, payload);
7259
+ },
7260
+ THREAD_MEMBER_UPDATE(client, d) {
7261
+ const data = d;
7262
+ const member = new ThreadMember(data);
7263
+ const thread = member.id ? client.channels.get(member.id) : void 0;
7264
+ if (thread?.isThread() && member.userId && member.userId === client.user?.id) {
7265
+ thread.member = member;
7266
+ }
7267
+ client.emit(Events.ThreadMemberUpdate, member);
7268
+ },
7269
+ THREAD_MEMBERS_UPDATE(client, d) {
7270
+ const data = d;
7271
+ const thread = client.channels.get(data.id);
7272
+ if (thread?.isThread()) thread.memberCount = data.member_count;
7273
+ const payload = {
7274
+ id: data.id,
7275
+ guildId: data.guild_id,
7276
+ memberCount: data.member_count,
7277
+ addedMembers: (data.added_members ?? []).map((member) => new ThreadMember(member)),
7278
+ removedMemberIds: data.removed_member_ids ?? []
7279
+ };
7280
+ client.emit(Events.ThreadMembersUpdate, payload);
7281
+ },
7282
+ THREAD_MEMBER_LIST_UPDATE(client, d) {
7283
+ const data = d;
7284
+ const guild = data.guild_id ? client.guilds.get(data.guild_id) : void 0;
7285
+ const payload = {
7286
+ guildId: data.guild_id,
7287
+ threadId: data.thread_id,
7288
+ members: (data.members ?? []).map((entry) => ({
7289
+ userId: entry.user_id,
7290
+ joinTimestamp: entry.join_timestamp,
7291
+ flags: entry.flags,
7292
+ member: guild && entry.member?.user?.id ? cacheMember(guild, entry.member) : null,
7293
+ presence: entry.presence ? { status: entry.presence.status ?? null } : null
7294
+ }))
7295
+ };
7296
+ client.emit(Events.ThreadMemberListUpdate, payload);
7297
+ },
7298
+ FORUM_UNREADS(client, d) {
7299
+ const data = d;
7300
+ const payload = {
7301
+ guildId: data.guild_id,
7302
+ channelId: data.channel_id,
7303
+ threads: (data.threads ?? []).map((entry) => ({
7304
+ threadId: entry.thread_id,
7305
+ count: entry.count ?? null,
7306
+ missing: entry.missing === true
7307
+ }))
7308
+ };
7309
+ client.emit(Events.ForumUnreads, payload);
7310
+ }
7311
+ };
7312
+
6398
7313
  // src/ClientCore/EventHandlers/index.ts
6399
7314
  var eventHandlers = buildRegistry(
6400
7315
  messageHandlers,
@@ -6403,7 +7318,8 @@ var eventHandlers = buildRegistry(
6403
7318
  memberHandlers,
6404
7319
  inviteHandlers,
6405
7320
  guildResourceHandlers,
6406
- passthroughHandlers
7321
+ passthroughHandlers,
7322
+ threadHandlers
6407
7323
  );
6408
7324
 
6409
7325
  // src/ClientCore/GatewayDispatch.ts
@@ -6629,7 +7545,7 @@ async function connectClientGateway(client, token, signal) {
6629
7545
 
6630
7546
  // src/ClientCore/GuildManager.ts
6631
7547
  import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
6632
- import { Routes as Routes32 } from "@fluxerjs/types";
7548
+ import { Routes as Routes35 } from "@fluxerjs/types";
6633
7549
  var GuildManager = class extends LimitedCollection5 {
6634
7550
  constructor(client) {
6635
7551
  super({
@@ -6668,7 +7584,7 @@ var GuildManager = class extends LimitedCollection5 {
6668
7584
  const cached = this.get(guildId);
6669
7585
  if (cached && !options?.force) return cached;
6670
7586
  try {
6671
- const data = await this.client.rest.get(Routes32.guild(guildId));
7587
+ const data = await this.client.rest.get(Routes35.guild(guildId));
6672
7588
  if (cached) {
6673
7589
  cached._patch(data);
6674
7590
  return cached;
@@ -6756,7 +7672,7 @@ var MessageCache = class {
6756
7672
  // src/ClientCore/UserManager.ts
6757
7673
  import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
6758
7674
  import {
6759
- Routes as Routes33
7675
+ Routes as Routes36
6760
7676
  } from "@fluxerjs/types";
6761
7677
  var soft = (p) => p.catch(() => null);
6762
7678
  var UserManager = class extends LimitedCollection6 {
@@ -6781,7 +7697,7 @@ var UserManager = class extends LimitedCollection6 {
6781
7697
  async fetch(userId, options) {
6782
7698
  const cached = this.get(userId);
6783
7699
  if (cached && !options?.force) return cached;
6784
- const data = await this.client.rest.get(Routes33.user(userId));
7700
+ const data = await this.client.rest.get(Routes36.user(userId));
6785
7701
  return this.client.getOrCreateUser(data);
6786
7702
  }
6787
7703
  /** Return a cached user, otherwise {@link fetch}. */
@@ -6799,10 +7715,10 @@ var UserManager = class extends LimitedCollection6 {
6799
7715
  async fetchWithProfile(userId, options) {
6800
7716
  const guildId = options?.guildId ?? void 0;
6801
7717
  const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
6802
- this.client.rest.get(Routes33.user(userId)),
6803
- soft(this.client.rest.get(Routes33.userProfile(userId))),
6804
- guildId ? soft(this.client.rest.get(Routes33.userProfile(userId, guildId))) : null,
6805
- guildId ? soft(this.client.rest.get(Routes33.guildMember(guildId, userId))) : null
7718
+ this.client.rest.get(Routes36.user(userId)),
7719
+ soft(this.client.rest.get(Routes36.userProfile(userId))),
7720
+ guildId ? soft(this.client.rest.get(Routes36.userProfile(userId, guildId))) : null,
7721
+ guildId ? soft(this.client.rest.get(Routes36.guildMember(guildId, userId))) : null
6806
7722
  ]);
6807
7723
  const user = this.client.getOrCreateUser(userData);
6808
7724
  let member = null;
@@ -7181,6 +8097,72 @@ var Client = class _Client extends EventEmitter3 {
7181
8097
  if (options.nonce !== void 0) data.nonce = options.nonce;
7182
8098
  this._sendToAllShards({ op: GatewayOpcodes2.RequestChannelMemberCounts, d: data });
7183
8099
  }
8100
+ /**
8101
+ * Request unread counts for posts in one forum or media channel (opcode 28).
8102
+ * Listen for `forumUnreads`. The gateway keeps at most 40 posts and ignores a channel the session cannot view.
8103
+ */
8104
+ requestForumUnreads(options) {
8105
+ if (!options.guildId || !options.channelId) {
8106
+ throw new FluxerError("requestForumUnreads requires guildId and channelId", {
8107
+ code: ErrorCodes.InvalidGatewayRequest
8108
+ });
8109
+ }
8110
+ const threads = [];
8111
+ const seen = /* @__PURE__ */ new Set();
8112
+ for (const thread of options.threads) {
8113
+ if (!thread.threadId || seen.has(thread.threadId)) continue;
8114
+ seen.add(thread.threadId);
8115
+ const entry = { thread_id: thread.threadId };
8116
+ if (thread.ackMessageId !== void 0) entry.ack_message_id = thread.ackMessageId;
8117
+ threads.push(entry);
8118
+ }
8119
+ if (!threads.length) {
8120
+ throw new FluxerError("requestForumUnreads requires at least one thread", {
8121
+ code: ErrorCodes.InvalidGatewayRequest
8122
+ });
8123
+ }
8124
+ if (threads.length > 40) {
8125
+ throw new FluxerError("requestForumUnreads accepts at most 40 threads", {
8126
+ code: ErrorCodes.InvalidGatewayRequest
8127
+ });
8128
+ }
8129
+ const data = {
8130
+ guild_id: options.guildId,
8131
+ channel_id: options.channelId,
8132
+ threads
8133
+ };
8134
+ this._sendToAllShards({ op: GatewayOpcodes2.RequestForumUnreads, d: data });
8135
+ }
8136
+ /**
8137
+ * Subscribe to thread traffic in a guild (opcode 14).
8138
+ * `threads: true` receives every thread event in the guild.
8139
+ * `threadIds` (at most 10) subscribes to those member lists. Each one arrives as `threadMemberListUpdate`.
8140
+ */
8141
+ subscribeThreads(options) {
8142
+ if (!options.guildId) {
8143
+ throw new FluxerError("subscribeThreads requires guildId", {
8144
+ code: ErrorCodes.InvalidGatewayRequest
8145
+ });
8146
+ }
8147
+ if (options.threads === void 0 && options.threadIds === void 0) {
8148
+ throw new FluxerError("subscribeThreads requires threads or threadIds", {
8149
+ code: ErrorCodes.InvalidGatewayRequest
8150
+ });
8151
+ }
8152
+ const subscription = {};
8153
+ if (options.threads !== void 0) subscription.threads = options.threads;
8154
+ if (options.threadIds !== void 0) {
8155
+ const threadIds = [...new Set(options.threadIds.filter(Boolean))];
8156
+ if (threadIds.length > 10) {
8157
+ throw new FluxerError("subscribeThreads accepts at most 10 threadIds", {
8158
+ code: ErrorCodes.InvalidGatewayRequest
8159
+ });
8160
+ }
8161
+ subscription.thread_member_lists = threadIds;
8162
+ }
8163
+ const data = { subscriptions: { [options.guildId]: subscription } };
8164
+ this._sendToAllShards({ op: GatewayOpcodes2.LazyRequest, d: data });
8165
+ }
7184
8166
  /**
7185
8167
  * Broadcast a gateway payload to all shards.
7186
8168
  * @param payload - Gateway send payload
@@ -7284,7 +8266,7 @@ var Client = class _Client extends EventEmitter3 {
7284
8266
  * @see {@link Routes}
7285
8267
  */
7286
8268
  static get Routes() {
7287
- return Routes34;
8269
+ return Routes37;
7288
8270
  }
7289
8271
  };
7290
8272
 
@@ -7626,6 +8608,7 @@ var ClientCluster = class extends EventEmitter4 {
7626
8608
  };
7627
8609
  export {
7628
8610
  AllowedMentions,
8611
+ AnnouncementChannel,
7629
8612
  AttachmentBuilder2 as AttachmentBuilder,
7630
8613
  AttachmentMeta,
7631
8614
  AuditLogActionType,
@@ -7636,7 +8619,7 @@ export {
7636
8619
  CategoryChannel,
7637
8620
  Channel,
7638
8621
  ChannelManager,
7639
- ChannelType5 as ChannelType,
8622
+ ChannelType11 as ChannelType,
7640
8623
  Client,
7641
8624
  ClientCluster,
7642
8625
  ClientClusterEvents,
@@ -7649,6 +8632,10 @@ export {
7649
8632
  ErrorCodes,
7650
8633
  Events,
7651
8634
  FluxerError,
8635
+ ForumChannel,
8636
+ ForumLayout,
8637
+ ForumSortOrder,
8638
+ ForumTagSetting,
7652
8639
  GatewayOpcodes3 as GatewayOpcodes,
7653
8640
  Guild,
7654
8641
  GuildBan,
@@ -7667,6 +8654,7 @@ export {
7667
8654
  Invite,
7668
8655
  InviteType3 as InviteType,
7669
8656
  LinkChannel,
8657
+ MediaChannel,
7670
8658
  Message,
7671
8659
  MessageAttachmentFlags2 as MessageAttachmentFlags,
7672
8660
  MessageCollector,
@@ -7691,11 +8679,17 @@ export {
7691
8679
  ReactionCollector,
7692
8680
  RelationshipType,
7693
8681
  Role,
7694
- Routes35 as Routes,
8682
+ Routes38 as Routes,
7695
8683
  STATIC_CDN_URL,
7696
8684
  SplashCardAlignment,
7697
8685
  SystemChannelFlags,
7698
8686
  TextChannel,
8687
+ ThreadAutoArchiveDuration,
8688
+ ThreadChannel,
8689
+ ThreadManager,
8690
+ ThreadMember,
8691
+ ThreadMemberFlags,
8692
+ ThreadMemberManager,
7699
8693
  User,
7700
8694
  UserFlagsBitField,
7701
8695
  UserFlagsBits,
@@ -7712,6 +8706,7 @@ export {
7712
8706
  cdnMemberBannerURL,
7713
8707
  cdnStickerURL,
7714
8708
  createLogger2 as createLogger,
8709
+ fetchActiveThreads,
7715
8710
  instanceDiscoveryUrl,
7716
8711
  inviteUrl,
7717
8712
  normalizeApiOrigin,