@fluxerjs/core 3.3.0 → 3.5.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/client.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/ClientCore/Client.ts
2
2
  import { EventEmitter as EventEmitter3 } from "events";
3
3
  import { REST } from "@fluxerjs/rest";
4
- import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes37 } from "@fluxerjs/types";
4
+ import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes38 } from "@fluxerjs/types";
5
5
  import { createLogger } from "@fluxerjs/util";
6
6
 
7
7
  // src/Domain/Message/Message.ts
@@ -947,6 +947,7 @@ var Events = {
947
947
  GuildEmojisUpdate: "guildEmojisUpdate",
948
948
  GuildStickersUpdate: "guildStickersUpdate",
949
949
  GuildCountsUpdate: "guildCountsUpdate",
950
+ GuildHealthUpdate: "guildHealthUpdate",
950
951
  ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
951
952
  GuildMemberAdd: "guildMemberAdd",
952
953
  GuildMemberUpdate: "guildMemberUpdate",
@@ -981,7 +982,16 @@ var Events = {
981
982
  VoiceStateAck: "voiceStateAck",
982
983
  VoiceServerUpdate: "voiceServerUpdate",
983
984
  EntranceSoundPlay: "entranceSoundPlay",
985
+ VoiceSignal: "voiceSignal",
986
+ OperatorPassUpdate: "operatorPassUpdate",
984
987
  VoiceStatesSync: "voiceStatesSync",
988
+ VoiceJoinQueued: "voiceJoinQueued",
989
+ StageInstanceCreate: "stageInstanceCreate",
990
+ StageInstanceUpdate: "stageInstanceUpdate",
991
+ StageInstanceDelete: "stageInstanceDelete",
992
+ StageCountsUpdate: "stageCountsUpdate",
993
+ StageVoiceStatesSync: "stageVoiceStatesSync",
994
+ StageAudienceListUpdate: "stageAudienceListUpdate",
985
995
  WebhooksUpdate: "webhooksUpdate",
986
996
  Resumed: "resumed",
987
997
  Error: "error",
@@ -1110,6 +1120,45 @@ import { SnowflakeUtil } from "@fluxerjs/util";
1110
1120
  // src/ClientCore/MessageManager.ts
1111
1121
  import { Collection as Collection2 } from "@fluxerjs/collection";
1112
1122
  import { Routes as Routes2 } from "@fluxerjs/types";
1123
+
1124
+ // src/ClientCore/Resolve.ts
1125
+ function normalizeSnowflakeId(value, label) {
1126
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
1127
+ throw new TypeError(
1128
+ `${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
1129
+ );
1130
+ }
1131
+ const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
1132
+ if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
1133
+ throw new TypeError(`${label} requires a non-empty ID`);
1134
+ }
1135
+ return id;
1136
+ }
1137
+ function assertApiObjectWithId(data, label) {
1138
+ if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
1139
+ throw new TypeError(`${label} received an invalid API payload (missing string id)`);
1140
+ }
1141
+ return data;
1142
+ }
1143
+ function assertApiArray(data, label) {
1144
+ if (!Array.isArray(data)) {
1145
+ throw new TypeError(`${label} received an invalid API payload (expected an array)`);
1146
+ }
1147
+ return data;
1148
+ }
1149
+ async function dedupeFetch(pending, key, fn) {
1150
+ const existing = pending.get(key);
1151
+ if (existing) return existing;
1152
+ const request = fn();
1153
+ pending.set(key, request);
1154
+ try {
1155
+ return await request;
1156
+ } finally {
1157
+ if (pending.get(key) === request) pending.delete(key);
1158
+ }
1159
+ }
1160
+
1161
+ // src/ClientCore/MessageManager.ts
1113
1162
  var BULK = {
1114
1163
  requests: { min: 1, max: 25 },
1115
1164
  limit: { min: 1, max: 25 },
@@ -1145,25 +1194,32 @@ var MessageManager = class {
1145
1194
  }
1146
1195
  /** Structure cache keyed by message id (identity for {@link get}). */
1147
1196
  _structures = new Collection2();
1197
+ pendingFetches = /* @__PURE__ */ new Map();
1148
1198
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
1149
1199
  get(messageId) {
1150
- const data = this.client._getMessageCache(this.channelId)?.get(messageId);
1200
+ const id = String(messageId ?? "").trim();
1201
+ if (!id) return void 0;
1202
+ const data = this.client._getMessageCache(this.channelId)?.get(id);
1151
1203
  if (!data) {
1152
- this._structures.delete(messageId);
1204
+ this._structures.delete(id);
1153
1205
  return void 0;
1154
1206
  }
1155
- const existing = this._structures.get(messageId);
1156
- if (existing) return existing;
1207
+ const existing = this._structures.get(id);
1208
+ if (existing) {
1209
+ existing._patch(data);
1210
+ return existing;
1211
+ }
1157
1212
  const message = new Message(this.client, data);
1158
- this._structures.set(messageId, message);
1213
+ this._structures.set(id, message);
1159
1214
  return message;
1160
1215
  }
1161
1216
  /** Retrieve from cache, otherwise {@link fetch}. */
1162
1217
  async resolve(messageId) {
1163
- return this.get(messageId) ?? this.fetch(messageId);
1218
+ const id = normalizeSnowflakeId(messageId, "messages.resolve()");
1219
+ return this.get(id) ?? this.fetch(id);
1164
1220
  }
1165
1221
  async fetch(idOrOptions) {
1166
- return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
1222
+ return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
1167
1223
  }
1168
1224
  /** Cache API data and return a {@link Message} (reusing identity when present). */
1169
1225
  wrap(data) {
@@ -1180,9 +1236,13 @@ var MessageManager = class {
1180
1236
  }
1181
1237
  /** Fetch a single message from the API. */
1182
1238
  async fetchOne(messageId) {
1239
+ return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
1240
+ }
1241
+ async fetchOneFresh(messageId) {
1183
1242
  try {
1184
- const data = await this.client.rest.get(
1185
- Routes2.channelMessage(this.channelId, messageId)
1243
+ const data = assertApiObjectWithId(
1244
+ await this.client.rest.get(Routes2.channelMessage(this.channelId, messageId)),
1245
+ "messages.fetch()"
1186
1246
  );
1187
1247
  return this.wrap(data);
1188
1248
  } catch (err) {
@@ -1208,9 +1268,15 @@ var MessageManager = class {
1208
1268
  if (value != null && value !== "") qs2.set(key, String(value));
1209
1269
  }
1210
1270
  const base = Routes2.channelMessages(this.channelId);
1211
- const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
1271
+ const data = assertApiArray(
1272
+ await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
1273
+ "messages.fetch()"
1274
+ );
1212
1275
  const collection = new Collection2();
1213
- for (const msg of data) collection.set(msg.id, this.wrap(msg));
1276
+ for (const msg of data) {
1277
+ if (!msg?.id) continue;
1278
+ collection.set(msg.id, this.wrap(msg));
1279
+ }
1214
1280
  return collection;
1215
1281
  }
1216
1282
  };
@@ -1414,6 +1480,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1414
1480
  }
1415
1481
 
1416
1482
  // src/Domain/Channel/Base.ts
1483
+ function isFullChannelData(data) {
1484
+ return "guild_id" in data || "permission_overwrites" in data || "position" in data || "last_message_id" in data || "topic" in data || "thread_metadata" in data || "available_tags" in data;
1485
+ }
1417
1486
  var Channel = class extends Base {
1418
1487
  #messages;
1419
1488
  /** The {@link Client} that instantiated this channel. */
@@ -1428,6 +1497,11 @@ var Channel = class extends Base {
1428
1497
  icon;
1429
1498
  /** ISO8601 timestamp of the last pinned message update. */
1430
1499
  lastPinTimestamp;
1500
+ /**
1501
+ * True when built from a partial payload (e.g. a DM stub) and not yet hydrated
1502
+ * with a full channel object. `channels.resolve()` refetches partial channels.
1503
+ */
1504
+ partial;
1431
1505
  constructor(client, data) {
1432
1506
  super();
1433
1507
  this.client = client;
@@ -1436,6 +1510,7 @@ var Channel = class extends Base {
1436
1510
  this.name = data.name ?? null;
1437
1511
  this.icon = data.icon ?? null;
1438
1512
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1513
+ this.partial = !isFullChannelData(data);
1439
1514
  }
1440
1515
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
1441
1516
  get createdTimestamp() {
@@ -1456,6 +1531,7 @@ var Channel = class extends Base {
1456
1531
  if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
1457
1532
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1458
1533
  }
1534
+ if (isFullChannelData(data)) this.partial = false;
1459
1535
  }
1460
1536
  /** @internal Factory wired after subclasses load. */
1461
1537
  static from(_c, _d) {
@@ -1475,11 +1551,11 @@ var Channel = class extends Base {
1475
1551
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
1476
1552
  */
1477
1553
  isTextBased() {
1478
- 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;
1554
+ return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildStageVoice || this.type === ChannelType3.DM || this.type === ChannelType3.GroupDM || this.type === ChannelType3.DMPersonalNotes || this.type === ChannelType3.AnnouncementThread || this.type === ChannelType3.PublicThread || this.type === ChannelType3.PrivateThread;
1479
1555
  }
1480
1556
  /** Check if this is a guild channel, including threads, forums, and media channels. */
1481
1557
  isGuild() {
1482
- 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;
1558
+ return this.type === ChannelType3.GuildText || this.type === ChannelType3.GuildAnnouncement || this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildStageVoice || 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;
1483
1559
  }
1484
1560
  /** Check if this is a thread (public, private, or announcement). */
1485
1561
  isThread() {
@@ -1513,10 +1589,18 @@ var Channel = class extends Base {
1513
1589
  isPersonalNotes() {
1514
1590
  return this.type === ChannelType3.DMPersonalNotes;
1515
1591
  }
1516
- /** Check if this is a voice channel. */
1592
+ /** Check if this is a voice channel (type 2 only; see {@link isVoiceBased} to include stages). */
1517
1593
  isVoice() {
1518
1594
  return this.type === ChannelType3.GuildVoice;
1519
1595
  }
1596
+ /** Check if this is a stage channel (type 13). */
1597
+ isStage() {
1598
+ return this.type === ChannelType3.GuildStageVoice;
1599
+ }
1600
+ /** Check if this is a voice or stage channel, i.e. one `@fluxerjs/voice` can join. */
1601
+ isVoiceBased() {
1602
+ return this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildStageVoice;
1603
+ }
1520
1604
  /** Check if this is a link channel. */
1521
1605
  isLink() {
1522
1606
  return this.type === ChannelType3.GuildLink;
@@ -2231,10 +2315,10 @@ var Message = class _Message extends Base {
2231
2315
  this.channelId = data.channel_id;
2232
2316
  this.guildId = data.guild_id ?? null;
2233
2317
  this.author = client.getOrCreateUser(data.author);
2234
- this.content = data.content;
2235
- this.createdAt = new Date(data.timestamp);
2318
+ this.content = data.content ?? "";
2319
+ this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
2236
2320
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2237
- this.pinned = data.pinned;
2321
+ this.pinned = data.pinned ?? false;
2238
2322
  this.attachments = new Collection5();
2239
2323
  for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2240
2324
  this.type = data.type ?? MessageType.Default;
@@ -2266,33 +2350,47 @@ var Message = class _Message extends Base {
2266
2350
  * @internal
2267
2351
  */
2268
2352
  _patch(data) {
2269
- this.content = data.content;
2270
- this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2271
- this.pinned = data.pinned;
2272
- this.attachments.clear();
2273
- for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2274
- this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
2275
- this.mentionEveryone = data.mention_everyone ?? false;
2276
- this.tts = data.tts ?? false;
2277
- this.embeds = (data.embeds ?? []).map(toMessageEmbed);
2278
- this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
2279
- this.reactions._patch(data.reactions);
2280
- this.messageReference = data.message_reference ? {
2281
- channelId: data.message_reference.channel_id,
2282
- messageId: data.message_reference.message_id,
2283
- guildId: data.message_reference.guild_id ?? null,
2284
- ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
2285
- } : null;
2286
- this.messageSnapshots = (data.message_snapshots ?? []).map(
2287
- (s) => toMessageSnapshot(this.client, s)
2288
- );
2289
- this.call = data.call ? toMessageCall(data.call) : null;
2290
- this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
2291
- this.webhookId = data.webhook_id ?? null;
2292
- this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
2293
- this.mentionRoles = data.mention_roles ?? [];
2294
- this.nonce = data.nonce ?? null;
2295
- this.nsfwEmojis = data.nsfw_emojis ?? [];
2353
+ if (data.content !== void 0) this.content = data.content ?? "";
2354
+ if (data.edited_timestamp !== void 0) {
2355
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2356
+ }
2357
+ if (data.pinned !== void 0) this.pinned = data.pinned;
2358
+ if (data.attachments !== void 0) {
2359
+ this.attachments.clear();
2360
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2361
+ }
2362
+ if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
2363
+ if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
2364
+ if (data.tts !== void 0) this.tts = data.tts;
2365
+ if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
2366
+ if (data.stickers !== void 0) {
2367
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
2368
+ }
2369
+ if (data.reactions !== void 0) this.reactions._patch(data.reactions);
2370
+ if (data.message_reference !== void 0) {
2371
+ this.messageReference = data.message_reference ? {
2372
+ channelId: data.message_reference.channel_id,
2373
+ messageId: data.message_reference.message_id,
2374
+ guildId: data.message_reference.guild_id ?? null,
2375
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
2376
+ } : null;
2377
+ }
2378
+ if (data.message_snapshots !== void 0) {
2379
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
2380
+ (s) => toMessageSnapshot(this.client, s)
2381
+ );
2382
+ }
2383
+ if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
2384
+ if (data.referenced_message !== void 0) {
2385
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
2386
+ }
2387
+ if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
2388
+ if (data.mentions !== void 0) {
2389
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
2390
+ }
2391
+ if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
2392
+ if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
2393
+ if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
2296
2394
  if (data.thread) this.thread = cacheThread(this.client, data.thread);
2297
2395
  }
2298
2396
  /**
@@ -2393,6 +2491,23 @@ var Message = class _Message extends Base {
2393
2491
  async fetch() {
2394
2492
  return this.client.channels.fetchMessage(this.channelId, this.id);
2395
2493
  }
2494
+ /** Publish this announcement message to channels following its channel. */
2495
+ async crosspost() {
2496
+ const data = await this.client.rest.post(
2497
+ Routes7.channelMessageCrosspost(this.channelId, this.id),
2498
+ { auth: true }
2499
+ );
2500
+ const published = new _Message(this.client, data);
2501
+ this.client._addMessageToCache(this.channelId, data);
2502
+ return published;
2503
+ }
2504
+ /** Fetch the source guild of a crossposted (followed-channel) message. */
2505
+ async fetchCrosspostSource() {
2506
+ return this.client.rest.get(
2507
+ Routes7.channelMessageCrosspostSource(this.channelId, this.id),
2508
+ { auth: true }
2509
+ );
2510
+ }
2396
2511
  /** Delete this message. */
2397
2512
  async delete(reason) {
2398
2513
  await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
@@ -2496,8 +2611,8 @@ var PartialMessage = class {
2496
2611
  };
2497
2612
 
2498
2613
  // src/Domain/User.ts
2499
- import { Routes as Routes17 } from "@fluxerjs/types";
2500
- import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
2614
+ import { Routes as Routes18 } from "@fluxerjs/types";
2615
+ import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
2501
2616
 
2502
2617
  // src/Domain/Channel/Dm.ts
2503
2618
  import { ChannelType as ChannelType4, Routes as Routes9 } from "@fluxerjs/types";
@@ -2556,7 +2671,7 @@ var DMChannel = class extends TextCapable(Channel) {
2556
2671
  const full = data;
2557
2672
  this.lastMessageId = full.last_message_id ?? null;
2558
2673
  this.ownerId = full.owner_id ?? null;
2559
- this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
2674
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
2560
2675
  this.nicks = full.nicks ?? {};
2561
2676
  }
2562
2677
  /**
@@ -2571,7 +2686,7 @@ var DMChannel = class extends TextCapable(Channel) {
2571
2686
  }
2572
2687
  if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2573
2688
  if ("recipients" in full && full.recipients !== void 0) {
2574
- this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2689
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
2575
2690
  }
2576
2691
  if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2577
2692
  }
@@ -2638,11 +2753,11 @@ var DMChannel = class extends TextCapable(Channel) {
2638
2753
  // src/Domain/Channel/Forum.ts
2639
2754
  import {
2640
2755
  ChannelType as ChannelType7,
2641
- Routes as Routes16
2756
+ Routes as Routes17
2642
2757
  } from "@fluxerjs/types";
2643
2758
 
2644
2759
  // src/Domain/Channel/Guild.ts
2645
- import { Routes as Routes13 } from "@fluxerjs/types";
2760
+ import { Routes as Routes14 } from "@fluxerjs/types";
2646
2761
  import { PermissionFlags } from "@fluxerjs/util";
2647
2762
 
2648
2763
  // src/Domain/Invite.ts
@@ -2656,17 +2771,19 @@ import {
2656
2771
  // src/Helpers/Instance.ts
2657
2772
  import { isRecord } from "@fluxerjs/util";
2658
2773
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2659
- api: "https://web.fluxer.app/api",
2660
- api_client: "https://web.fluxer.app/api",
2661
- api_public: "https://api.fluxer.app",
2662
- gateway: "wss://gateway.fluxer.app",
2774
+ api: "https://fluxer.com/api",
2775
+ api_client: "https://fluxer.com/api",
2776
+ api_public: "https://fluxer.com/api",
2777
+ gateway: "wss://gateway.fluxer.com",
2663
2778
  media: CDN_URL,
2779
+ upload_relay: "https://uploads.fluxer.app",
2664
2780
  static_cdn: STATIC_CDN_URL,
2665
- marketing: "https://fluxer.app",
2781
+ marketing: "https://fluxer.com",
2782
+ docs: "https://docs.fluxer.com",
2666
2783
  admin: "https://admin.fluxer.app",
2667
2784
  invite: "https://fluxer.gg",
2668
2785
  gift: "https://fluxer.gift",
2669
- webapp: "https://web.fluxer.app"
2786
+ webapp: "https://fluxer.com"
2670
2787
  });
2671
2788
  var ENDPOINT_KEYS = [
2672
2789
  "api",
@@ -2681,6 +2798,11 @@ var ENDPOINT_KEYS = [
2681
2798
  "gift",
2682
2799
  "webapp"
2683
2800
  ];
2801
+ var OPTIONAL_ENDPOINT_KEYS = [
2802
+ "api_transport",
2803
+ "upload_relay",
2804
+ "docs"
2805
+ ];
2684
2806
  function requireString(obj, key, path) {
2685
2807
  const value = obj[key];
2686
2808
  if (typeof value !== "string" || value.length === 0) {
@@ -2721,6 +2843,10 @@ function parseInstanceDiscovery(raw) {
2721
2843
  for (const key of ENDPOINT_KEYS) {
2722
2844
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2723
2845
  }
2846
+ for (const key of OPTIONAL_ENDPOINT_KEYS) {
2847
+ const value = raw.endpoints[key];
2848
+ if (typeof value === "string" && value.length > 0) endpoints[key] = value;
2849
+ }
2724
2850
  endpoints.api = normalizeApiOrigin(endpoints.api);
2725
2851
  endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2726
2852
  endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
@@ -2774,7 +2900,21 @@ function parseInstanceDiscovery(raw) {
2774
2900
  defaultsHash: ""
2775
2901
  },
2776
2902
  push: raw.push ?? { public_vapid_key: null },
2777
- app_public: raw.app_public ?? {}
2903
+ app_public: raw.app_public ?? {},
2904
+ ...typeof raw.codename === "string" ? { codename: raw.codename } : {},
2905
+ age_policy: isRecord(raw.age_policy) ? raw.age_policy : { geos: [] },
2906
+ ...raw.notice === null || isRecord(raw.notice) ? { notice: raw.notice } : {},
2907
+ ...isRecord(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
2908
+ ...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
2909
+ ...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
2910
+ ...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
2911
+ ...isRecord(raw.built_in_guild_badge_images) ? {
2912
+ built_in_guild_badge_images: raw.built_in_guild_badge_images
2913
+ } : {},
2914
+ ...Array.isArray(raw.hidden_built_in_guild_badges) ? {
2915
+ hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
2916
+ } : {},
2917
+ ...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
2778
2918
  };
2779
2919
  }
2780
2920
  function resolveInstanceEndpoints(input) {
@@ -2794,7 +2934,7 @@ function resolveInstanceEndpoints(input) {
2794
2934
  }
2795
2935
  const partial = input;
2796
2936
  const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
2797
- for (const key of ENDPOINT_KEYS) {
2937
+ for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
2798
2938
  const value = partial[key];
2799
2939
  if (typeof value === "string" && value.length > 0) {
2800
2940
  merged[key] = value;
@@ -3216,6 +3356,127 @@ var PermissionOverwriteManager = class {
3216
3356
  }
3217
3357
  };
3218
3358
 
3359
+ // src/Domain/StageInstance.ts
3360
+ import { Routes as Routes13, StageInstancePrivacyLevel } from "@fluxerjs/types";
3361
+ import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
3362
+ var StageInstance = class extends Base {
3363
+ client;
3364
+ id;
3365
+ guildId;
3366
+ channelId;
3367
+ topic;
3368
+ /** Always {@link StageInstancePrivacyLevel.GuildOnly} on Fluxer. */
3369
+ privacyLevel;
3370
+ /** Always `true` on Fluxer. */
3371
+ discoverableDisabled;
3372
+ /** Always null on Fluxer. */
3373
+ guildScheduledEventId;
3374
+ constructor(client, data) {
3375
+ super();
3376
+ this.client = client;
3377
+ this.id = data.id;
3378
+ this.guildId = data.guild_id;
3379
+ this.channelId = data.channel_id;
3380
+ this.topic = data.topic;
3381
+ this.privacyLevel = data.privacy_level ?? StageInstancePrivacyLevel.GuildOnly;
3382
+ this.discoverableDisabled = data.discoverable_disabled ?? true;
3383
+ this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
3384
+ }
3385
+ /** @internal Patch in place from a newer payload. */
3386
+ _patch(data) {
3387
+ if (data.topic !== void 0) this.topic = data.topic;
3388
+ if (data.privacy_level !== void 0) this.privacyLevel = data.privacy_level;
3389
+ if (data.discoverable_disabled !== void 0) {
3390
+ this.discoverableDisabled = data.discoverable_disabled;
3391
+ }
3392
+ if (data.guild_scheduled_event_id !== void 0) {
3393
+ this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
3394
+ }
3395
+ }
3396
+ get guild() {
3397
+ return this.client.guilds.get(this.guildId) ?? null;
3398
+ }
3399
+ get channel() {
3400
+ const channel = this.client.channels.get(this.channelId);
3401
+ return channel?.isStage() ? channel : null;
3402
+ }
3403
+ /** Unix timestamp (ms) when the stage started, from its snowflake ID. */
3404
+ get createdTimestamp() {
3405
+ return SnowflakeUtil5.timestampFromSnowflake(this.id);
3406
+ }
3407
+ get createdAt() {
3408
+ return SnowflakeUtil5.dateFromSnowflake(this.id);
3409
+ }
3410
+ /**
3411
+ * Change the live stage. Needs a stage moderator.
3412
+ * Fires `STAGE_INSTANCE_UPDATE`.
3413
+ */
3414
+ async edit(options) {
3415
+ const body = {};
3416
+ if (options.topic !== void 0) body.topic = options.topic;
3417
+ const data = await this.client.rest.patch(
3418
+ Routes13.stageInstance(this.channelId),
3419
+ { body, auth: true, ...auditReasonHeaders(options.reason) }
3420
+ );
3421
+ this._patch(data);
3422
+ return this;
3423
+ }
3424
+ /** Change the stage topic. Shorthand for {@link edit}. */
3425
+ async setTopic(topic, reason) {
3426
+ return this.edit({ topic, reason });
3427
+ }
3428
+ /**
3429
+ * End the stage. Needs a stage moderator. Speakers move to the audience, raised hands are
3430
+ * lowered, and everyone stays connected unless `disconnectAll` is set.
3431
+ */
3432
+ async delete(options = {}) {
3433
+ const route = Routes13.stageInstance(this.channelId) + (options.disconnectAll ? "?disconnect_all=true" : "");
3434
+ await this.client.rest.delete(route, { auth: true, ...auditReasonHeaders(options.reason) });
3435
+ }
3436
+ toJSON() {
3437
+ return {
3438
+ id: this.id,
3439
+ guild_id: this.guildId,
3440
+ channel_id: this.channelId,
3441
+ topic: this.topic,
3442
+ privacy_level: this.privacyLevel,
3443
+ discoverable_disabled: this.discoverableDisabled,
3444
+ guild_scheduled_event_id: this.guildScheduledEventId
3445
+ };
3446
+ }
3447
+ };
3448
+
3449
+ // src/Domain/Channel/StageSync.ts
3450
+ function syncStageInstances(guild, instances) {
3451
+ const seen = /* @__PURE__ */ new Set();
3452
+ for (const data of instances) {
3453
+ seen.add(data.id);
3454
+ const existing = guild.stageInstances.get(data.id);
3455
+ if (existing) existing._patch(data);
3456
+ else guild.stageInstances.set(data.id, new StageInstance(guild.client, data));
3457
+ }
3458
+ for (const id of [...guild.stageInstances.keys()]) {
3459
+ if (!seen.has(id)) guild.stageInstances.delete(id);
3460
+ }
3461
+ }
3462
+ function applyStageCounts(guild, counts) {
3463
+ for (const count of counts) {
3464
+ const channel = guild.channels.get(count.channel_id);
3465
+ if (channel?.isStage()) channel._patchCounts(count);
3466
+ }
3467
+ }
3468
+ function cacheStageInstance(client, data) {
3469
+ const guild = client.guilds.get(data.guild_id);
3470
+ const existing = guild?.stageInstances.get(data.id);
3471
+ if (existing) {
3472
+ existing._patch(data);
3473
+ return existing;
3474
+ }
3475
+ const instance = new StageInstance(client, data);
3476
+ guild?.stageInstances.set(instance.id, instance);
3477
+ return instance;
3478
+ }
3479
+
3219
3480
  // src/Domain/Channel/ThreadBind.ts
3220
3481
  var factory;
3221
3482
  var managers = /* @__PURE__ */ new WeakMap();
@@ -3270,7 +3531,7 @@ var GuildChannel = class extends Channel {
3270
3531
  }
3271
3532
  /** Create a webhook for this channel. Requires Manage Webhooks. */
3272
3533
  async createWebhook(options) {
3273
- const data = await this.client.rest.post(Routes13.channelWebhooks(this.id), {
3534
+ const data = await this.client.rest.post(Routes14.channelWebhooks(this.id), {
3274
3535
  body: options,
3275
3536
  auth: true
3276
3537
  });
@@ -3278,13 +3539,13 @@ var GuildChannel = class extends Channel {
3278
3539
  }
3279
3540
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
3280
3541
  async fetchWebhooks() {
3281
- const data = await this.client.rest.get(Routes13.channelWebhooks(this.id));
3542
+ const data = await this.client.rest.get(Routes14.channelWebhooks(this.id));
3282
3543
  return data.map((w) => new Webhook(this.client, w));
3283
3544
  }
3284
3545
  /** Create an invite for this channel. Requires Create Instant Invite. */
3285
3546
  async createInvite(options) {
3286
3547
  const body = options ? toChannelInviteBody(options) : {};
3287
- const data = await this.client.rest.post(Routes13.channelInvites(this.id), {
3548
+ const data = await this.client.rest.post(Routes14.channelInvites(this.id), {
3288
3549
  body: Object.keys(body).length ? body : void 0,
3289
3550
  auth: true
3290
3551
  });
@@ -3292,7 +3553,7 @@ var GuildChannel = class extends Channel {
3292
3553
  }
3293
3554
  /** Fetch all invites for this channel. Requires Manage Channels. */
3294
3555
  async fetchInvites() {
3295
- const data = await this.client.rest.get(Routes13.channelInvites(this.id));
3556
+ const data = await this.client.rest.get(Routes14.channelInvites(this.id));
3296
3557
  return data.map((i) => new Invite(this.client, i));
3297
3558
  }
3298
3559
  /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
@@ -3322,7 +3583,7 @@ var GuildChannel = class extends Channel {
3322
3583
  }
3323
3584
  /** Edit this channel's settings. Requires Manage Channels. */
3324
3585
  async edit(options) {
3325
- const data = await this.client.rest.patch(Routes13.channel(this.id), {
3586
+ const data = await this.client.rest.patch(Routes14.channel(this.id), {
3326
3587
  body: toChannelEditBody(options),
3327
3588
  auth: true,
3328
3589
  ...auditReasonHeaders(options.reason)
@@ -3404,7 +3665,7 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3404
3665
  * Sends only those fields. The thread-parent update body does not accept a channel rename.
3405
3666
  */
3406
3667
  async editThreadDefaults(options) {
3407
- const data = await this.client.rest.patch(Routes13.channel(this.id), {
3668
+ const data = await this.client.rest.patch(Routes14.channel(this.id), {
3408
3669
  body: toThreadParentEditBody(options),
3409
3670
  auth: true,
3410
3671
  ...auditReasonHeaders(options.reason)
@@ -3414,6 +3675,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3414
3675
  }
3415
3676
  };
3416
3677
  var AnnouncementChannel = class extends TextChannel {
3678
+ /**
3679
+ * Follow this announcement channel into `webhookChannelId` (a channel in a guild
3680
+ * where the bot can manage webhooks). Published messages are copied there.
3681
+ */
3682
+ async follow(webhookChannelId) {
3683
+ return this.client.rest.post(
3684
+ Routes14.channelFollowers(this.id),
3685
+ { body: { webhook_channel_id: webhookChannelId }, auth: true }
3686
+ );
3687
+ }
3688
+ /** Fetch follower counts for this announcement channel. */
3689
+ async fetchFollowerStats() {
3690
+ return this.client.rest.get(
3691
+ Routes14.channelFollowerStats(this.id),
3692
+ { auth: true }
3693
+ );
3694
+ }
3417
3695
  };
3418
3696
  var CategoryChannel = class extends GuildChannel {
3419
3697
  };
@@ -3440,6 +3718,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3440
3718
  voiceConnectionLimit;
3441
3719
  /** RTC region override for this channel. */
3442
3720
  rtcRegion;
3721
+ /** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
3722
+ rtcP2p;
3443
3723
  constructor(client, data) {
3444
3724
  super(client, data);
3445
3725
  this.topic = data.topic ?? null;
@@ -3453,6 +3733,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3453
3733
  this.userLimit = data.user_limit ?? null;
3454
3734
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3455
3735
  this.rtcRegion = data.rtc_region ?? null;
3736
+ this.rtcP2p = data.rtc_p2p ?? false;
3456
3737
  }
3457
3738
  /**
3458
3739
  * Set slowmode (seconds between messages). Pass `0` to disable.
@@ -3479,6 +3760,97 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3479
3760
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3480
3761
  }
3481
3762
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
3763
+ if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
3764
+ }
3765
+ };
3766
+ var StageChannel = class extends VoiceChannel {
3767
+ /** Last known stage counts, or null until Fluxer sends them. */
3768
+ counts = null;
3769
+ /** The cached live stage of this channel, or null when the stage isn't live (or not cached). */
3770
+ get stageInstance() {
3771
+ const guild = this.client.guilds.get(this.guildId);
3772
+ if (!guild) return null;
3773
+ for (const instance of guild.stageInstances.values()) {
3774
+ if (instance.channelId === this.id) return instance;
3775
+ }
3776
+ return null;
3777
+ }
3778
+ /** Whether the stage is live according to the cache. */
3779
+ get isLive() {
3780
+ return this.stageInstance !== null;
3781
+ }
3782
+ /**
3783
+ * Start a stage in this channel. Needs a stage moderator (`MANAGE_CHANNELS`, `MUTE_MEMBERS` and
3784
+ * `MOVE_MEMBERS`). When the caller is connected to the stage, they become a speaker.
3785
+ */
3786
+ async createStageInstance(options) {
3787
+ const body = { channel_id: this.id, topic: options.topic };
3788
+ if (options.sendStartNotification !== void 0) {
3789
+ body.send_start_notification = options.sendStartNotification;
3790
+ }
3791
+ const data = await this.client.rest.post(Routes14.stageInstances(), {
3792
+ body,
3793
+ auth: true,
3794
+ ...auditReasonHeaders(options.reason)
3795
+ });
3796
+ return cacheStageInstance(this.client, data);
3797
+ }
3798
+ /** Fetch the live stage of this channel. Rejects with `UNKNOWN_STAGE_INSTANCE` when not live. */
3799
+ async fetchStageInstance() {
3800
+ const data = await this.client.rest.get(Routes14.stageInstance(this.id), {
3801
+ auth: true
3802
+ });
3803
+ return cacheStageInstance(this.client, data);
3804
+ }
3805
+ /**
3806
+ * Move a member (or yourself when `user` is omitted) between the audience and the speakers.
3807
+ *
3808
+ * - Yourself, `false`: become a speaker (needs `MUTE_MEMBERS`), or accept an open invite.
3809
+ * - Yourself, `true`: move to the audience, or decline an invite.
3810
+ * - Another member, `false`: invite them to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`.
3811
+ * - Another member, `true`: move them to the audience and clear a raised hand or invite.
3812
+ */
3813
+ async setSuppressed(suppressed, user) {
3814
+ const userId = user === void 0 ? "@me" : typeof user === "string" ? user : user.id;
3815
+ const body = {
3816
+ channel_id: this.id,
3817
+ suppress: suppressed
3818
+ };
3819
+ await this.client.rest.patch(Routes14.guildVoiceState(this.guildId, userId), {
3820
+ body,
3821
+ auth: true
3822
+ });
3823
+ }
3824
+ /** Invite a member to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`. */
3825
+ async inviteToSpeak(user) {
3826
+ await this.setSuppressed(false, user);
3827
+ }
3828
+ /** Move a speaker (or yourself when `user` is omitted) to the audience. */
3829
+ async moveToAudience(user) {
3830
+ await this.setSuppressed(true, user);
3831
+ }
3832
+ /**
3833
+ * Raise (`true`) or lower (`false`) your hand. Raising needs a live stage and
3834
+ * `REQUEST_TO_SPEAK`; lowering also accepts an open invite to speak.
3835
+ */
3836
+ async setRequestToSpeak(raised = true) {
3837
+ const body = {
3838
+ channel_id: this.id,
3839
+ request_to_speak_timestamp: raised ? (/* @__PURE__ */ new Date()).toISOString() : null
3840
+ };
3841
+ await this.client.rest.patch(Routes14.guildVoiceState(this.guildId, "@me"), {
3842
+ body,
3843
+ auth: true
3844
+ });
3845
+ }
3846
+ /** @internal Apply a stage count object. */
3847
+ _patchCounts(data) {
3848
+ this.counts = {
3849
+ listenerCount: data.listener_count,
3850
+ speakerCount: data.speaker_count,
3851
+ requestCount: data.request_count,
3852
+ videoEnabled: data.video_enabled ?? null
3853
+ };
3482
3854
  }
3483
3855
  };
3484
3856
  var LinkChannel = class extends GuildChannel {
@@ -3494,10 +3866,10 @@ var LinkChannel = class extends GuildChannel {
3494
3866
  };
3495
3867
 
3496
3868
  // src/Domain/Channel/ThreadManager.ts
3497
- import { ChannelType as ChannelType6, Routes as Routes15 } from "@fluxerjs/types";
3869
+ import { ChannelType as ChannelType6, Routes as Routes16 } from "@fluxerjs/types";
3498
3870
 
3499
3871
  // src/Domain/Channel/ThreadChannel.ts
3500
- import { ChannelType as ChannelType5, Routes as Routes14 } from "@fluxerjs/types";
3872
+ import { ChannelType as ChannelType5, Routes as Routes15 } from "@fluxerjs/types";
3501
3873
  var ThreadMember = class {
3502
3874
  /** Thread ID. */
3503
3875
  id;
@@ -3624,7 +3996,7 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
3624
3996
  * `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
3625
3997
  */
3626
3998
  async edit(options) {
3627
- const data = await this.client.rest.patch(Routes14.channel(this.id), {
3999
+ const data = await this.client.rest.patch(Routes15.channel(this.id), {
3628
4000
  body: toThreadEditBody(this.type, threadEditFields(options)),
3629
4001
  auth: true,
3630
4002
  ...auditReasonHeaders(options.reason)
@@ -3642,16 +4014,16 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
3642
4014
  }
3643
4015
  /** Join this thread. */
3644
4016
  async join() {
3645
- await this.client.rest.put(Routes14.channelThreadMemberMe(this.id), { auth: true });
4017
+ await this.client.rest.put(Routes15.channelThreadMemberMe(this.id), { auth: true });
3646
4018
  }
3647
4019
  /** Leave this thread. */
3648
4020
  async leave() {
3649
- await this.client.rest.delete(Routes14.channelThreadMemberMe(this.id), { auth: true });
4021
+ await this.client.rest.delete(Routes15.channelThreadMemberMe(this.id), { auth: true });
3650
4022
  }
3651
4023
  /** Update the current user's notification settings for this thread. */
3652
4024
  async editSelf(options) {
3653
4025
  const data = await this.client.rest.patch(
3654
- Routes14.channelThreadMemberMeSettings(this.id),
4026
+ Routes15.channelThreadMemberMeSettings(this.id),
3655
4027
  { body: toThreadMemberSettingsBody(options), auth: true }
3656
4028
  );
3657
4029
  this.member = data ? new ThreadMember(data) : null;
@@ -3665,7 +4037,7 @@ var ThreadMemberManager = class {
3665
4037
  /** List members of this thread. */
3666
4038
  async fetch(options) {
3667
4039
  const data = await this.thread.client.rest.get(
3668
- withQuery(Routes14.channelThreadMembers(this.thread.id), {
4040
+ withQuery(Routes15.channelThreadMembers(this.thread.id), {
3669
4041
  with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
3670
4042
  after: options?.after,
3671
4043
  limit: options?.limit
@@ -3676,7 +4048,7 @@ var ThreadMemberManager = class {
3676
4048
  /** Fetch one member of this thread. */
3677
4049
  async fetchOne(userId, options) {
3678
4050
  const data = await this.thread.client.rest.get(
3679
- withQuery(Routes14.channelThreadMember(this.thread.id, userId), {
4051
+ withQuery(Routes15.channelThreadMember(this.thread.id, userId), {
3680
4052
  with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
3681
4053
  })
3682
4054
  );
@@ -3684,13 +4056,13 @@ var ThreadMemberManager = class {
3684
4056
  }
3685
4057
  /** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
3686
4058
  async add(userId) {
3687
- await this.thread.client.rest.put(Routes14.channelThreadMember(this.thread.id, userId), {
4059
+ await this.thread.client.rest.put(Routes15.channelThreadMember(this.thread.id, userId), {
3688
4060
  auth: true
3689
4061
  });
3690
4062
  }
3691
4063
  /** Remove a user from this thread. */
3692
4064
  async remove(userId) {
3693
- await this.thread.client.rest.delete(Routes14.channelThreadMember(this.thread.id, userId), {
4065
+ await this.thread.client.rest.delete(Routes15.channelThreadMember(this.thread.id, userId), {
3694
4066
  auth: true
3695
4067
  });
3696
4068
  }
@@ -3715,7 +4087,7 @@ var ThreadManager = class {
3715
4087
  });
3716
4088
  }
3717
4089
  const data = await this.channel.client.rest.post(
3718
- Routes15.channelThreads(this.channel.id),
4090
+ Routes16.channelThreads(this.channel.id),
3719
4091
  {
3720
4092
  body: toStartThreadBody(this.channel.type, options),
3721
4093
  auth: true,
@@ -3748,7 +4120,7 @@ var ThreadManager = class {
3748
4120
  if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
3749
4121
  if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
3750
4122
  const data = await this.channel.client.rest.post(
3751
- Routes15.channelThreads(this.channel.id),
4123
+ Routes16.channelThreads(this.channel.id),
3752
4124
  {
3753
4125
  body,
3754
4126
  files: prepared.files,
@@ -3767,7 +4139,7 @@ var ThreadManager = class {
3767
4139
  * `before` is an ISO-8601 archive timestamp.
3768
4140
  */
3769
4141
  async fetchArchived(options) {
3770
- const path = options.type === "private" ? Routes15.channelThreadsArchivedPrivate(this.channel.id) : Routes15.channelThreadsArchivedPublic(this.channel.id);
4142
+ const path = options.type === "private" ? Routes16.channelThreadsArchivedPrivate(this.channel.id) : Routes16.channelThreadsArchivedPublic(this.channel.id);
3771
4143
  const data = await this.channel.client.rest.get(
3772
4144
  withQuery(path, { before: options.before, limit: options.limit })
3773
4145
  );
@@ -3779,7 +4151,7 @@ var ThreadManager = class {
3779
4151
  */
3780
4152
  async fetchJoinedPrivateArchived(options) {
3781
4153
  const data = await this.channel.client.rest.get(
3782
- withQuery(Routes15.channelJoinedArchivedPrivateThreads(this.channel.id), {
4154
+ withQuery(Routes16.channelJoinedArchivedPrivateThreads(this.channel.id), {
3783
4155
  before: options?.before,
3784
4156
  limit: options?.limit
3785
4157
  })
@@ -3792,7 +4164,7 @@ var ThreadManager = class {
3792
4164
  */
3793
4165
  async search(options) {
3794
4166
  const data = await this.channel.client.rest.get(
3795
- withQuery(Routes15.channelThreadSearch(this.channel.id), {
4167
+ withQuery(Routes16.channelThreadSearch(this.channel.id), {
3796
4168
  name: options?.name,
3797
4169
  tag: options?.tag,
3798
4170
  tag_setting: options?.tagSetting,
@@ -3820,7 +4192,7 @@ var ThreadManager = class {
3820
4192
  }
3821
4193
  /** Set the auto-archive and slowmode defaults copied onto new threads. */
3822
4194
  async editDefaults(options) {
3823
- return this.channel.client.rest.patch(Routes15.channel(this.channel.id), {
4195
+ return this.channel.client.rest.patch(Routes16.channel(this.channel.id), {
3824
4196
  body: toThreadParentEditBody(options),
3825
4197
  auth: true,
3826
4198
  ...auditReasonHeaders(options.reason)
@@ -3838,7 +4210,7 @@ function isSearchNotReady(data) {
3838
4210
  return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
3839
4211
  }
3840
4212
  async function fetchActiveThreads(client, guildId) {
3841
- const data = await client.rest.get(Routes15.guildActiveThreads(guildId));
4213
+ const data = await client.rest.get(Routes16.guildActiveThreads(guildId));
3842
4214
  return fetchedThreadsFrom(client, data);
3843
4215
  }
3844
4216
 
@@ -3897,7 +4269,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3897
4269
  * `defaultForumLayout` is sent only for forum channels.
3898
4270
  */
3899
4271
  async edit(options) {
3900
- const data = await this.client.rest.patch(Routes16.channel(this.id), {
4272
+ const data = await this.client.rest.patch(Routes17.channel(this.id), {
3901
4273
  body: {
3902
4274
  ...toChannelEditBody(options),
3903
4275
  ...forumParentWire(options, this.type === ChannelType7.GuildForum)
@@ -3926,7 +4298,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3926
4298
  }
3927
4299
  /** Set the auto-archive and slowmode defaults copied onto new posts. */
3928
4300
  async editThreadDefaults(options) {
3929
- const data = await this.client.rest.patch(Routes16.channel(this.id), {
4301
+ const data = await this.client.rest.patch(Routes17.channel(this.id), {
3930
4302
  body: toThreadParentEditBody(options),
3931
4303
  auth: true,
3932
4304
  ...auditReasonHeaders(options.reason)
@@ -3936,7 +4308,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3936
4308
  }
3937
4309
  /** Create a tag. The response replaces {@link availableTags}. */
3938
4310
  async createTag(options) {
3939
- const data = await this.client.rest.post(Routes16.channelTags(this.id), {
4311
+ const data = await this.client.rest.post(Routes17.channelTags(this.id), {
3940
4312
  body: toForumTagBody(options),
3941
4313
  auth: true,
3942
4314
  ...auditReasonHeaders(options.reason)
@@ -3946,7 +4318,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3946
4318
  }
3947
4319
  /** Replace a tag. The response replaces {@link availableTags}. */
3948
4320
  async editTag(tagId, options) {
3949
- const data = await this.client.rest.put(Routes16.channelTag(this.id, tagId), {
4321
+ const data = await this.client.rest.put(Routes17.channelTag(this.id, tagId), {
3950
4322
  body: toForumTagBody(options),
3951
4323
  auth: true,
3952
4324
  ...auditReasonHeaders(options.reason)
@@ -3956,7 +4328,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3956
4328
  }
3957
4329
  /** Delete a tag. The response replaces {@link availableTags}. */
3958
4330
  async deleteTag(tagId, reason) {
3959
- const data = await this.client.rest.delete(Routes16.channelTag(this.id, tagId), {
4331
+ const data = await this.client.rest.delete(Routes17.channelTag(this.id, tagId), {
3960
4332
  auth: true,
3961
4333
  ...auditReasonHeaders(reason)
3962
4334
  });
@@ -3991,6 +4363,7 @@ var GUILD_FACTORIES = {
3991
4363
  [ChannelType8.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
3992
4364
  [ChannelType8.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3993
4365
  [ChannelType8.GuildVoice]: (c, d) => new VoiceChannel(c, d),
4366
+ [ChannelType8.GuildStageVoice]: (c, d) => new StageChannel(c, d),
3994
4367
  [ChannelType8.GuildLink]: (c, d) => new LinkChannel(c, d),
3995
4368
  [ChannelType8.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
3996
4369
  [ChannelType8.PublicThread]: (c, d) => new ThreadChannel(c, d),
@@ -4044,12 +4417,15 @@ var User = class extends Base {
4044
4417
  system;
4045
4418
  /** Banner hash for profile. */
4046
4419
  banner;
4420
+ /** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
4421
+ partial;
4047
4422
  constructor(client, data) {
4048
4423
  super();
4049
4424
  this.client = client;
4050
4425
  this.id = data.id;
4051
- this.username = data.username;
4052
- this.discriminator = data.discriminator;
4426
+ this.partial = typeof data.username !== "string" || data.username.length === 0;
4427
+ this.username = data.username ?? "Unknown";
4428
+ this.discriminator = data.discriminator ?? "0";
4053
4429
  this.globalName = data.global_name ?? null;
4054
4430
  this.avatar = data.avatar ?? null;
4055
4431
  this.bot = !!data.bot;
@@ -4060,13 +4436,18 @@ var User = class extends Base {
4060
4436
  }
4061
4437
  /** @internal */
4062
4438
  _patch(data) {
4063
- this.username = data.username;
4064
- this.discriminator = data.discriminator;
4065
- this.globalName = data.global_name ?? null;
4066
- this.avatar = data.avatar ?? null;
4439
+ if (data.username !== void 0) this.username = data.username;
4440
+ if (data.discriminator !== void 0) this.discriminator = data.discriminator;
4441
+ if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
4442
+ if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
4067
4443
  if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
4068
4444
  if (data.flags !== void 0) this.flags = data.flags;
4069
4445
  if (data.banner !== void 0) this.banner = data.banner;
4446
+ if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
4447
+ }
4448
+ /** Fetch the full user from REST when this instance is a partial stub. */
4449
+ async fetch() {
4450
+ return this.client.users.fetch(this.id, { force: true });
4070
4451
  }
4071
4452
  cdnOpts() {
4072
4453
  return {
@@ -4104,11 +4485,11 @@ var User = class extends Base {
4104
4485
  */
4105
4486
  /** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
4106
4487
  get createdTimestamp() {
4107
- return SnowflakeUtil5.timestampFromSnowflake(this.id);
4488
+ return SnowflakeUtil6.timestampFromSnowflake(this.id);
4108
4489
  }
4109
4490
  /** Date when this account was created, derived from its snowflake ID. */
4110
4491
  get createdAt() {
4111
- return SnowflakeUtil5.dateFromSnowflake(this.id);
4492
+ return SnowflakeUtil6.dateFromSnowflake(this.id);
4112
4493
  }
4113
4494
  toString() {
4114
4495
  return `<@${this.id}>`;
@@ -4118,7 +4499,7 @@ var User = class extends Base {
4118
4499
  * @returns DM channel instance (cached if already open)
4119
4500
  */
4120
4501
  async createDM() {
4121
- const data = await this.client.rest.post(Routes17.userMeChannels(), {
4502
+ const data = await this.client.rest.post(Routes18.userMeChannels(), {
4122
4503
  body: { recipient_id: this.id },
4123
4504
  auth: true
4124
4505
  });
@@ -4335,14 +4716,14 @@ var CacheController = class {
4335
4716
 
4336
4717
  // src/ClientCore/ChannelManager.ts
4337
4718
  import { LimitedCollection } from "@fluxerjs/collection";
4338
- import { Routes as Routes23 } from "@fluxerjs/types";
4719
+ import { Routes as Routes24 } from "@fluxerjs/types";
4339
4720
 
4340
4721
  // src/Domain/Guild/Cache.ts
4341
4722
  import { ChannelType as ChannelType9 } from "@fluxerjs/types";
4342
4723
 
4343
4724
  // src/Domain/Guild/GuildEmoji.ts
4344
- import { Routes as Routes18 } from "@fluxerjs/types";
4345
- import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
4725
+ import { Routes as Routes19 } from "@fluxerjs/types";
4726
+ import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
4346
4727
  var GuildEmoji = class extends Base {
4347
4728
  client;
4348
4729
  id;
@@ -4378,11 +4759,11 @@ var GuildEmoji = class extends Base {
4378
4759
  }
4379
4760
  /** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
4380
4761
  get createdTimestamp() {
4381
- return SnowflakeUtil6.timestampFromSnowflake(this.id);
4762
+ return SnowflakeUtil7.timestampFromSnowflake(this.id);
4382
4763
  }
4383
4764
  /** Date when this emoji was created, derived from its snowflake ID. */
4384
4765
  get createdAt() {
4385
- return SnowflakeUtil6.dateFromSnowflake(this.id);
4766
+ return SnowflakeUtil7.dateFromSnowflake(this.id);
4386
4767
  }
4387
4768
  /** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
4388
4769
  toString() {
@@ -4390,7 +4771,7 @@ var GuildEmoji = class extends Base {
4390
4771
  }
4391
4772
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
4392
4773
  async delete(reason) {
4393
- await this.client.rest.delete(Routes18.guildEmoji(this.guildId, this.id), {
4774
+ await this.client.rest.delete(Routes19.guildEmoji(this.guildId, this.id), {
4394
4775
  auth: true,
4395
4776
  ...auditReasonHeaders(reason)
4396
4777
  });
@@ -4403,7 +4784,7 @@ var GuildEmoji = class extends Base {
4403
4784
  */
4404
4785
  async edit(options) {
4405
4786
  const { reason, name } = options;
4406
- const data = await this.client.rest.patch(Routes18.guildEmoji(this.guildId, this.id), {
4787
+ const data = await this.client.rest.patch(Routes19.guildEmoji(this.guildId, this.id), {
4407
4788
  body: { name },
4408
4789
  auth: true,
4409
4790
  ...auditReasonHeaders(reason)
@@ -4414,7 +4795,7 @@ var GuildEmoji = class extends Base {
4414
4795
  };
4415
4796
 
4416
4797
  // src/Domain/Guild/GuildMember.ts
4417
- import { Routes as Routes20 } from "@fluxerjs/types";
4798
+ import { Routes as Routes21 } from "@fluxerjs/types";
4418
4799
  import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
4419
4800
 
4420
4801
  // src/Helpers/Permissions.ts
@@ -4438,7 +4819,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
4438
4819
 
4439
4820
  // src/Domain/Guild/GuildMemberRoleManager.ts
4440
4821
  import { Collection as Collection7 } from "@fluxerjs/collection";
4441
- import { Routes as Routes19 } from "@fluxerjs/types";
4822
+ import { Routes as Routes20 } from "@fluxerjs/types";
4442
4823
  function roleId(roleOrId) {
4443
4824
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
4444
4825
  }
@@ -4467,7 +4848,7 @@ var GuildMemberRoleManager = class {
4467
4848
  const id = roleId(roleOrId);
4468
4849
  if (this.ids.includes(id)) return;
4469
4850
  await this.member.client.rest.put(
4470
- Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
4851
+ Routes20.guildMemberRole(this.member.guild.id, this.member.id, id)
4471
4852
  );
4472
4853
  this.ids.push(id);
4473
4854
  }
@@ -4476,13 +4857,13 @@ var GuildMemberRoleManager = class {
4476
4857
  const idx = this.ids.indexOf(id);
4477
4858
  if (idx === -1) return;
4478
4859
  await this.member.client.rest.delete(
4479
- Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
4860
+ Routes20.guildMemberRole(this.member.guild.id, this.member.id, id)
4480
4861
  );
4481
4862
  this.ids.splice(idx, 1);
4482
4863
  }
4483
4864
  async set(roleIds) {
4484
4865
  const data = await this.member.client.rest.patch(
4485
- Routes19.guildMember(this.member.guild.id, this.member.id),
4866
+ Routes20.guildMember(this.member.guild.id, this.member.id),
4486
4867
  { body: { roles: roleIds }, auth: true }
4487
4868
  );
4488
4869
  this.ids = data.roles ? [...data.roles] : [];
@@ -4636,7 +5017,7 @@ var GuildMember = class _GuildMember extends Base {
4636
5017
  */
4637
5018
  async edit(options) {
4638
5019
  const isMe = this.client.user?.id === this.id;
4639
- const route = isMe ? Routes20.guildMemberMe(this.guild.id) : Routes20.guildMember(this.guild.id, this.id);
5020
+ const route = isMe ? Routes21.guildMemberMe(this.guild.id) : Routes21.guildMember(this.guild.id, this.id);
4640
5021
  const data = await this.client.rest.patch(route, {
4641
5022
  body: toMemberEditBody(options),
4642
5023
  auth: true,
@@ -4749,8 +5130,8 @@ var GuildMember = class _GuildMember extends Base {
4749
5130
  };
4750
5131
 
4751
5132
  // src/Domain/Guild/GuildSticker.ts
4752
- import { Routes as Routes21 } from "@fluxerjs/types";
4753
- import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
5133
+ import { Routes as Routes22 } from "@fluxerjs/types";
5134
+ import { SnowflakeUtil as SnowflakeUtil8 } from "@fluxerjs/util";
4754
5135
  var GuildSticker = class extends Base {
4755
5136
  client;
4756
5137
  id;
@@ -4792,15 +5173,15 @@ var GuildSticker = class extends Base {
4792
5173
  }
4793
5174
  /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
4794
5175
  get createdTimestamp() {
4795
- return SnowflakeUtil7.timestampFromSnowflake(this.id);
5176
+ return SnowflakeUtil8.timestampFromSnowflake(this.id);
4796
5177
  }
4797
5178
  /** Date when this sticker was created, derived from its snowflake ID. */
4798
5179
  get createdAt() {
4799
- return SnowflakeUtil7.dateFromSnowflake(this.id);
5180
+ return SnowflakeUtil8.dateFromSnowflake(this.id);
4800
5181
  }
4801
5182
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
4802
5183
  async delete(reason) {
4803
- await this.client.rest.delete(Routes21.guildSticker(this.guildId, this.id), {
5184
+ await this.client.rest.delete(Routes22.guildSticker(this.guildId, this.id), {
4804
5185
  auth: true,
4805
5186
  ...auditReasonHeaders(reason)
4806
5187
  });
@@ -4813,7 +5194,7 @@ var GuildSticker = class extends Base {
4813
5194
  */
4814
5195
  async edit(options) {
4815
5196
  const { reason, ...body } = options;
4816
- const data = await this.client.rest.patch(Routes21.guildSticker(this.guildId, this.id), {
5197
+ const data = await this.client.rest.patch(Routes22.guildSticker(this.guildId, this.id), {
4817
5198
  body,
4818
5199
  auth: true,
4819
5200
  ...auditReasonHeaders(reason)
@@ -4826,12 +5207,12 @@ var GuildSticker = class extends Base {
4826
5207
  };
4827
5208
 
4828
5209
  // src/Domain/Guild/Role.ts
4829
- import { Routes as Routes22 } from "@fluxerjs/types";
5210
+ import { Routes as Routes23 } from "@fluxerjs/types";
4830
5211
  import {
4831
5212
  ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
4832
5213
  PermissionFlags as PermissionFlags4,
4833
5214
  PermissionsBitField as PermissionsBitField3,
4834
- SnowflakeUtil as SnowflakeUtil8
5215
+ SnowflakeUtil as SnowflakeUtil9
4835
5216
  } from "@fluxerjs/util";
4836
5217
  var Role = class _Role extends Base {
4837
5218
  /** Parent client instance. */
@@ -4854,6 +5235,8 @@ var Role = class _Role extends Base {
4854
5235
  mentionable;
4855
5236
  /** Unicode emoji for this role (null = none). */
4856
5237
  unicodeEmoji;
5238
+ /** Role icon image hash (null = none). */
5239
+ icon;
4857
5240
  /** Hoist position (null = not hoisted). */
4858
5241
  hoistPosition;
4859
5242
  constructor(client, data, guildId) {
@@ -4861,20 +5244,26 @@ var Role = class _Role extends Base {
4861
5244
  this.client = client;
4862
5245
  this.id = data.id;
4863
5246
  this.guildId = guildId;
4864
- this.name = data.name;
4865
- this.color = data.color;
4866
- this.position = data.position;
4867
- this._permissions = data.permissions;
5247
+ this.name = data.name ?? "";
5248
+ this.color = data.color ?? 0;
5249
+ this.position = data.position ?? 0;
5250
+ this._permissions = data.permissions ?? "0";
4868
5251
  this.hoist = !!data.hoist;
4869
5252
  this.mentionable = !!data.mentionable;
4870
5253
  this.unicodeEmoji = data.unicode_emoji ?? null;
5254
+ this.icon = data.icon ?? null;
4871
5255
  this.hoistPosition = data.hoist_position ?? null;
4872
5256
  }
4873
5257
  /**
4874
5258
  * Permissions bitfield (Administrator grants all permissions).
4875
5259
  */
4876
5260
  get permissions() {
4877
- const bits = BigInt(this._permissions);
5261
+ let bits;
5262
+ try {
5263
+ bits = BigInt(this._permissions ?? "0");
5264
+ } catch {
5265
+ bits = 0n;
5266
+ }
4878
5267
  return new PermissionsBitField3(
4879
5268
  (bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
4880
5269
  );
@@ -4893,25 +5282,26 @@ var Role = class _Role extends Base {
4893
5282
  */
4894
5283
  /** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
4895
5284
  get createdTimestamp() {
4896
- return SnowflakeUtil8.timestampFromSnowflake(this.id);
5285
+ return SnowflakeUtil9.timestampFromSnowflake(this.id);
4897
5286
  }
4898
5287
  /** Date when this role was created, derived from its snowflake ID. */
4899
5288
  get createdAt() {
4900
- return SnowflakeUtil8.dateFromSnowflake(this.id);
5289
+ return SnowflakeUtil9.dateFromSnowflake(this.id);
4901
5290
  }
4902
5291
  toString() {
4903
5292
  return `<@&${this.id}>`;
4904
5293
  }
4905
5294
  /** @internal */
4906
5295
  _patch(data) {
4907
- this.name = data.name;
4908
- this.color = data.color;
4909
- this.position = data.position;
4910
- this._permissions = data.permissions;
4911
- this.hoist = !!data.hoist;
4912
- this.mentionable = !!data.mentionable;
4913
- this.unicodeEmoji = data.unicode_emoji ?? null;
4914
- this.hoistPosition = data.hoist_position ?? null;
5296
+ if (data.name !== void 0) this.name = data.name;
5297
+ if (data.color !== void 0) this.color = data.color;
5298
+ if (data.position !== void 0) this.position = data.position;
5299
+ if (data.permissions !== void 0) this._permissions = data.permissions;
5300
+ if (data.hoist !== void 0) this.hoist = !!data.hoist;
5301
+ if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
5302
+ if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
5303
+ if (data.icon !== void 0) this.icon = data.icon ?? null;
5304
+ if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
4915
5305
  }
4916
5306
  /**
4917
5307
  * Snapshot for role-update events (before in-place patch).
@@ -4929,6 +5319,7 @@ var Role = class _Role extends Base {
4929
5319
  hoist: this.hoist,
4930
5320
  mentionable: this.mentionable,
4931
5321
  unicode_emoji: this.unicodeEmoji,
5322
+ icon: this.icon,
4932
5323
  hoist_position: this.hoistPosition
4933
5324
  },
4934
5325
  this.guildId
@@ -4941,7 +5332,7 @@ var Role = class _Role extends Base {
4941
5332
  */
4942
5333
  async edit(options) {
4943
5334
  const body = toRoleEditBody(options);
4944
- const data = await this.client.rest.patch(Routes22.guildRole(this.guildId, this.id), {
5335
+ const data = await this.client.rest.patch(Routes23.guildRole(this.guildId, this.id), {
4945
5336
  body: Object.keys(body).length ? body : void 0,
4946
5337
  auth: true,
4947
5338
  ...auditReasonHeaders(options.reason)
@@ -4954,7 +5345,7 @@ var Role = class _Role extends Base {
4954
5345
  * @param reason - Audit log reason (`X-Audit-Log-Reason`)
4955
5346
  */
4956
5347
  async delete(reason) {
4957
- await this.client.rest.delete(Routes22.guildRole(this.guildId, this.id), {
5348
+ await this.client.rest.delete(Routes23.guildRole(this.guildId, this.id), {
4958
5349
  auth: true,
4959
5350
  ...auditReasonHeaders(reason)
4960
5351
  });
@@ -5106,6 +5497,7 @@ var ChannelManager = class extends LimitedCollection {
5106
5497
  });
5107
5498
  this.client = client;
5108
5499
  }
5500
+ pendingFetches = /* @__PURE__ */ new Map();
5109
5501
  /**
5110
5502
  * Remove a channel from cache. Does not delete it on the API.
5111
5503
  * Use {@link Channel.delete} after {@link fetch} to delete the channel.
@@ -5118,9 +5510,11 @@ var ChannelManager = class extends LimitedCollection {
5118
5510
  }
5119
5511
  return deleted;
5120
5512
  }
5121
- /** Retrieve from cache, otherwise {@link fetch}. */
5513
+ /** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
5122
5514
  async resolve(channelId) {
5123
- return this.get(channelId) ?? this.fetch(channelId);
5515
+ const id = normalizeSnowflakeId(channelId, "channels.resolve()");
5516
+ const cached = this.get(id);
5517
+ return cached && !cached.partial ? cached : this.fetch(id);
5124
5518
  }
5125
5519
  /**
5126
5520
  * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
@@ -5133,10 +5527,23 @@ var ChannelManager = class extends LimitedCollection {
5133
5527
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
5134
5528
  */
5135
5529
  async fetch(channelId, options) {
5136
- const cached = this.get(channelId);
5137
- if (cached && !options?.force) return cached;
5530
+ const id = normalizeSnowflakeId(channelId, "channels.fetch()");
5531
+ const cached = this.get(id);
5532
+ if (cached && !cached.partial && !options?.force) return cached;
5533
+ return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
5534
+ }
5535
+ async fetchFresh(channelId) {
5138
5536
  try {
5139
- const data = await this.client.rest.get(Routes23.channel(channelId));
5537
+ const data = assertApiObjectWithId(
5538
+ await this.client.rest.get(Routes24.channel(channelId)),
5539
+ "channels.fetch()"
5540
+ );
5541
+ const existing = this.get(channelId);
5542
+ if (existing && existing.type === data.type) {
5543
+ existing._patch(data);
5544
+ putChannel(this.client, existing);
5545
+ return existing;
5546
+ }
5140
5547
  const guildId = "guild_id" in data ? data.guild_id : void 0;
5141
5548
  if (guildId) {
5142
5549
  const guild = this.client.guilds.get(guildId);
@@ -5181,7 +5588,7 @@ var ChannelManager = class extends LimitedCollection {
5181
5588
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
5182
5589
  });
5183
5590
  const data = await this.client.rest.post(
5184
- Routes23.channelMessages(channelId),
5591
+ Routes24.channelMessages(channelId),
5185
5592
  postPayload
5186
5593
  );
5187
5594
  this.client._addMessageToCache(channelId, data);
@@ -5191,7 +5598,7 @@ var ChannelManager = class extends LimitedCollection {
5191
5598
 
5192
5599
  // src/ClientCore/ClientEmoji.ts
5193
5600
  import { Collection as Collection8 } from "@fluxerjs/collection";
5194
- import { Routes as Routes24 } from "@fluxerjs/types";
5601
+ import { Routes as Routes25 } from "@fluxerjs/types";
5195
5602
  import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
5196
5603
  async function resolveClientEmoji(client, emoji, guildId) {
5197
5604
  if (typeof emoji === "object" && emoji.id) {
@@ -5210,7 +5617,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
5210
5617
  const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
5211
5618
  if (unicodeFromShortcode) return unicodeFromShortcode;
5212
5619
  if (guildId) {
5213
- const emojis = await client.rest.get(Routes24.guildEmojis(guildId));
5620
+ const emojis = await client.rest.get(Routes25.guildEmojis(guildId));
5214
5621
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
5215
5622
  if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
5216
5623
  throw new FluxerError(
@@ -5227,26 +5634,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
5227
5634
  return parsed.name;
5228
5635
  }
5229
5636
  async function fetchInstance(client) {
5230
- const raw = await client.rest.get(Routes24.instanceDiscovery(), {
5637
+ const raw = await client.rest.get(Routes25.instanceDiscovery(), {
5231
5638
  auth: false,
5232
5639
  unversioned: true
5233
5640
  });
5234
5641
  return parseInstanceDiscovery(raw);
5235
5642
  }
5236
5643
  function fetchGatewayInfo(client) {
5237
- return client.rest.get(Routes24.gatewayBot());
5644
+ return client.rest.get(Routes25.gatewayBot());
5238
5645
  }
5239
5646
  function fetchEmojiMetadata(client, emojiId) {
5240
- return client.rest.get(Routes24.emojiMetadata(emojiId), { auth: true });
5647
+ return client.rest.get(Routes25.emojiMetadata(emojiId), { auth: true });
5241
5648
  }
5242
5649
  function fetchStickerMetadata(client, stickerId) {
5243
- return client.rest.get(Routes24.stickerMetadata(stickerId), { auth: true });
5650
+ return client.rest.get(Routes25.stickerMetadata(stickerId), { auth: true });
5244
5651
  }
5245
5652
  function fetchApplication(client) {
5246
- return client.rest.get(Routes24.applicationsMe(), { auth: true });
5653
+ return client.rest.get(Routes25.applicationsMe(), { auth: true });
5247
5654
  }
5248
5655
  async function fetchOAuthApplications(client) {
5249
- const data = await client.rest.get(Routes24.oauth2ApplicationsMe(), { auth: true });
5656
+ const data = await client.rest.get(Routes25.oauth2ApplicationsMe(), { auth: true });
5250
5657
  if (Array.isArray(data)) return data;
5251
5658
  if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
5252
5659
  return data.applications;
@@ -5265,14 +5672,14 @@ function assertChannelIdBatch(name, channelIds) {
5265
5672
  }
5266
5673
  function preloadMessages(client, channelIds) {
5267
5674
  assertChannelIdBatch("preloadMessages", channelIds);
5268
- return client.rest.post(Routes24.preloadMessages(), {
5675
+ return client.rest.post(Routes25.preloadMessages(), {
5269
5676
  body: { channels: channelIds },
5270
5677
  auth: true
5271
5678
  });
5272
5679
  }
5273
5680
  function preloadMessagesAlt(client, channelIds) {
5274
5681
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
5275
- return client.rest.post(Routes24.preloadMessagesAlt(), {
5682
+ return client.rest.post(Routes25.preloadMessagesAlt(), {
5276
5683
  body: { channels: channelIds },
5277
5684
  auth: true
5278
5685
  });
@@ -5280,7 +5687,7 @@ function preloadMessagesAlt(client, channelIds) {
5280
5687
  async function bulkFetchMessages(client, requests, options = {}) {
5281
5688
  validateBulkMessageFetchRequests(requests);
5282
5689
  const wire = toBulkFetchWire(requests);
5283
- const data = await client.rest.post(Routes24.channelsMessagesBulk(), {
5690
+ const data = await client.rest.post(Routes25.channelsMessagesBulk(), {
5284
5691
  body: { requests: wire },
5285
5692
  auth: true
5286
5693
  });
@@ -5297,12 +5704,74 @@ async function bulkFetchMessages(client, requests, options = {}) {
5297
5704
  };
5298
5705
  }
5299
5706
  async function searchMessages(client, options = {}) {
5300
- const data = await client.rest.post(Routes24.searchMessages(), {
5707
+ const data = await client.rest.post(Routes25.searchMessages(), {
5301
5708
  body: toMessageSearchBody(options),
5302
5709
  auth: true
5303
5710
  });
5304
5711
  return toMessageSearchResponse(data);
5305
5712
  }
5713
+ function fetchEmojiSource(client, emojiId) {
5714
+ return client.rest.get(
5715
+ Routes25.emojiSource(emojiId),
5716
+ { auth: true }
5717
+ );
5718
+ }
5719
+ function fetchStickerSource(client, stickerId) {
5720
+ return client.rest.get(
5721
+ Routes25.stickerSource(stickerId),
5722
+ { auth: true }
5723
+ );
5724
+ }
5725
+ function fetchDiscoveryCategories(client) {
5726
+ return client.rest.get(
5727
+ Routes25.discoveryCategories(),
5728
+ { auth: true }
5729
+ );
5730
+ }
5731
+ function searchDiscoveryGuilds(client, options = {}) {
5732
+ const params = new URLSearchParams();
5733
+ if (options.query !== void 0) params.set("query", options.query);
5734
+ if (options.category !== void 0) params.set("category", String(options.category));
5735
+ if (options.language !== void 0) params.set("language", options.language);
5736
+ if (options.tag !== void 0) params.set("tag", options.tag);
5737
+ if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
5738
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5739
+ if (options.offset !== void 0) params.set("offset", String(options.offset));
5740
+ const qs2 = params.toString();
5741
+ return client.rest.get(
5742
+ qs2 ? `${Routes25.discoveryGuilds()}?${qs2}` : Routes25.discoveryGuilds(),
5743
+ { auth: true }
5744
+ );
5745
+ }
5746
+ function fetchExperiments(client) {
5747
+ return client.rest.get(Routes25.experiments(), {
5748
+ auth: true
5749
+ });
5750
+ }
5751
+ function refreshAttachmentUrls(client, attachmentUrls) {
5752
+ return client.rest.post(
5753
+ Routes25.attachmentsRefreshUrls(),
5754
+ { body: { attachment_urls: attachmentUrls }, auth: true }
5755
+ );
5756
+ }
5757
+ function fetchInstanceBadges(client, options = {}) {
5758
+ const params = new URLSearchParams();
5759
+ if (options.ids !== void 0) params.set("ids", options.ids);
5760
+ if (options.after !== void 0) params.set("after", options.after);
5761
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5762
+ if (options.version !== void 0) params.set("version", options.version);
5763
+ const qs2 = params.toString();
5764
+ return client.rest.get(
5765
+ qs2 ? `${Routes25.instanceBadges()}?${qs2}` : Routes25.instanceBadges(),
5766
+ { auth: false }
5767
+ );
5768
+ }
5769
+ function fetchChannelPostData(client, channelId, threadIds) {
5770
+ return client.rest.post(
5771
+ Routes25.channelPostData(channelId),
5772
+ { body: { thread_ids: threadIds }, auth: true }
5773
+ );
5774
+ }
5306
5775
 
5307
5776
  // src/ClientCore/ClientEvents.ts
5308
5777
  function createEventMethods(client) {
@@ -5321,18 +5790,19 @@ function createEventMethods(client) {
5321
5790
  import { GatewayCloseCodes, WebSocketManager } from "@fluxerjs/ws";
5322
5791
 
5323
5792
  // src/Domain/Guild/Guild.ts
5324
- import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
5793
+ import { Collection as Collection9, LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
5325
5794
  import { GuildNSFWLevel } from "@fluxerjs/types";
5326
- import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
5795
+ import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
5327
5796
 
5328
5797
  // src/ClientCore/GuildMemberManager.ts
5329
5798
  import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
5330
- import { Routes as Routes25 } from "@fluxerjs/types";
5799
+ import { Routes as Routes26 } from "@fluxerjs/types";
5331
5800
  var GuildMemberManager = class extends LimitedCollection2 {
5332
5801
  constructor(guild) {
5333
5802
  super({ maxSize: guild.client.cache.limits.members });
5334
5803
  this.guild = guild;
5335
5804
  }
5805
+ pendingFetches = /* @__PURE__ */ new Map();
5336
5806
  /**
5337
5807
  * Get a guild member from cache or fetch from the API if not present.
5338
5808
  * Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
@@ -5344,7 +5814,9 @@ var GuildMemberManager = class extends LimitedCollection2 {
5344
5814
  * console.log(member.displayName);
5345
5815
  */
5346
5816
  async resolve(userId) {
5347
- return this.get(userId) ?? this.fetch(userId);
5817
+ const id = normalizeSnowflakeId(userId, "members.resolve()");
5818
+ const cached = this.get(id);
5819
+ return cached && !cached.user.partial ? cached : this.fetch(id);
5348
5820
  }
5349
5821
  /**
5350
5822
  * The current bot user as a GuildMember in this guild.
@@ -5372,10 +5844,11 @@ var GuildMemberManager = class extends LimitedCollection2 {
5372
5844
  return this.guild.fetchMe();
5373
5845
  }
5374
5846
  async fetch(userIdOrOptions, options) {
5375
- if (typeof userIdOrOptions === "string") {
5376
- const cached = this.get(userIdOrOptions);
5377
- if (cached && !options?.force) return cached;
5378
- return this.guild.fetchMember(userIdOrOptions);
5847
+ if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
5848
+ const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
5849
+ const cached = this.get(id);
5850
+ if (cached && !cached.user.partial && !options?.force) return cached;
5851
+ return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
5379
5852
  }
5380
5853
  return this.fetchMany(userIdOrOptions);
5381
5854
  }
@@ -5384,10 +5857,14 @@ var GuildMemberManager = class extends LimitedCollection2 {
5384
5857
  if (options?.limit != null) params.set("limit", String(options.limit));
5385
5858
  if (options?.after) params.set("after", options.after);
5386
5859
  const qs2 = params.toString();
5387
- const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5388
- const data = await this.guild.client.rest.get(url, { auth: true });
5860
+ const url = Routes26.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5861
+ const data = assertApiArray(
5862
+ await this.guild.client.rest.get(url, { auth: true }),
5863
+ "members.fetch()"
5864
+ );
5389
5865
  const members = [];
5390
5866
  for (const m of data) {
5867
+ if (!m?.user?.id) continue;
5391
5868
  const member = new GuildMember(
5392
5869
  this.guild.client,
5393
5870
  { ...m, guild_id: this.guild.id },
@@ -5407,7 +5884,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
5407
5884
  */
5408
5885
  async search(options = {}) {
5409
5886
  const data = await this.guild.client.rest.post(
5410
- Routes25.guildMembersSearch(this.guild.id),
5887
+ Routes26.guildMembersSearch(this.guild.id),
5411
5888
  { body: toMemberSearchBody(options), auth: true }
5412
5889
  );
5413
5890
  const offset = options.offset ?? 0;
@@ -5433,7 +5910,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
5433
5910
  };
5434
5911
 
5435
5912
  // src/Domain/Guild/Admin.ts
5436
- import { Routes as Routes26 } from "@fluxerjs/types";
5913
+ import { Routes as Routes27 } from "@fluxerjs/types";
5437
5914
  function toAuditLogEntryPayload(entry, guildId) {
5438
5915
  return {
5439
5916
  id: entry.id,
@@ -5454,7 +5931,7 @@ function toVanityPayload(data) {
5454
5931
  return { code: data.code ?? null, uses: data.uses };
5455
5932
  }
5456
5933
  async function fetchAuditLogs(guild, options) {
5457
- const url = Routes26.guildAuditLogs(guild.id) + qs({
5934
+ const url = Routes27.guildAuditLogs(guild.id) + qs({
5458
5935
  limit: options?.limit,
5459
5936
  before: options?.before,
5460
5937
  after: options?.after,
@@ -5478,7 +5955,7 @@ async function fetchAuditLogs(guild, options) {
5478
5955
  };
5479
5956
  }
5480
5957
  async function editGuild(guild, options) {
5481
- const data = await guild.client.rest.patch(Routes26.guild(guild.id), {
5958
+ const data = await guild.client.rest.patch(Routes27.guild(guild.id), {
5482
5959
  body: toGuildEditBody(options),
5483
5960
  auth: true
5484
5961
  });
@@ -5486,13 +5963,13 @@ async function editGuild(guild, options) {
5486
5963
  return guild;
5487
5964
  }
5488
5965
  async function fetchVanityURL(guild) {
5489
- const data = await guild.client.rest.get(Routes26.guildVanityUrl(guild.id), {
5966
+ const data = await guild.client.rest.get(Routes27.guildVanityUrl(guild.id), {
5490
5967
  auth: true
5491
5968
  });
5492
5969
  return toVanityPayload(data);
5493
5970
  }
5494
5971
  async function editVanityURL(guild, code) {
5495
- const data = await guild.client.rest.patch(Routes26.guildVanityUrl(guild.id), {
5972
+ const data = await guild.client.rest.patch(Routes27.guildVanityUrl(guild.id), {
5496
5973
  body: { code },
5497
5974
  auth: true
5498
5975
  });
@@ -5500,14 +5977,14 @@ async function editVanityURL(guild, code) {
5500
5977
  return toVanityPayload(data);
5501
5978
  }
5502
5979
  async function fetchDiscoveryStatus(guild) {
5503
- const data = await guild.client.rest.get(Routes26.guildDiscovery(guild.id), {
5980
+ const data = await guild.client.rest.get(Routes27.guildDiscovery(guild.id), {
5504
5981
  auth: true
5505
5982
  });
5506
5983
  return toDiscoveryStatusPayload(data);
5507
5984
  }
5508
5985
  async function applyForDiscovery(guild, options) {
5509
5986
  const data = await guild.client.rest.post(
5510
- Routes26.guildDiscovery(guild.id),
5987
+ Routes27.guildDiscovery(guild.id),
5511
5988
  {
5512
5989
  body: toDiscoveryBody(options),
5513
5990
  auth: true
@@ -5517,7 +5994,7 @@ async function applyForDiscovery(guild, options) {
5517
5994
  }
5518
5995
  async function editDiscoveryApplication(guild, options) {
5519
5996
  const data = await guild.client.rest.patch(
5520
- Routes26.guildDiscovery(guild.id),
5997
+ Routes27.guildDiscovery(guild.id),
5521
5998
  {
5522
5999
  body: toDiscoveryBody(options),
5523
6000
  auth: true
@@ -5526,34 +6003,39 @@ async function editDiscoveryApplication(guild, options) {
5526
6003
  return toDiscoveryApplicationPayload(data);
5527
6004
  }
5528
6005
  async function withdrawDiscoveryApplication(guild) {
5529
- await guild.client.rest.delete(Routes26.guildDiscovery(guild.id), { auth: true });
6006
+ await guild.client.rest.delete(Routes27.guildDiscovery(guild.id), { auth: true });
5530
6007
  }
5531
6008
  async function deleteGuild(guild, options) {
5532
6009
  const body = options ? toSudoBody(options) : {};
5533
- await guild.client.rest.post(Routes26.guildDelete(guild.id), {
6010
+ await guild.client.rest.post(Routes27.guildDelete(guild.id), {
5534
6011
  body,
5535
6012
  auth: true
5536
6013
  });
5537
6014
  guild.client.guilds.delete(guild.id);
5538
6015
  }
5539
6016
  async function transferOwnership(guild, newOwnerId, password) {
5540
- await guild.client.rest.post(Routes26.guildTransferOwnership(guild.id), {
6017
+ await guild.client.rest.post(Routes27.guildTransferOwnership(guild.id), {
5541
6018
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
5542
6019
  auth: true
5543
6020
  });
5544
6021
  }
5545
6022
 
5546
6023
  // src/Domain/Guild/Channels.ts
5547
- import { Routes as Routes27 } from "@fluxerjs/types";
6024
+ import { Routes as Routes28 } from "@fluxerjs/types";
5548
6025
  async function createChannel(guild, options) {
5549
- const created = await guild.client.rest.post(Routes27.guildChannels(guild.id), {
6026
+ const created = await guild.client.rest.post(Routes28.guildChannels(guild.id), {
5550
6027
  body: toChannelCreateBody(options),
5551
6028
  auth: true
5552
6029
  });
5553
6030
  return cacheChannel(guild, created);
5554
6031
  }
5555
6032
  async function fetchChannels(guild) {
5556
- const data = await guild.client.rest.get(Routes27.guildChannels(guild.id));
6033
+ const raw = await guild.client.rest.get(Routes28.guildChannels(guild.id));
6034
+ if (!Array.isArray(raw))
6035
+ throw new TypeError(
6036
+ "guild.fetchChannels() received an invalid API payload (expected an array)"
6037
+ );
6038
+ const data = raw;
5557
6039
  const channels = [];
5558
6040
  for (const ch of data) {
5559
6041
  const channel = cacheChannel(guild, ch);
@@ -5562,17 +6044,17 @@ async function fetchChannels(guild) {
5562
6044
  return channels;
5563
6045
  }
5564
6046
  async function setChannelPositions(guild, updates) {
5565
- await guild.client.rest.patch(Routes27.guildChannels(guild.id), {
6047
+ await guild.client.rest.patch(Routes28.guildChannels(guild.id), {
5566
6048
  body: toChannelPositionBody(updates),
5567
6049
  auth: true
5568
6050
  });
5569
6051
  }
5570
6052
  async function fetchWebhooks(guild) {
5571
- const data = await guild.client.rest.get(Routes27.guildWebhooks(guild.id));
6053
+ const data = await guild.client.rest.get(Routes28.guildWebhooks(guild.id));
5572
6054
  return data.map((w) => new Webhook(guild.client, w));
5573
6055
  }
5574
6056
  async function fetchInvites(guild) {
5575
- const data = await guild.client.rest.get(Routes27.guildInvites(guild.id));
6057
+ const data = await guild.client.rest.get(Routes28.guildInvites(guild.id));
5576
6058
  return data.map((invite) => new Invite(guild.client, invite));
5577
6059
  }
5578
6060
  async function fetchInvite(guild, codeOrUrl) {
@@ -5592,14 +6074,14 @@ function resolveGuildOnlineCount(data) {
5592
6074
  }
5593
6075
 
5594
6076
  // src/Domain/Guild/Emojis.ts
5595
- import { Routes as Routes28 } from "@fluxerjs/types";
6077
+ import { Routes as Routes29 } from "@fluxerjs/types";
5596
6078
  async function fetchEmojis(guild) {
5597
- const data = await guild.client.rest.get(Routes28.guildEmojis(guild.id));
6079
+ const data = await guild.client.rest.get(Routes29.guildEmojis(guild.id));
5598
6080
  return data.map((e) => cacheEmoji(guild, e));
5599
6081
  }
5600
6082
  async function fetchEmoji(guild, emojiId) {
5601
6083
  try {
5602
- const data = await guild.client.rest.get(Routes28.guildEmoji(guild.id, emojiId));
6084
+ const data = await guild.client.rest.get(Routes29.guildEmoji(guild.id, emojiId));
5603
6085
  return cacheEmoji(guild, data);
5604
6086
  } catch (err) {
5605
6087
  rethrowMapped(err, {
@@ -5610,7 +6092,7 @@ async function fetchEmoji(guild, emojiId) {
5610
6092
  }
5611
6093
  async function createEmoji(guild, options) {
5612
6094
  const { reason, ...body } = options;
5613
- const data = await guild.client.rest.post(Routes28.guildEmojis(guild.id), {
6095
+ const data = await guild.client.rest.post(Routes29.guildEmojis(guild.id), {
5614
6096
  body,
5615
6097
  auth: true,
5616
6098
  ...auditReasonHeaders(reason)
@@ -5618,7 +6100,7 @@ async function createEmoji(guild, options) {
5618
6100
  return cacheEmoji(guild, data);
5619
6101
  }
5620
6102
  async function cloneEmoji(guild, sourceEmojiId) {
5621
- const data = await guild.client.rest.post(Routes28.guildEmojisClone(guild.id), {
6103
+ const data = await guild.client.rest.post(Routes29.guildEmojisClone(guild.id), {
5622
6104
  body: { source_emoji_id: sourceEmojiId },
5623
6105
  auth: true
5624
6106
  });
@@ -5626,7 +6108,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
5626
6108
  }
5627
6109
  async function createEmojisBulk(guild, emojis) {
5628
6110
  const data = await guild.client.rest.post(
5629
- Routes28.guildEmojisBulk(guild.id),
6111
+ Routes29.guildEmojisBulk(guild.id),
5630
6112
  { body: { emojis }, auth: true }
5631
6113
  );
5632
6114
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
@@ -5646,18 +6128,22 @@ var GuildRoleManager = class extends LimitedCollection3 {
5646
6128
  };
5647
6129
 
5648
6130
  // src/Domain/Guild/MemberHttp.ts
5649
- import { Routes as Routes29 } from "@fluxerjs/types";
6131
+ import { Routes as Routes30 } from "@fluxerjs/types";
5650
6132
  async function fetchMember(guild, userId) {
6133
+ const id = normalizeSnowflakeId(userId, "members.fetch()");
5651
6134
  try {
5652
6135
  const data = await guild.client.rest.get(
5653
- Routes29.guildMember(guild.id, userId)
6136
+ Routes30.guildMember(guild.id, id)
5654
6137
  );
6138
+ if (!data?.user?.id) {
6139
+ throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
6140
+ }
5655
6141
  return cacheMember(guild, data);
5656
6142
  } catch (err) {
5657
6143
  rethrowMapped(err, {
5658
6144
  notFound: {
5659
6145
  code: ErrorCodes.MemberNotFound,
5660
- message: `Member ${userId} not found in guild`
6146
+ message: `Member ${id} not found in guild`
5661
6147
  },
5662
6148
  fallback: "Failed to fetch guild member"
5663
6149
  });
@@ -5665,17 +6151,20 @@ async function fetchMember(guild, userId) {
5665
6151
  }
5666
6152
  async function fetchMe(guild) {
5667
6153
  const data = await guild.client.rest.get(
5668
- Routes29.guildMemberMe(guild.id),
6154
+ Routes30.guildMemberMe(guild.id),
5669
6155
  { auth: true }
5670
6156
  );
6157
+ if (!data?.user?.id) {
6158
+ throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
6159
+ }
5671
6160
  return cacheMember(guild, data);
5672
6161
  }
5673
6162
 
5674
6163
  // src/Domain/Guild/Moderation.ts
5675
- import { Routes as Routes31 } from "@fluxerjs/types";
6164
+ import { Routes as Routes32 } from "@fluxerjs/types";
5676
6165
 
5677
6166
  // src/Domain/Guild/GuildBan.ts
5678
- import { Routes as Routes30 } from "@fluxerjs/types";
6167
+ import { Routes as Routes31 } from "@fluxerjs/types";
5679
6168
  function parseOptionalDate2(value) {
5680
6169
  if (value == null || value === "") return null;
5681
6170
  const date = new Date(value);
@@ -5702,7 +6191,7 @@ var GuildBan = class extends Base {
5702
6191
  * Requires Ban Members permission.
5703
6192
  */
5704
6193
  async unban(reason) {
5705
- await this.client.rest.delete(Routes30.guildBan(this.guildId, this.user.id), {
6194
+ await this.client.rest.delete(Routes31.guildBan(this.guildId, this.user.id), {
5706
6195
  auth: true,
5707
6196
  ...auditReasonHeaders(reason)
5708
6197
  });
@@ -5712,35 +6201,39 @@ var GuildBan = class extends Base {
5712
6201
  // src/Domain/Guild/Moderation.ts
5713
6202
  async function ban(guild, userId, options) {
5714
6203
  const body = options ? toGuildBanBody(options) : {};
5715
- await guild.client.rest.put(Routes31.guildBan(guild.id, userId), {
6204
+ await guild.client.rest.put(Routes32.guildBan(guild.id, userId), {
5716
6205
  body: Object.keys(body).length ? body : void 0,
5717
6206
  auth: true,
5718
6207
  ...auditReasonHeaders(options?.reason)
5719
6208
  });
5720
6209
  }
6210
+ async function fetchBan(guild, userId) {
6211
+ const data = await guild.client.rest.get(Routes32.guildBan(guild.id, userId));
6212
+ return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
6213
+ }
5721
6214
  async function fetchBans(guild) {
5722
- const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
6215
+ const data = await guild.client.rest.get(Routes32.guildBans(guild.id));
5723
6216
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
5724
6217
  }
5725
6218
  async function unban(guild, userId, reason) {
5726
- await guild.client.rest.delete(Routes31.guildBan(guild.id, userId), {
6219
+ await guild.client.rest.delete(Routes32.guildBan(guild.id, userId), {
5727
6220
  auth: true,
5728
6221
  ...auditReasonHeaders(reason)
5729
6222
  });
5730
6223
  }
5731
6224
  async function kick(guild, userId, reason) {
5732
- await guild.client.rest.delete(Routes31.guildMember(guild.id, userId), {
6225
+ await guild.client.rest.delete(Routes32.guildMember(guild.id, userId), {
5733
6226
  auth: true,
5734
6227
  ...auditReasonHeaders(reason)
5735
6228
  });
5736
6229
  }
5737
6230
 
5738
6231
  // src/Domain/Guild/Roles.ts
5739
- import { Routes as Routes32 } from "@fluxerjs/types";
6232
+ import { Routes as Routes33 } from "@fluxerjs/types";
5740
6233
  import { parseRoleMention } from "@fluxerjs/util";
5741
6234
  async function createRole(guild, options = {}) {
5742
6235
  const body = toRoleCreateBody(options);
5743
- const data = await guild.client.rest.post(Routes32.guildRoles(guild.id), {
6236
+ const data = await guild.client.rest.post(Routes33.guildRoles(guild.id), {
5744
6237
  body: Object.keys(body).length ? body : void 0,
5745
6238
  auth: true,
5746
6239
  ...auditReasonHeaders(options.reason)
@@ -5748,12 +6241,14 @@ async function createRole(guild, options = {}) {
5748
6241
  return cacheRole(guild, data);
5749
6242
  }
5750
6243
  async function fetchRoles(guild) {
5751
- const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
6244
+ const data = await guild.client.rest.get(Routes33.guildRoles(guild.id));
6245
+ if (!Array.isArray(data))
6246
+ throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
5752
6247
  return data.map((r) => cacheRole(guild, r));
5753
6248
  }
5754
6249
  async function fetchRole(guild, roleId2) {
5755
6250
  try {
5756
- const data = await guild.client.rest.get(Routes32.guildRole(guild.id, roleId2));
6251
+ const data = await guild.client.rest.get(Routes33.guildRole(guild.id, roleId2));
5757
6252
  return cacheRole(guild, data);
5758
6253
  } catch (err) {
5759
6254
  rethrowMapped(err, {
@@ -5770,7 +6265,7 @@ async function resolveRoleId(guild, arg) {
5770
6265
  const needle = trimmed.toLowerCase();
5771
6266
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
5772
6267
  if (cached) return cached.id;
5773
- const roles = await guild.client.rest.get(Routes32.guildRoles(guild.id));
6268
+ const roles = await guild.client.rest.get(Routes33.guildRoles(guild.id));
5774
6269
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
5775
6270
  if (!role) return null;
5776
6271
  cacheRole(guild, role);
@@ -5779,7 +6274,7 @@ async function resolveRoleId(guild, arg) {
5779
6274
  async function setRolePositions(guild, updates) {
5780
6275
  return replaceRoles(
5781
6276
  guild,
5782
- await guild.client.rest.patch(Routes32.guildRoles(guild.id), {
6277
+ await guild.client.rest.patch(Routes33.guildRoles(guild.id), {
5783
6278
  body: updates,
5784
6279
  auth: true
5785
6280
  })
@@ -5788,7 +6283,7 @@ async function setRolePositions(guild, updates) {
5788
6283
  async function setRoleHoistPositions(guild, updates) {
5789
6284
  return replaceRoles(
5790
6285
  guild,
5791
- await guild.client.rest.patch(Routes32.guildRolesHoistPositions(guild.id), {
6286
+ await guild.client.rest.patch(Routes33.guildRolesHoistPositions(guild.id), {
5792
6287
  body: updates.map((u) => ({
5793
6288
  id: u.id,
5794
6289
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -5800,17 +6295,17 @@ async function setRoleHoistPositions(guild, updates) {
5800
6295
  async function resetRoleHoistPositions(guild) {
5801
6296
  return replaceRoles(
5802
6297
  guild,
5803
- await guild.client.rest.delete(Routes32.guildRolesHoistPositions(guild.id), {
6298
+ await guild.client.rest.delete(Routes33.guildRolesHoistPositions(guild.id), {
5804
6299
  auth: true
5805
6300
  })
5806
6301
  );
5807
6302
  }
5808
6303
 
5809
6304
  // src/Domain/Guild/Stickers.ts
5810
- import { Routes as Routes33 } from "@fluxerjs/types";
6305
+ import { Routes as Routes34 } from "@fluxerjs/types";
5811
6306
  async function createSticker(guild, options) {
5812
6307
  const { reason, ...body } = options;
5813
- const data = await guild.client.rest.post(Routes33.guildStickers(guild.id), {
6308
+ const data = await guild.client.rest.post(Routes34.guildStickers(guild.id), {
5814
6309
  body,
5815
6310
  auth: true,
5816
6311
  ...auditReasonHeaders(reason)
@@ -5818,7 +6313,7 @@ async function createSticker(guild, options) {
5818
6313
  return cacheSticker(guild, data);
5819
6314
  }
5820
6315
  async function cloneSticker(guild, sourceStickerId) {
5821
- const data = await guild.client.rest.post(Routes33.guildStickersClone(guild.id), {
6316
+ const data = await guild.client.rest.post(Routes34.guildStickersClone(guild.id), {
5822
6317
  body: { source_sticker_id: sourceStickerId },
5823
6318
  auth: true
5824
6319
  });
@@ -5826,17 +6321,17 @@ async function cloneSticker(guild, sourceStickerId) {
5826
6321
  }
5827
6322
  async function createStickersBulk(guild, stickers) {
5828
6323
  const data = await guild.client.rest.post(
5829
- Routes33.guildStickersBulk(guild.id),
6324
+ Routes34.guildStickersBulk(guild.id),
5830
6325
  { body: { stickers }, auth: true }
5831
6326
  );
5832
6327
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
5833
6328
  }
5834
6329
  async function fetchStickers(guild) {
5835
- const data = await guild.client.rest.get(Routes33.guildStickers(guild.id));
6330
+ const data = await guild.client.rest.get(Routes34.guildStickers(guild.id));
5836
6331
  return data.map((s) => cacheSticker(guild, s));
5837
6332
  }
5838
6333
  async function fetchSticker(guild, stickerId) {
5839
- const data = await guild.client.rest.get(Routes33.guildSticker(guild.id, stickerId));
6334
+ const data = await guild.client.rest.get(Routes34.guildSticker(guild.id, stickerId));
5840
6335
  return cacheSticker(guild, data);
5841
6336
  }
5842
6337
 
@@ -5848,6 +6343,11 @@ var Guild = class extends Base {
5848
6343
  id;
5849
6344
  /** Whether the guild is currently available through the gateway. */
5850
6345
  available = true;
6346
+ /**
6347
+ * True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
6348
+ * and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
6349
+ */
6350
+ partial = true;
5851
6351
  /** Guild name. */
5852
6352
  name;
5853
6353
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -5920,6 +6420,10 @@ var Guild = class extends Base {
5920
6420
  emojis;
5921
6421
  /** Cached stickers in this guild. */
5922
6422
  stickers;
6423
+ /** Live stages in this guild's stage channels, keyed by stage instance ID. */
6424
+ stageInstances;
6425
+ /** Most participants a stage can have while speakers use video, or null if unknown. */
6426
+ maxStageVideoChannelUsers;
5923
6427
  /**
5924
6428
  * Construct a guild from API data.
5925
6429
  * @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE
@@ -5936,6 +6440,7 @@ var Guild = class extends Base {
5936
6440
  this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
5937
6441
  this.emojis = new LimitedCollection4({ maxSize: client.cache.limits.emojis });
5938
6442
  this.stickers = new LimitedCollection4({ maxSize: client.cache.limits.stickers });
6443
+ this.stageInstances = new Collection9();
5939
6444
  this.name = data.name ?? "";
5940
6445
  this.icon = data.icon ?? null;
5941
6446
  this.banner = data.banner ?? null;
@@ -5965,6 +6470,7 @@ var Guild = class extends Base {
5965
6470
  this.bannerHeight = data.banner_height ?? null;
5966
6471
  this.splashWidth = data.splash_width ?? null;
5967
6472
  this.splashHeight = data.splash_height ?? null;
6473
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
5968
6474
  this.memberCount = resolveGuildMemberCount(data) ?? null;
5969
6475
  this.onlineCount = resolveGuildOnlineCount(data) ?? null;
5970
6476
  for (const r of data.roles ?? []) {
@@ -6021,6 +6527,9 @@ var Guild = class extends Base {
6021
6527
  if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
6022
6528
  if (data.splash_width !== void 0) this.splashWidth = data.splash_width ?? null;
6023
6529
  if (data.splash_height !== void 0) this.splashHeight = data.splash_height ?? null;
6530
+ if (data.max_stage_video_channel_users !== void 0) {
6531
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
6532
+ }
6024
6533
  const memberCount = resolveGuildMemberCount(data);
6025
6534
  if (memberCount !== void 0) this.memberCount = memberCount;
6026
6535
  const onlineCount = resolveGuildOnlineCount(data);
@@ -6036,11 +6545,11 @@ var Guild = class extends Base {
6036
6545
  }
6037
6546
  /** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
6038
6547
  get createdTimestamp() {
6039
- return SnowflakeUtil9.timestampFromSnowflake(this.id);
6548
+ return SnowflakeUtil10.timestampFromSnowflake(this.id);
6040
6549
  }
6041
6550
  /** Date when this guild was created, derived from its snowflake ID. */
6042
6551
  get createdAt() {
6043
- return SnowflakeUtil9.dateFromSnowflake(this.id);
6552
+ return SnowflakeUtil10.dateFromSnowflake(this.id);
6044
6553
  }
6045
6554
  /** The guild's name. */
6046
6555
  toString() {
@@ -6142,6 +6651,10 @@ var Guild = class extends Base {
6142
6651
  ban(userId, options) {
6143
6652
  return ban(this, userId, options);
6144
6653
  }
6654
+ /** Fetch a single ban by user ID. Requires Ban Members. */
6655
+ fetchBan(userId) {
6656
+ return fetchBan(this, userId);
6657
+ }
6145
6658
  /** Fetch all bans in this guild. Requires Ban Members. */
6146
6659
  fetchBans() {
6147
6660
  return fetchBans(this);
@@ -6322,6 +6835,9 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
6322
6835
  if (resources.members !== void 0) mergeMembers(guild, resources.members);
6323
6836
  if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
6324
6837
  if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
6838
+ if (resources.stageInstances !== void 0) syncStageInstances(guild, resources.stageInstances);
6839
+ if (resources.stageCounts !== void 0) applyStageCounts(guild, resources.stageCounts);
6840
+ if (resources.channels !== void 0) guild.partial = false;
6325
6841
  return { guild, created, recovered };
6326
6842
  }
6327
6843
  function applyGuildSnapshotFromGateway(client, raw) {
@@ -6335,7 +6851,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
6335
6851
  emojis: g.emojis,
6336
6852
  stickers: g.stickers,
6337
6853
  // A channel list without `threads` means this session has no viewable threads.
6338
- threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
6854
+ threads: g.channels !== void 0 ? g.threads ?? [] : g.threads,
6855
+ stageInstances: g.stage_instances,
6856
+ stageCounts: g.stage_counts
6339
6857
  });
6340
6858
  if (g.voice_states?.length) {
6341
6859
  client.emit(Events.VoiceStatesSync, {
@@ -6347,7 +6865,7 @@ function applyGuildSnapshotFromGateway(client, raw) {
6347
6865
  }
6348
6866
 
6349
6867
  // src/ClientCore/ClientUser.ts
6350
- import { GatewayOpcodes, Routes as Routes34 } from "@fluxerjs/types";
6868
+ import { GatewayOpcodes, Routes as Routes35 } from "@fluxerjs/types";
6351
6869
  var ClientUser = class extends User {
6352
6870
  /** Broadcast presence (gateway opcode 3) on all shards. */
6353
6871
  setPresence(presence) {
@@ -6357,13 +6875,13 @@ var ClientUser = class extends User {
6357
6875
  }
6358
6876
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
6359
6877
  async fetch() {
6360
- const data = await this.client.rest.get(Routes34.currentUser(), { auth: true });
6878
+ const data = await this.client.rest.get(Routes35.currentUser(), { auth: true });
6361
6879
  this._patch(data);
6362
6880
  return this;
6363
6881
  }
6364
6882
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
6365
6883
  async fetchGuilds(options) {
6366
- const path = Routes34.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6884
+ const path = Routes35.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6367
6885
  const data = await this.client.rest.get(path, { auth: true });
6368
6886
  return data.map((g) => ({
6369
6887
  id: g.id,
@@ -6387,7 +6905,7 @@ var ClientUser = class extends User {
6387
6905
  */
6388
6906
  async leaveGuild(guildId, options) {
6389
6907
  const body = options ? toSudoBody(options) : void 0;
6390
- await this.client.rest.delete(Routes34.leaveGuild(guildId), {
6908
+ await this.client.rest.delete(Routes35.leaveGuild(guildId), {
6391
6909
  body: body && Object.keys(body).length ? body : void 0,
6392
6910
  auth: true
6393
6911
  });
@@ -6395,7 +6913,7 @@ var ClientUser = class extends User {
6395
6913
  /** Delete every message authored by the caller across a guild (sudo). */
6396
6914
  async bulkDeleteMyMessagesInGuild(guildId, options) {
6397
6915
  const body = options ? toSudoBody(options) : void 0;
6398
- await this.client.rest.post(Routes34.guildBulkDeleteMine(guildId), {
6916
+ await this.client.rest.post(Routes35.guildBulkDeleteMine(guildId), {
6399
6917
  body: body && Object.keys(body).length ? body : void 0,
6400
6918
  auth: true
6401
6919
  });
@@ -6405,15 +6923,7 @@ var ClientUser = class extends User {
6405
6923
  // src/ClientCore/EventHandlers/Helpers.ts
6406
6924
  import { asRecord, num, str } from "@fluxerjs/util";
6407
6925
  function unknownUser(id) {
6408
- return {
6409
- id,
6410
- username: "Unknown",
6411
- discriminator: "0",
6412
- global_name: null,
6413
- avatar: null,
6414
- avatar_color: null,
6415
- flags: 0
6416
- };
6926
+ return { id };
6417
6927
  }
6418
6928
  function indexMember(_client, guild, data) {
6419
6929
  if (!data.user?.id) return null;
@@ -6875,7 +7385,7 @@ var memberHandlers = {
6875
7385
  };
6876
7386
 
6877
7387
  // src/ClientCore/EventHandlers/Messages.ts
6878
- import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
7388
+ import { SnowflakeUtil as SnowflakeUtil11 } from "@fluxerjs/util";
6879
7389
  function cachedTextChannel(client, channelId) {
6880
7390
  const channel = client.channels.get(channelId);
6881
7391
  return channel?.isTextBased() ? channel : null;
@@ -6891,7 +7401,7 @@ function toPartialMessage(client, args) {
6891
7401
  const cached = args.cached;
6892
7402
  const authorId = args.authorId ?? cached?.author?.id ?? null;
6893
7403
  const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
6894
- const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil10.isValid(args.id) ? SnowflakeUtil10.dateFromSnowflake(args.id) : null;
7404
+ const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil11.isValid(args.id) ? SnowflakeUtil11.dateFromSnowflake(args.id) : null;
6895
7405
  return new PartialMessage(client, {
6896
7406
  id: args.id,
6897
7407
  channelId: args.channelId,
@@ -7097,6 +7607,9 @@ var passthroughHandlers = {
7097
7607
  VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
7098
7608
  VOICE_STATE_ACK: pass(Events.VoiceStateAck),
7099
7609
  ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
7610
+ VOICE_SIGNAL: pass(Events.VoiceSignal),
7611
+ GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
7612
+ OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
7100
7613
  TYPING_START(client, d) {
7101
7614
  const data = d;
7102
7615
  const payload = {
@@ -7152,6 +7665,46 @@ var passthroughHandlers = {
7152
7665
  WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
7153
7666
  };
7154
7667
 
7668
+ // src/ClientCore/EventHandlers/Stages.ts
7669
+ var stageHandlers = {
7670
+ STAGE_INSTANCE_CREATE(client, d) {
7671
+ const instance = cacheStageInstance(client, d);
7672
+ client.emit(Events.StageInstanceCreate, instance);
7673
+ },
7674
+ STAGE_INSTANCE_UPDATE(client, d) {
7675
+ const data = d;
7676
+ const cached = client.guilds.get(data.guild_id)?.stageInstances.get(data.id);
7677
+ const old = cached ? new StageInstance(client, cached.toJSON()) : null;
7678
+ const instance = cacheStageInstance(client, data);
7679
+ client.emit(Events.StageInstanceUpdate, old, instance);
7680
+ },
7681
+ STAGE_INSTANCE_DELETE(client, d) {
7682
+ const data = d;
7683
+ const guild = client.guilds.get(data.guild_id);
7684
+ const instance = guild?.stageInstances.get(data.id) ?? new StageInstance(client, data);
7685
+ instance._patch(data);
7686
+ guild?.stageInstances.delete(data.id);
7687
+ client.emit(Events.StageInstanceDelete, instance);
7688
+ },
7689
+ STAGE_COUNTS_UPDATE(client, d) {
7690
+ const data = d;
7691
+ const channel = client.channels.get(data.channel_id);
7692
+ if (channel?.isStage()) channel._patchCounts(data);
7693
+ const payload = {
7694
+ guildId: data.guild_id,
7695
+ channelId: data.channel_id,
7696
+ listenerCount: data.listener_count,
7697
+ speakerCount: data.speaker_count,
7698
+ requestCount: data.request_count,
7699
+ videoEnabled: data.video_enabled ?? null
7700
+ };
7701
+ client.emit(Events.StageCountsUpdate, payload);
7702
+ },
7703
+ STAGE_VOICE_STATES_SYNC: pass(Events.StageVoiceStatesSync),
7704
+ STAGE_AUDIENCE_LIST_UPDATE: pass(Events.StageAudienceListUpdate),
7705
+ VOICE_JOIN_QUEUED: pass(Events.VoiceJoinQueued)
7706
+ };
7707
+
7155
7708
  // src/ClientCore/EventHandlers/Threads.ts
7156
7709
  function cachedChannel(client, id) {
7157
7710
  const direct = client.channels.get(id);
@@ -7262,7 +7815,8 @@ var eventHandlers = buildRegistry(
7262
7815
  inviteHandlers,
7263
7816
  guildResourceHandlers,
7264
7817
  passthroughHandlers,
7265
- threadHandlers
7818
+ threadHandlers,
7819
+ stageHandlers
7266
7820
  );
7267
7821
 
7268
7822
  // src/ClientCore/GatewayDispatch.ts
@@ -7287,29 +7841,63 @@ function handleGatewayDispatch(client, payload, deferred) {
7287
7841
  }
7288
7842
  return dispatchGatewayPayload(client, payload);
7289
7843
  }
7290
- function dispatchGatewayPayload(client, payload) {
7844
+ var dispatchQueues = /* @__PURE__ */ new WeakMap();
7845
+ function queueFor(client) {
7846
+ let queue = dispatchQueues.get(client);
7847
+ if (!queue) {
7848
+ queue = { tail: Promise.resolve(), pending: 0 };
7849
+ dispatchQueues.set(client, queue);
7850
+ }
7851
+ return queue;
7852
+ }
7853
+ async function runGatewayHandler(client, payload) {
7291
7854
  const event = payload.t;
7292
- if (!event) return Promise.resolve();
7855
+ if (!event) return;
7293
7856
  const handler = eventHandlers.get(event);
7294
7857
  if (!handler) {
7295
7858
  client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
7296
- return Promise.resolve();
7859
+ return;
7297
7860
  }
7298
- const run = async () => {
7299
- try {
7300
- await handler(client, payload.d);
7301
- } catch (err) {
7302
- emitClientError(client, err);
7303
- }
7304
- };
7305
- if (client.options.gatewayDeferHandlers === false) return run();
7306
- return new Promise((resolve, reject) => {
7307
- const start = () => {
7308
- void run().then(resolve).catch(reject);
7309
- };
7310
- if (typeof setImmediate === "function") setImmediate(start);
7311
- else setTimeout(start, 0);
7861
+ if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
7862
+ client.emit(
7863
+ Events.Debug,
7864
+ `[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
7865
+ );
7866
+ return;
7867
+ }
7868
+ if (client.options.gatewayDeferHandlers !== false) {
7869
+ await new Promise((resolve) => {
7870
+ if (typeof setImmediate === "function") setImmediate(resolve);
7871
+ else setTimeout(resolve, 0);
7872
+ });
7873
+ }
7874
+ try {
7875
+ await handler(client, payload.d);
7876
+ } catch (err) {
7877
+ emitClientError(client, err);
7878
+ }
7879
+ }
7880
+ function dispatchGatewayPayload(client, payload) {
7881
+ const queue = queueFor(client);
7882
+ if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
7883
+ queue.pending++;
7884
+ const run = runGatewayHandler(client, payload).finally(() => {
7885
+ queue.pending--;
7886
+ });
7887
+ queue.tail = run.catch(() => {
7888
+ });
7889
+ return run;
7890
+ }
7891
+ queue.pending++;
7892
+ const next = queue.tail.then(
7893
+ () => runGatewayHandler(client, payload),
7894
+ () => runGatewayHandler(client, payload)
7895
+ ).finally(() => {
7896
+ queue.pending--;
7897
+ });
7898
+ queue.tail = next.catch(() => {
7312
7899
  });
7900
+ return next;
7313
7901
  }
7314
7902
  async function flushDeferredGatewayDispatches(client, deferred) {
7315
7903
  while (deferred.length > 0) {
@@ -7488,7 +8076,7 @@ async function connectClientGateway(client, token, signal) {
7488
8076
 
7489
8077
  // src/ClientCore/GuildManager.ts
7490
8078
  import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
7491
- import { Routes as Routes35 } from "@fluxerjs/types";
8079
+ import { Routes as Routes36 } from "@fluxerjs/types";
7492
8080
  var GuildManager = class extends LimitedCollection5 {
7493
8081
  constructor(client) {
7494
8082
  super({
@@ -7497,6 +8085,7 @@ var GuildManager = class extends LimitedCollection5 {
7497
8085
  });
7498
8086
  this.client = client;
7499
8087
  }
8088
+ pendingFetches = /* @__PURE__ */ new Map();
7500
8089
  /**
7501
8090
  * Remove a guild from cache and cascade its channels / message caches.
7502
8091
  * Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
@@ -7511,35 +8100,73 @@ var GuildManager = class extends LimitedCollection5 {
7511
8100
  }
7512
8101
  /**
7513
8102
  * Get a guild from cache or fetch from the API if not present.
8103
+ * Partial (metadata-only) cached guilds are hydrated first.
7514
8104
  * @param guildId - Snowflake of the guild
7515
8105
  * @returns The guild
7516
8106
  * @throws FluxerError with GUILD_NOT_FOUND if missing
7517
8107
  */
7518
8108
  async resolve(guildId) {
7519
- return this.get(guildId) ?? this.fetch(guildId);
8109
+ const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
8110
+ const cached = this.get(id);
8111
+ if (cached && !cached.partial) return cached;
8112
+ if (cached) {
8113
+ await dedupeFetch(this.pendingFetches, id, async () => {
8114
+ await this.hydrate(cached);
8115
+ return cached;
8116
+ });
8117
+ return cached;
8118
+ }
8119
+ const guild = await this.fetch(id);
8120
+ await dedupeFetch(this.pendingFetches, id, async () => {
8121
+ await this.hydrate(guild);
8122
+ return guild;
8123
+ });
8124
+ return guild;
7520
8125
  }
7521
8126
  /**
7522
8127
  * Fetch a guild by ID.
7523
- * Returns the cached guild unless `force` is set, in which case REST metadata is applied via `_patch`.
8128
+ * Returns the cached guild unless `force` is set, in which case REST metadata
8129
+ * is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
7524
8130
  * @throws FluxerError with GUILD_NOT_FOUND if missing
7525
8131
  */
7526
8132
  async fetch(guildId, options) {
7527
- const cached = this.get(guildId);
8133
+ const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
8134
+ const cached = this.get(id);
7528
8135
  if (cached && !options?.force) return cached;
7529
- try {
7530
- const data = await this.client.rest.get(Routes35.guild(guildId));
7531
- if (cached) {
7532
- cached._patch(data);
7533
- return cached;
8136
+ return dedupeFetch(this.pendingFetches, id, async () => {
8137
+ try {
8138
+ const data = assertApiObjectWithId(
8139
+ await this.client.rest.get(Routes36.guild(id)),
8140
+ "guilds.fetch()"
8141
+ );
8142
+ let guild;
8143
+ const existing = this.get(id);
8144
+ if (existing) {
8145
+ existing._patch(data);
8146
+ guild = existing;
8147
+ } else {
8148
+ guild = new Guild(this.client, data);
8149
+ this.set(guild.id, guild);
8150
+ }
8151
+ return guild;
8152
+ } catch (err) {
8153
+ rethrowMapped(err, {
8154
+ notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
8155
+ fallback: `Failed to fetch guild ${id}`
8156
+ });
7534
8157
  }
7535
- const guild = new Guild(this.client, data);
7536
- this.set(guild.id, guild);
7537
- return guild;
8158
+ });
8159
+ }
8160
+ /** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
8161
+ async hydrate(guild) {
8162
+ try {
8163
+ await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
8164
+ guild.partial = false;
7538
8165
  } catch (err) {
7539
- rethrowMapped(err, {
7540
- notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${guildId} not found` },
7541
- fallback: `Failed to fetch guild ${guildId}`
7542
- });
8166
+ this.client.emit(
8167
+ Events.Debug,
8168
+ `[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
8169
+ );
7543
8170
  }
7544
8171
  }
7545
8172
  };
@@ -7564,6 +8191,10 @@ var MessageCache = class {
7564
8191
  if (limit === false) return;
7565
8192
  if (!this.caches) this.caches = /* @__PURE__ */ new Map();
7566
8193
  let cache = this.caches.get(channelId);
8194
+ if (cache) {
8195
+ this.caches.delete(channelId);
8196
+ this.caches.set(channelId, cache);
8197
+ }
7567
8198
  if (!cache) {
7568
8199
  const channelLimit = this.getChannelLimit();
7569
8200
  if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
@@ -7615,7 +8246,7 @@ var MessageCache = class {
7615
8246
  // src/ClientCore/UserManager.ts
7616
8247
  import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
7617
8248
  import {
7618
- Routes as Routes36
8249
+ Routes as Routes37
7619
8250
  } from "@fluxerjs/types";
7620
8251
  var soft = (p) => p.catch(() => null);
7621
8252
  var UserManager = class extends LimitedCollection6 {
@@ -7623,6 +8254,7 @@ var UserManager = class extends LimitedCollection6 {
7623
8254
  super({ maxSize: client.cache.limits.users });
7624
8255
  this.client = client;
7625
8256
  }
8257
+ pendingFetches = /* @__PURE__ */ new Map();
7626
8258
  /** Remove matching users (skips `client.user`). Returns count removed. */
7627
8259
  sweep(filter) {
7628
8260
  let removed = 0;
@@ -7636,16 +8268,30 @@ var UserManager = class extends LimitedCollection6 {
7636
8268
  }
7637
8269
  return removed;
7638
8270
  }
7639
- /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
8271
+ /**
8272
+ * Fetch a user by ID and update cache. Returns the cached user unless `force` is set
8273
+ * or the cached entry is only a partial stub (e.g. from a reaction event).
8274
+ */
7640
8275
  async fetch(userId, options) {
7641
- const cached = this.get(userId);
7642
- if (cached && !options?.force) return cached;
7643
- const data = await this.client.rest.get(Routes36.user(userId));
7644
- return this.client.getOrCreateUser(data);
8276
+ const id = normalizeSnowflakeId(userId, "users.fetch()");
8277
+ const cached = this.get(id);
8278
+ if (cached && !cached.partial && !options?.force) return cached;
8279
+ return dedupeFetch(
8280
+ this.pendingFetches,
8281
+ id,
8282
+ async () => this.client.getOrCreateUser(
8283
+ assertApiObjectWithId(
8284
+ await this.client.rest.get(Routes37.user(id)),
8285
+ "users.fetch()"
8286
+ )
8287
+ )
8288
+ );
7645
8289
  }
7646
- /** Return a cached user, otherwise {@link fetch}. */
8290
+ /** Return a cached (non-partial) user, otherwise {@link fetch}. */
7647
8291
  async resolve(userId) {
7648
- return this.get(userId) ?? this.fetch(userId);
8292
+ const id = normalizeSnowflakeId(userId, "users.resolve()");
8293
+ const cached = this.get(id);
8294
+ return cached && !cached.partial ? cached : this.fetch(id);
7649
8295
  }
7650
8296
  /**
7651
8297
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
@@ -7658,10 +8304,10 @@ var UserManager = class extends LimitedCollection6 {
7658
8304
  async fetchWithProfile(userId, options) {
7659
8305
  const guildId = options?.guildId ?? void 0;
7660
8306
  const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
7661
- this.client.rest.get(Routes36.user(userId)),
7662
- soft(this.client.rest.get(Routes36.userProfile(userId))),
7663
- guildId ? soft(this.client.rest.get(Routes36.userProfile(userId, guildId))) : null,
7664
- guildId ? soft(this.client.rest.get(Routes36.guildMember(guildId, userId))) : null
8307
+ this.client.rest.get(Routes37.user(userId)),
8308
+ soft(this.client.rest.get(Routes37.userProfile(userId))),
8309
+ guildId ? soft(this.client.rest.get(Routes37.userProfile(userId, guildId))) : null,
8310
+ guildId ? soft(this.client.rest.get(Routes37.guildMember(guildId, userId))) : null
7665
8311
  ]);
7666
8312
  const user = this.client.getOrCreateUser(userData);
7667
8313
  let member = null;
@@ -7786,7 +8432,7 @@ var Client = class _Client extends EventEmitter3 {
7786
8432
  * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
7787
8433
  * Does not log in. Call {@link login} with a token afterward.
7788
8434
  *
7789
- * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
8435
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
7790
8436
  * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
7791
8437
  * @param connectOptions - Optional abort signal for the discovery request
7792
8438
  */
@@ -7863,6 +8509,38 @@ var Client = class _Client extends EventEmitter3 {
7863
8509
  fetchStickerMetadata(stickerId) {
7864
8510
  return fetchStickerMetadata(this, stickerId);
7865
8511
  }
8512
+ /** Fetch the source guild of a custom emoji. */
8513
+ fetchEmojiSource(emojiId) {
8514
+ return fetchEmojiSource(this, emojiId);
8515
+ }
8516
+ /** Fetch the source guild of a custom sticker. */
8517
+ fetchStickerSource(stickerId) {
8518
+ return fetchStickerSource(this, stickerId);
8519
+ }
8520
+ /** List discovery categories. */
8521
+ fetchDiscoveryCategories() {
8522
+ return fetchDiscoveryCategories(this);
8523
+ }
8524
+ /** Search discoverable guilds. */
8525
+ searchDiscoveryGuilds(options) {
8526
+ return searchDiscoveryGuilds(this, options);
8527
+ }
8528
+ /** Fetch experiment assignments for this account. */
8529
+ fetchExperiments() {
8530
+ return fetchExperiments(this);
8531
+ }
8532
+ /** Refresh expiring attachment CDN URLs. */
8533
+ refreshAttachmentUrls(attachmentUrls) {
8534
+ return refreshAttachmentUrls(this, attachmentUrls);
8535
+ }
8536
+ /** List instance custom guild badges (`GET /instance/badges`). */
8537
+ fetchInstanceBadges(options) {
8538
+ return fetchInstanceBadges(this, options);
8539
+ }
8540
+ /** Fetch forum/media thread post data for a channel. */
8541
+ fetchChannelPostData(channelId, threadIds) {
8542
+ return fetchChannelPostData(this, channelId, threadIds);
8543
+ }
7866
8544
  /**
7867
8545
  * Fetch the current application (`/applications/@me`).
7868
8546
  * @returns Application metadata (owner, flags, RPC origins, etc.)
@@ -7957,6 +8635,9 @@ var Client = class _Client extends EventEmitter3 {
7957
8635
  * @internal
7958
8636
  */
7959
8637
  getOrCreateUser(data) {
8638
+ if (!data || typeof data.id !== "string" || data.id.length === 0) {
8639
+ throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
8640
+ }
7960
8641
  const existing = this.users.get(data.id);
7961
8642
  if (existing) {
7962
8643
  existing._patch(data);
@@ -8209,7 +8890,7 @@ var Client = class _Client extends EventEmitter3 {
8209
8890
  * @see {@link Routes}
8210
8891
  */
8211
8892
  static get Routes() {
8212
- return Routes37;
8893
+ return Routes38;
8213
8894
  }
8214
8895
  };
8215
8896
  export {