@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/cluster.mjs CHANGED
@@ -24,6 +24,7 @@ var Events = {
24
24
  GuildEmojisUpdate: "guildEmojisUpdate",
25
25
  GuildStickersUpdate: "guildStickersUpdate",
26
26
  GuildCountsUpdate: "guildCountsUpdate",
27
+ GuildHealthUpdate: "guildHealthUpdate",
27
28
  ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
28
29
  GuildMemberAdd: "guildMemberAdd",
29
30
  GuildMemberUpdate: "guildMemberUpdate",
@@ -58,7 +59,16 @@ var Events = {
58
59
  VoiceStateAck: "voiceStateAck",
59
60
  VoiceServerUpdate: "voiceServerUpdate",
60
61
  EntranceSoundPlay: "entranceSoundPlay",
62
+ VoiceSignal: "voiceSignal",
63
+ OperatorPassUpdate: "operatorPassUpdate",
61
64
  VoiceStatesSync: "voiceStatesSync",
65
+ VoiceJoinQueued: "voiceJoinQueued",
66
+ StageInstanceCreate: "stageInstanceCreate",
67
+ StageInstanceUpdate: "stageInstanceUpdate",
68
+ StageInstanceDelete: "stageInstanceDelete",
69
+ StageCountsUpdate: "stageCountsUpdate",
70
+ StageVoiceStatesSync: "stageVoiceStatesSync",
71
+ StageAudienceListUpdate: "stageAudienceListUpdate",
62
72
  WebhooksUpdate: "webhooksUpdate",
63
73
  Resumed: "resumed",
64
74
  Error: "error",
@@ -80,7 +90,7 @@ import { FluxerError } from "@fluxerjs/util";
80
90
  // src/ClientCore/Client.ts
81
91
  import { EventEmitter as EventEmitter3 } from "events";
82
92
  import { REST } from "@fluxerjs/rest";
83
- import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes37 } from "@fluxerjs/types";
93
+ import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes38 } from "@fluxerjs/types";
84
94
  import { createLogger } from "@fluxerjs/util";
85
95
 
86
96
  // src/Domain/Message/Message.ts
@@ -1113,6 +1123,45 @@ import { SnowflakeUtil } from "@fluxerjs/util";
1113
1123
  // src/ClientCore/MessageManager.ts
1114
1124
  import { Collection as Collection2 } from "@fluxerjs/collection";
1115
1125
  import { Routes as Routes2 } from "@fluxerjs/types";
1126
+
1127
+ // src/ClientCore/Resolve.ts
1128
+ function normalizeSnowflakeId(value, label) {
1129
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
1130
+ throw new TypeError(
1131
+ `${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
1132
+ );
1133
+ }
1134
+ const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
1135
+ if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
1136
+ throw new TypeError(`${label} requires a non-empty ID`);
1137
+ }
1138
+ return id;
1139
+ }
1140
+ function assertApiObjectWithId(data, label) {
1141
+ if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
1142
+ throw new TypeError(`${label} received an invalid API payload (missing string id)`);
1143
+ }
1144
+ return data;
1145
+ }
1146
+ function assertApiArray(data, label) {
1147
+ if (!Array.isArray(data)) {
1148
+ throw new TypeError(`${label} received an invalid API payload (expected an array)`);
1149
+ }
1150
+ return data;
1151
+ }
1152
+ async function dedupeFetch(pending, key, fn) {
1153
+ const existing = pending.get(key);
1154
+ if (existing) return existing;
1155
+ const request = fn();
1156
+ pending.set(key, request);
1157
+ try {
1158
+ return await request;
1159
+ } finally {
1160
+ if (pending.get(key) === request) pending.delete(key);
1161
+ }
1162
+ }
1163
+
1164
+ // src/ClientCore/MessageManager.ts
1116
1165
  var BULK = {
1117
1166
  requests: { min: 1, max: 25 },
1118
1167
  limit: { min: 1, max: 25 },
@@ -1148,25 +1197,32 @@ var MessageManager = class {
1148
1197
  }
1149
1198
  /** Structure cache keyed by message id (identity for {@link get}). */
1150
1199
  _structures = new Collection2();
1200
+ pendingFetches = /* @__PURE__ */ new Map();
1151
1201
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
1152
1202
  get(messageId) {
1153
- const data = this.client._getMessageCache(this.channelId)?.get(messageId);
1203
+ const id = String(messageId ?? "").trim();
1204
+ if (!id) return void 0;
1205
+ const data = this.client._getMessageCache(this.channelId)?.get(id);
1154
1206
  if (!data) {
1155
- this._structures.delete(messageId);
1207
+ this._structures.delete(id);
1156
1208
  return void 0;
1157
1209
  }
1158
- const existing = this._structures.get(messageId);
1159
- if (existing) return existing;
1210
+ const existing = this._structures.get(id);
1211
+ if (existing) {
1212
+ existing._patch(data);
1213
+ return existing;
1214
+ }
1160
1215
  const message = new Message(this.client, data);
1161
- this._structures.set(messageId, message);
1216
+ this._structures.set(id, message);
1162
1217
  return message;
1163
1218
  }
1164
1219
  /** Retrieve from cache, otherwise {@link fetch}. */
1165
1220
  async resolve(messageId) {
1166
- return this.get(messageId) ?? this.fetch(messageId);
1221
+ const id = normalizeSnowflakeId(messageId, "messages.resolve()");
1222
+ return this.get(id) ?? this.fetch(id);
1167
1223
  }
1168
1224
  async fetch(idOrOptions) {
1169
- return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
1225
+ return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
1170
1226
  }
1171
1227
  /** Cache API data and return a {@link Message} (reusing identity when present). */
1172
1228
  wrap(data) {
@@ -1183,9 +1239,13 @@ var MessageManager = class {
1183
1239
  }
1184
1240
  /** Fetch a single message from the API. */
1185
1241
  async fetchOne(messageId) {
1242
+ return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
1243
+ }
1244
+ async fetchOneFresh(messageId) {
1186
1245
  try {
1187
- const data = await this.client.rest.get(
1188
- Routes2.channelMessage(this.channelId, messageId)
1246
+ const data = assertApiObjectWithId(
1247
+ await this.client.rest.get(Routes2.channelMessage(this.channelId, messageId)),
1248
+ "messages.fetch()"
1189
1249
  );
1190
1250
  return this.wrap(data);
1191
1251
  } catch (err) {
@@ -1211,9 +1271,15 @@ var MessageManager = class {
1211
1271
  if (value != null && value !== "") qs2.set(key, String(value));
1212
1272
  }
1213
1273
  const base = Routes2.channelMessages(this.channelId);
1214
- const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
1274
+ const data = assertApiArray(
1275
+ await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
1276
+ "messages.fetch()"
1277
+ );
1215
1278
  const collection = new Collection2();
1216
- for (const msg of data) collection.set(msg.id, this.wrap(msg));
1279
+ for (const msg of data) {
1280
+ if (!msg?.id) continue;
1281
+ collection.set(msg.id, this.wrap(msg));
1282
+ }
1217
1283
  return collection;
1218
1284
  }
1219
1285
  };
@@ -1417,6 +1483,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1417
1483
  }
1418
1484
 
1419
1485
  // src/Domain/Channel/Base.ts
1486
+ function isFullChannelData(data) {
1487
+ 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;
1488
+ }
1420
1489
  var Channel = class extends Base {
1421
1490
  #messages;
1422
1491
  /** The {@link Client} that instantiated this channel. */
@@ -1431,6 +1500,11 @@ var Channel = class extends Base {
1431
1500
  icon;
1432
1501
  /** ISO8601 timestamp of the last pinned message update. */
1433
1502
  lastPinTimestamp;
1503
+ /**
1504
+ * True when built from a partial payload (e.g. a DM stub) and not yet hydrated
1505
+ * with a full channel object. `channels.resolve()` refetches partial channels.
1506
+ */
1507
+ partial;
1434
1508
  constructor(client, data) {
1435
1509
  super();
1436
1510
  this.client = client;
@@ -1439,6 +1513,7 @@ var Channel = class extends Base {
1439
1513
  this.name = data.name ?? null;
1440
1514
  this.icon = data.icon ?? null;
1441
1515
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1516
+ this.partial = !isFullChannelData(data);
1442
1517
  }
1443
1518
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
1444
1519
  get createdTimestamp() {
@@ -1459,6 +1534,7 @@ var Channel = class extends Base {
1459
1534
  if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
1460
1535
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1461
1536
  }
1537
+ if (isFullChannelData(data)) this.partial = false;
1462
1538
  }
1463
1539
  /** @internal Factory wired after subclasses load. */
1464
1540
  static from(_c, _d) {
@@ -1478,11 +1554,11 @@ var Channel = class extends Base {
1478
1554
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
1479
1555
  */
1480
1556
  isTextBased() {
1481
- 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;
1557
+ 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;
1482
1558
  }
1483
1559
  /** Check if this is a guild channel, including threads, forums, and media channels. */
1484
1560
  isGuild() {
1485
- 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;
1561
+ 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;
1486
1562
  }
1487
1563
  /** Check if this is a thread (public, private, or announcement). */
1488
1564
  isThread() {
@@ -1516,10 +1592,18 @@ var Channel = class extends Base {
1516
1592
  isPersonalNotes() {
1517
1593
  return this.type === ChannelType3.DMPersonalNotes;
1518
1594
  }
1519
- /** Check if this is a voice channel. */
1595
+ /** Check if this is a voice channel (type 2 only; see {@link isVoiceBased} to include stages). */
1520
1596
  isVoice() {
1521
1597
  return this.type === ChannelType3.GuildVoice;
1522
1598
  }
1599
+ /** Check if this is a stage channel (type 13). */
1600
+ isStage() {
1601
+ return this.type === ChannelType3.GuildStageVoice;
1602
+ }
1603
+ /** Check if this is a voice or stage channel, i.e. one `@fluxerjs/voice` can join. */
1604
+ isVoiceBased() {
1605
+ return this.type === ChannelType3.GuildVoice || this.type === ChannelType3.GuildStageVoice;
1606
+ }
1523
1607
  /** Check if this is a link channel. */
1524
1608
  isLink() {
1525
1609
  return this.type === ChannelType3.GuildLink;
@@ -2234,10 +2318,10 @@ var Message = class _Message extends Base {
2234
2318
  this.channelId = data.channel_id;
2235
2319
  this.guildId = data.guild_id ?? null;
2236
2320
  this.author = client.getOrCreateUser(data.author);
2237
- this.content = data.content;
2238
- this.createdAt = new Date(data.timestamp);
2321
+ this.content = data.content ?? "";
2322
+ this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
2239
2323
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2240
- this.pinned = data.pinned;
2324
+ this.pinned = data.pinned ?? false;
2241
2325
  this.attachments = new Collection5();
2242
2326
  for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2243
2327
  this.type = data.type ?? MessageType.Default;
@@ -2269,33 +2353,47 @@ var Message = class _Message extends Base {
2269
2353
  * @internal
2270
2354
  */
2271
2355
  _patch(data) {
2272
- this.content = data.content;
2273
- this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2274
- this.pinned = data.pinned;
2275
- this.attachments.clear();
2276
- for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2277
- this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
2278
- this.mentionEveryone = data.mention_everyone ?? false;
2279
- this.tts = data.tts ?? false;
2280
- this.embeds = (data.embeds ?? []).map(toMessageEmbed);
2281
- this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
2282
- this.reactions._patch(data.reactions);
2283
- this.messageReference = data.message_reference ? {
2284
- channelId: data.message_reference.channel_id,
2285
- messageId: data.message_reference.message_id,
2286
- guildId: data.message_reference.guild_id ?? null,
2287
- ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
2288
- } : null;
2289
- this.messageSnapshots = (data.message_snapshots ?? []).map(
2290
- (s) => toMessageSnapshot(this.client, s)
2291
- );
2292
- this.call = data.call ? toMessageCall(data.call) : null;
2293
- this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
2294
- this.webhookId = data.webhook_id ?? null;
2295
- this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
2296
- this.mentionRoles = data.mention_roles ?? [];
2297
- this.nonce = data.nonce ?? null;
2298
- this.nsfwEmojis = data.nsfw_emojis ?? [];
2356
+ if (data.content !== void 0) this.content = data.content ?? "";
2357
+ if (data.edited_timestamp !== void 0) {
2358
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2359
+ }
2360
+ if (data.pinned !== void 0) this.pinned = data.pinned;
2361
+ if (data.attachments !== void 0) {
2362
+ this.attachments.clear();
2363
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2364
+ }
2365
+ if (data.flags !== void 0) this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
2366
+ if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
2367
+ if (data.tts !== void 0) this.tts = data.tts;
2368
+ if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
2369
+ if (data.stickers !== void 0) {
2370
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
2371
+ }
2372
+ if (data.reactions !== void 0) this.reactions._patch(data.reactions);
2373
+ if (data.message_reference !== void 0) {
2374
+ this.messageReference = data.message_reference ? {
2375
+ channelId: data.message_reference.channel_id,
2376
+ messageId: data.message_reference.message_id,
2377
+ guildId: data.message_reference.guild_id ?? null,
2378
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
2379
+ } : null;
2380
+ }
2381
+ if (data.message_snapshots !== void 0) {
2382
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
2383
+ (s) => toMessageSnapshot(this.client, s)
2384
+ );
2385
+ }
2386
+ if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
2387
+ if (data.referenced_message !== void 0) {
2388
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
2389
+ }
2390
+ if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
2391
+ if (data.mentions !== void 0) {
2392
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
2393
+ }
2394
+ if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
2395
+ if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
2396
+ if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
2299
2397
  if (data.thread) this.thread = cacheThread(this.client, data.thread);
2300
2398
  }
2301
2399
  /**
@@ -2396,6 +2494,23 @@ var Message = class _Message extends Base {
2396
2494
  async fetch() {
2397
2495
  return this.client.channels.fetchMessage(this.channelId, this.id);
2398
2496
  }
2497
+ /** Publish this announcement message to channels following its channel. */
2498
+ async crosspost() {
2499
+ const data = await this.client.rest.post(
2500
+ Routes7.channelMessageCrosspost(this.channelId, this.id),
2501
+ { auth: true }
2502
+ );
2503
+ const published = new _Message(this.client, data);
2504
+ this.client._addMessageToCache(this.channelId, data);
2505
+ return published;
2506
+ }
2507
+ /** Fetch the source guild of a crossposted (followed-channel) message. */
2508
+ async fetchCrosspostSource() {
2509
+ return this.client.rest.get(
2510
+ Routes7.channelMessageCrosspostSource(this.channelId, this.id),
2511
+ { auth: true }
2512
+ );
2513
+ }
2399
2514
  /** Delete this message. */
2400
2515
  async delete(reason) {
2401
2516
  await this.client.rest.delete(Routes7.channelMessage(this.channelId, this.id), {
@@ -2499,8 +2614,8 @@ var PartialMessage = class {
2499
2614
  };
2500
2615
 
2501
2616
  // src/Domain/User.ts
2502
- import { Routes as Routes17 } from "@fluxerjs/types";
2503
- import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
2617
+ import { Routes as Routes18 } from "@fluxerjs/types";
2618
+ import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
2504
2619
 
2505
2620
  // src/Domain/Channel/Dm.ts
2506
2621
  import { ChannelType as ChannelType4, Routes as Routes9 } from "@fluxerjs/types";
@@ -2559,7 +2674,7 @@ var DMChannel = class extends TextCapable(Channel) {
2559
2674
  const full = data;
2560
2675
  this.lastMessageId = full.last_message_id ?? null;
2561
2676
  this.ownerId = full.owner_id ?? null;
2562
- this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
2677
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
2563
2678
  this.nicks = full.nicks ?? {};
2564
2679
  }
2565
2680
  /**
@@ -2574,7 +2689,7 @@ var DMChannel = class extends TextCapable(Channel) {
2574
2689
  }
2575
2690
  if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2576
2691
  if ("recipients" in full && full.recipients !== void 0) {
2577
- this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2692
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
2578
2693
  }
2579
2694
  if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2580
2695
  }
@@ -2641,11 +2756,11 @@ var DMChannel = class extends TextCapable(Channel) {
2641
2756
  // src/Domain/Channel/Forum.ts
2642
2757
  import {
2643
2758
  ChannelType as ChannelType7,
2644
- Routes as Routes16
2759
+ Routes as Routes17
2645
2760
  } from "@fluxerjs/types";
2646
2761
 
2647
2762
  // src/Domain/Channel/Guild.ts
2648
- import { Routes as Routes13 } from "@fluxerjs/types";
2763
+ import { Routes as Routes14 } from "@fluxerjs/types";
2649
2764
  import { PermissionFlags } from "@fluxerjs/util";
2650
2765
 
2651
2766
  // src/Domain/Invite.ts
@@ -2659,17 +2774,19 @@ import {
2659
2774
  // src/Helpers/Instance.ts
2660
2775
  import { isRecord } from "@fluxerjs/util";
2661
2776
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2662
- api: "https://web.fluxer.app/api",
2663
- api_client: "https://web.fluxer.app/api",
2664
- api_public: "https://api.fluxer.app",
2665
- gateway: "wss://gateway.fluxer.app",
2777
+ api: "https://fluxer.com/api",
2778
+ api_client: "https://fluxer.com/api",
2779
+ api_public: "https://fluxer.com/api",
2780
+ gateway: "wss://gateway.fluxer.com",
2666
2781
  media: CDN_URL,
2782
+ upload_relay: "https://uploads.fluxer.app",
2667
2783
  static_cdn: STATIC_CDN_URL,
2668
- marketing: "https://fluxer.app",
2784
+ marketing: "https://fluxer.com",
2785
+ docs: "https://docs.fluxer.com",
2669
2786
  admin: "https://admin.fluxer.app",
2670
2787
  invite: "https://fluxer.gg",
2671
2788
  gift: "https://fluxer.gift",
2672
- webapp: "https://web.fluxer.app"
2789
+ webapp: "https://fluxer.com"
2673
2790
  });
2674
2791
  var ENDPOINT_KEYS = [
2675
2792
  "api",
@@ -2684,6 +2801,11 @@ var ENDPOINT_KEYS = [
2684
2801
  "gift",
2685
2802
  "webapp"
2686
2803
  ];
2804
+ var OPTIONAL_ENDPOINT_KEYS = [
2805
+ "api_transport",
2806
+ "upload_relay",
2807
+ "docs"
2808
+ ];
2687
2809
  function requireString(obj, key, path) {
2688
2810
  const value = obj[key];
2689
2811
  if (typeof value !== "string" || value.length === 0) {
@@ -2724,6 +2846,10 @@ function parseInstanceDiscovery(raw) {
2724
2846
  for (const key of ENDPOINT_KEYS) {
2725
2847
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2726
2848
  }
2849
+ for (const key of OPTIONAL_ENDPOINT_KEYS) {
2850
+ const value = raw.endpoints[key];
2851
+ if (typeof value === "string" && value.length > 0) endpoints[key] = value;
2852
+ }
2727
2853
  endpoints.api = normalizeApiOrigin(endpoints.api);
2728
2854
  endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2729
2855
  endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
@@ -2777,7 +2903,21 @@ function parseInstanceDiscovery(raw) {
2777
2903
  defaultsHash: ""
2778
2904
  },
2779
2905
  push: raw.push ?? { public_vapid_key: null },
2780
- app_public: raw.app_public ?? {}
2906
+ app_public: raw.app_public ?? {},
2907
+ ...typeof raw.codename === "string" ? { codename: raw.codename } : {},
2908
+ age_policy: isRecord(raw.age_policy) ? raw.age_policy : { geos: [] },
2909
+ ...raw.notice === null || isRecord(raw.notice) ? { notice: raw.notice } : {},
2910
+ ...isRecord(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
2911
+ ...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
2912
+ ...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
2913
+ ...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
2914
+ ...isRecord(raw.built_in_guild_badge_images) ? {
2915
+ built_in_guild_badge_images: raw.built_in_guild_badge_images
2916
+ } : {},
2917
+ ...Array.isArray(raw.hidden_built_in_guild_badges) ? {
2918
+ hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
2919
+ } : {},
2920
+ ...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
2781
2921
  };
2782
2922
  }
2783
2923
  function resolveInstanceEndpoints(input) {
@@ -2797,7 +2937,7 @@ function resolveInstanceEndpoints(input) {
2797
2937
  }
2798
2938
  const partial = input;
2799
2939
  const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
2800
- for (const key of ENDPOINT_KEYS) {
2940
+ for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
2801
2941
  const value = partial[key];
2802
2942
  if (typeof value === "string" && value.length > 0) {
2803
2943
  merged[key] = value;
@@ -3219,6 +3359,127 @@ var PermissionOverwriteManager = class {
3219
3359
  }
3220
3360
  };
3221
3361
 
3362
+ // src/Domain/StageInstance.ts
3363
+ import { Routes as Routes13, StageInstancePrivacyLevel } from "@fluxerjs/types";
3364
+ import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
3365
+ var StageInstance = class extends Base {
3366
+ client;
3367
+ id;
3368
+ guildId;
3369
+ channelId;
3370
+ topic;
3371
+ /** Always {@link StageInstancePrivacyLevel.GuildOnly} on Fluxer. */
3372
+ privacyLevel;
3373
+ /** Always `true` on Fluxer. */
3374
+ discoverableDisabled;
3375
+ /** Always null on Fluxer. */
3376
+ guildScheduledEventId;
3377
+ constructor(client, data) {
3378
+ super();
3379
+ this.client = client;
3380
+ this.id = data.id;
3381
+ this.guildId = data.guild_id;
3382
+ this.channelId = data.channel_id;
3383
+ this.topic = data.topic;
3384
+ this.privacyLevel = data.privacy_level ?? StageInstancePrivacyLevel.GuildOnly;
3385
+ this.discoverableDisabled = data.discoverable_disabled ?? true;
3386
+ this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
3387
+ }
3388
+ /** @internal Patch in place from a newer payload. */
3389
+ _patch(data) {
3390
+ if (data.topic !== void 0) this.topic = data.topic;
3391
+ if (data.privacy_level !== void 0) this.privacyLevel = data.privacy_level;
3392
+ if (data.discoverable_disabled !== void 0) {
3393
+ this.discoverableDisabled = data.discoverable_disabled;
3394
+ }
3395
+ if (data.guild_scheduled_event_id !== void 0) {
3396
+ this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
3397
+ }
3398
+ }
3399
+ get guild() {
3400
+ return this.client.guilds.get(this.guildId) ?? null;
3401
+ }
3402
+ get channel() {
3403
+ const channel = this.client.channels.get(this.channelId);
3404
+ return channel?.isStage() ? channel : null;
3405
+ }
3406
+ /** Unix timestamp (ms) when the stage started, from its snowflake ID. */
3407
+ get createdTimestamp() {
3408
+ return SnowflakeUtil5.timestampFromSnowflake(this.id);
3409
+ }
3410
+ get createdAt() {
3411
+ return SnowflakeUtil5.dateFromSnowflake(this.id);
3412
+ }
3413
+ /**
3414
+ * Change the live stage. Needs a stage moderator.
3415
+ * Fires `STAGE_INSTANCE_UPDATE`.
3416
+ */
3417
+ async edit(options) {
3418
+ const body = {};
3419
+ if (options.topic !== void 0) body.topic = options.topic;
3420
+ const data = await this.client.rest.patch(
3421
+ Routes13.stageInstance(this.channelId),
3422
+ { body, auth: true, ...auditReasonHeaders(options.reason) }
3423
+ );
3424
+ this._patch(data);
3425
+ return this;
3426
+ }
3427
+ /** Change the stage topic. Shorthand for {@link edit}. */
3428
+ async setTopic(topic, reason) {
3429
+ return this.edit({ topic, reason });
3430
+ }
3431
+ /**
3432
+ * End the stage. Needs a stage moderator. Speakers move to the audience, raised hands are
3433
+ * lowered, and everyone stays connected unless `disconnectAll` is set.
3434
+ */
3435
+ async delete(options = {}) {
3436
+ const route = Routes13.stageInstance(this.channelId) + (options.disconnectAll ? "?disconnect_all=true" : "");
3437
+ await this.client.rest.delete(route, { auth: true, ...auditReasonHeaders(options.reason) });
3438
+ }
3439
+ toJSON() {
3440
+ return {
3441
+ id: this.id,
3442
+ guild_id: this.guildId,
3443
+ channel_id: this.channelId,
3444
+ topic: this.topic,
3445
+ privacy_level: this.privacyLevel,
3446
+ discoverable_disabled: this.discoverableDisabled,
3447
+ guild_scheduled_event_id: this.guildScheduledEventId
3448
+ };
3449
+ }
3450
+ };
3451
+
3452
+ // src/Domain/Channel/StageSync.ts
3453
+ function syncStageInstances(guild, instances) {
3454
+ const seen = /* @__PURE__ */ new Set();
3455
+ for (const data of instances) {
3456
+ seen.add(data.id);
3457
+ const existing = guild.stageInstances.get(data.id);
3458
+ if (existing) existing._patch(data);
3459
+ else guild.stageInstances.set(data.id, new StageInstance(guild.client, data));
3460
+ }
3461
+ for (const id of [...guild.stageInstances.keys()]) {
3462
+ if (!seen.has(id)) guild.stageInstances.delete(id);
3463
+ }
3464
+ }
3465
+ function applyStageCounts(guild, counts) {
3466
+ for (const count of counts) {
3467
+ const channel = guild.channels.get(count.channel_id);
3468
+ if (channel?.isStage()) channel._patchCounts(count);
3469
+ }
3470
+ }
3471
+ function cacheStageInstance(client, data) {
3472
+ const guild = client.guilds.get(data.guild_id);
3473
+ const existing = guild?.stageInstances.get(data.id);
3474
+ if (existing) {
3475
+ existing._patch(data);
3476
+ return existing;
3477
+ }
3478
+ const instance = new StageInstance(client, data);
3479
+ guild?.stageInstances.set(instance.id, instance);
3480
+ return instance;
3481
+ }
3482
+
3222
3483
  // src/Domain/Channel/ThreadBind.ts
3223
3484
  var factory;
3224
3485
  var managers = /* @__PURE__ */ new WeakMap();
@@ -3273,7 +3534,7 @@ var GuildChannel = class extends Channel {
3273
3534
  }
3274
3535
  /** Create a webhook for this channel. Requires Manage Webhooks. */
3275
3536
  async createWebhook(options) {
3276
- const data = await this.client.rest.post(Routes13.channelWebhooks(this.id), {
3537
+ const data = await this.client.rest.post(Routes14.channelWebhooks(this.id), {
3277
3538
  body: options,
3278
3539
  auth: true
3279
3540
  });
@@ -3281,13 +3542,13 @@ var GuildChannel = class extends Channel {
3281
3542
  }
3282
3543
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
3283
3544
  async fetchWebhooks() {
3284
- const data = await this.client.rest.get(Routes13.channelWebhooks(this.id));
3545
+ const data = await this.client.rest.get(Routes14.channelWebhooks(this.id));
3285
3546
  return data.map((w) => new Webhook(this.client, w));
3286
3547
  }
3287
3548
  /** Create an invite for this channel. Requires Create Instant Invite. */
3288
3549
  async createInvite(options) {
3289
3550
  const body = options ? toChannelInviteBody(options) : {};
3290
- const data = await this.client.rest.post(Routes13.channelInvites(this.id), {
3551
+ const data = await this.client.rest.post(Routes14.channelInvites(this.id), {
3291
3552
  body: Object.keys(body).length ? body : void 0,
3292
3553
  auth: true
3293
3554
  });
@@ -3295,7 +3556,7 @@ var GuildChannel = class extends Channel {
3295
3556
  }
3296
3557
  /** Fetch all invites for this channel. Requires Manage Channels. */
3297
3558
  async fetchInvites() {
3298
- const data = await this.client.rest.get(Routes13.channelInvites(this.id));
3559
+ const data = await this.client.rest.get(Routes14.channelInvites(this.id));
3299
3560
  return data.map((i) => new Invite(this.client, i));
3300
3561
  }
3301
3562
  /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
@@ -3325,7 +3586,7 @@ var GuildChannel = class extends Channel {
3325
3586
  }
3326
3587
  /** Edit this channel's settings. Requires Manage Channels. */
3327
3588
  async edit(options) {
3328
- const data = await this.client.rest.patch(Routes13.channel(this.id), {
3589
+ const data = await this.client.rest.patch(Routes14.channel(this.id), {
3329
3590
  body: toChannelEditBody(options),
3330
3591
  auth: true,
3331
3592
  ...auditReasonHeaders(options.reason)
@@ -3407,7 +3668,7 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3407
3668
  * Sends only those fields. The thread-parent update body does not accept a channel rename.
3408
3669
  */
3409
3670
  async editThreadDefaults(options) {
3410
- const data = await this.client.rest.patch(Routes13.channel(this.id), {
3671
+ const data = await this.client.rest.patch(Routes14.channel(this.id), {
3411
3672
  body: toThreadParentEditBody(options),
3412
3673
  auth: true,
3413
3674
  ...auditReasonHeaders(options.reason)
@@ -3417,6 +3678,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3417
3678
  }
3418
3679
  };
3419
3680
  var AnnouncementChannel = class extends TextChannel {
3681
+ /**
3682
+ * Follow this announcement channel into `webhookChannelId` (a channel in a guild
3683
+ * where the bot can manage webhooks). Published messages are copied there.
3684
+ */
3685
+ async follow(webhookChannelId) {
3686
+ return this.client.rest.post(
3687
+ Routes14.channelFollowers(this.id),
3688
+ { body: { webhook_channel_id: webhookChannelId }, auth: true }
3689
+ );
3690
+ }
3691
+ /** Fetch follower counts for this announcement channel. */
3692
+ async fetchFollowerStats() {
3693
+ return this.client.rest.get(
3694
+ Routes14.channelFollowerStats(this.id),
3695
+ { auth: true }
3696
+ );
3697
+ }
3420
3698
  };
3421
3699
  var CategoryChannel = class extends GuildChannel {
3422
3700
  };
@@ -3443,6 +3721,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3443
3721
  voiceConnectionLimit;
3444
3722
  /** RTC region override for this channel. */
3445
3723
  rtcRegion;
3724
+ /** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
3725
+ rtcP2p;
3446
3726
  constructor(client, data) {
3447
3727
  super(client, data);
3448
3728
  this.topic = data.topic ?? null;
@@ -3456,6 +3736,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3456
3736
  this.userLimit = data.user_limit ?? null;
3457
3737
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3458
3738
  this.rtcRegion = data.rtc_region ?? null;
3739
+ this.rtcP2p = data.rtc_p2p ?? false;
3459
3740
  }
3460
3741
  /**
3461
3742
  * Set slowmode (seconds between messages). Pass `0` to disable.
@@ -3482,6 +3763,97 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3482
3763
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3483
3764
  }
3484
3765
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
3766
+ if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
3767
+ }
3768
+ };
3769
+ var StageChannel = class extends VoiceChannel {
3770
+ /** Last known stage counts, or null until Fluxer sends them. */
3771
+ counts = null;
3772
+ /** The cached live stage of this channel, or null when the stage isn't live (or not cached). */
3773
+ get stageInstance() {
3774
+ const guild = this.client.guilds.get(this.guildId);
3775
+ if (!guild) return null;
3776
+ for (const instance of guild.stageInstances.values()) {
3777
+ if (instance.channelId === this.id) return instance;
3778
+ }
3779
+ return null;
3780
+ }
3781
+ /** Whether the stage is live according to the cache. */
3782
+ get isLive() {
3783
+ return this.stageInstance !== null;
3784
+ }
3785
+ /**
3786
+ * Start a stage in this channel. Needs a stage moderator (`MANAGE_CHANNELS`, `MUTE_MEMBERS` and
3787
+ * `MOVE_MEMBERS`). When the caller is connected to the stage, they become a speaker.
3788
+ */
3789
+ async createStageInstance(options) {
3790
+ const body = { channel_id: this.id, topic: options.topic };
3791
+ if (options.sendStartNotification !== void 0) {
3792
+ body.send_start_notification = options.sendStartNotification;
3793
+ }
3794
+ const data = await this.client.rest.post(Routes14.stageInstances(), {
3795
+ body,
3796
+ auth: true,
3797
+ ...auditReasonHeaders(options.reason)
3798
+ });
3799
+ return cacheStageInstance(this.client, data);
3800
+ }
3801
+ /** Fetch the live stage of this channel. Rejects with `UNKNOWN_STAGE_INSTANCE` when not live. */
3802
+ async fetchStageInstance() {
3803
+ const data = await this.client.rest.get(Routes14.stageInstance(this.id), {
3804
+ auth: true
3805
+ });
3806
+ return cacheStageInstance(this.client, data);
3807
+ }
3808
+ /**
3809
+ * Move a member (or yourself when `user` is omitted) between the audience and the speakers.
3810
+ *
3811
+ * - Yourself, `false`: become a speaker (needs `MUTE_MEMBERS`), or accept an open invite.
3812
+ * - Yourself, `true`: move to the audience, or decline an invite.
3813
+ * - Another member, `false`: invite them to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`.
3814
+ * - Another member, `true`: move them to the audience and clear a raised hand or invite.
3815
+ */
3816
+ async setSuppressed(suppressed, user) {
3817
+ const userId = user === void 0 ? "@me" : typeof user === "string" ? user : user.id;
3818
+ const body = {
3819
+ channel_id: this.id,
3820
+ suppress: suppressed
3821
+ };
3822
+ await this.client.rest.patch(Routes14.guildVoiceState(this.guildId, userId), {
3823
+ body,
3824
+ auth: true
3825
+ });
3826
+ }
3827
+ /** Invite a member to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`. */
3828
+ async inviteToSpeak(user) {
3829
+ await this.setSuppressed(false, user);
3830
+ }
3831
+ /** Move a speaker (or yourself when `user` is omitted) to the audience. */
3832
+ async moveToAudience(user) {
3833
+ await this.setSuppressed(true, user);
3834
+ }
3835
+ /**
3836
+ * Raise (`true`) or lower (`false`) your hand. Raising needs a live stage and
3837
+ * `REQUEST_TO_SPEAK`; lowering also accepts an open invite to speak.
3838
+ */
3839
+ async setRequestToSpeak(raised = true) {
3840
+ const body = {
3841
+ channel_id: this.id,
3842
+ request_to_speak_timestamp: raised ? (/* @__PURE__ */ new Date()).toISOString() : null
3843
+ };
3844
+ await this.client.rest.patch(Routes14.guildVoiceState(this.guildId, "@me"), {
3845
+ body,
3846
+ auth: true
3847
+ });
3848
+ }
3849
+ /** @internal Apply a stage count object. */
3850
+ _patchCounts(data) {
3851
+ this.counts = {
3852
+ listenerCount: data.listener_count,
3853
+ speakerCount: data.speaker_count,
3854
+ requestCount: data.request_count,
3855
+ videoEnabled: data.video_enabled ?? null
3856
+ };
3485
3857
  }
3486
3858
  };
3487
3859
  var LinkChannel = class extends GuildChannel {
@@ -3497,10 +3869,10 @@ var LinkChannel = class extends GuildChannel {
3497
3869
  };
3498
3870
 
3499
3871
  // src/Domain/Channel/ThreadManager.ts
3500
- import { ChannelType as ChannelType6, Routes as Routes15 } from "@fluxerjs/types";
3872
+ import { ChannelType as ChannelType6, Routes as Routes16 } from "@fluxerjs/types";
3501
3873
 
3502
3874
  // src/Domain/Channel/ThreadChannel.ts
3503
- import { ChannelType as ChannelType5, Routes as Routes14 } from "@fluxerjs/types";
3875
+ import { ChannelType as ChannelType5, Routes as Routes15 } from "@fluxerjs/types";
3504
3876
  var ThreadMember = class {
3505
3877
  /** Thread ID. */
3506
3878
  id;
@@ -3627,7 +3999,7 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
3627
3999
  * `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
3628
4000
  */
3629
4001
  async edit(options) {
3630
- const data = await this.client.rest.patch(Routes14.channel(this.id), {
4002
+ const data = await this.client.rest.patch(Routes15.channel(this.id), {
3631
4003
  body: toThreadEditBody(this.type, threadEditFields(options)),
3632
4004
  auth: true,
3633
4005
  ...auditReasonHeaders(options.reason)
@@ -3645,16 +4017,16 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
3645
4017
  }
3646
4018
  /** Join this thread. */
3647
4019
  async join() {
3648
- await this.client.rest.put(Routes14.channelThreadMemberMe(this.id), { auth: true });
4020
+ await this.client.rest.put(Routes15.channelThreadMemberMe(this.id), { auth: true });
3649
4021
  }
3650
4022
  /** Leave this thread. */
3651
4023
  async leave() {
3652
- await this.client.rest.delete(Routes14.channelThreadMemberMe(this.id), { auth: true });
4024
+ await this.client.rest.delete(Routes15.channelThreadMemberMe(this.id), { auth: true });
3653
4025
  }
3654
4026
  /** Update the current user's notification settings for this thread. */
3655
4027
  async editSelf(options) {
3656
4028
  const data = await this.client.rest.patch(
3657
- Routes14.channelThreadMemberMeSettings(this.id),
4029
+ Routes15.channelThreadMemberMeSettings(this.id),
3658
4030
  { body: toThreadMemberSettingsBody(options), auth: true }
3659
4031
  );
3660
4032
  this.member = data ? new ThreadMember(data) : null;
@@ -3668,7 +4040,7 @@ var ThreadMemberManager = class {
3668
4040
  /** List members of this thread. */
3669
4041
  async fetch(options) {
3670
4042
  const data = await this.thread.client.rest.get(
3671
- withQuery(Routes14.channelThreadMembers(this.thread.id), {
4043
+ withQuery(Routes15.channelThreadMembers(this.thread.id), {
3672
4044
  with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
3673
4045
  after: options?.after,
3674
4046
  limit: options?.limit
@@ -3679,7 +4051,7 @@ var ThreadMemberManager = class {
3679
4051
  /** Fetch one member of this thread. */
3680
4052
  async fetchOne(userId, options) {
3681
4053
  const data = await this.thread.client.rest.get(
3682
- withQuery(Routes14.channelThreadMember(this.thread.id, userId), {
4054
+ withQuery(Routes15.channelThreadMember(this.thread.id, userId), {
3683
4055
  with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
3684
4056
  })
3685
4057
  );
@@ -3687,13 +4059,13 @@ var ThreadMemberManager = class {
3687
4059
  }
3688
4060
  /** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
3689
4061
  async add(userId) {
3690
- await this.thread.client.rest.put(Routes14.channelThreadMember(this.thread.id, userId), {
4062
+ await this.thread.client.rest.put(Routes15.channelThreadMember(this.thread.id, userId), {
3691
4063
  auth: true
3692
4064
  });
3693
4065
  }
3694
4066
  /** Remove a user from this thread. */
3695
4067
  async remove(userId) {
3696
- await this.thread.client.rest.delete(Routes14.channelThreadMember(this.thread.id, userId), {
4068
+ await this.thread.client.rest.delete(Routes15.channelThreadMember(this.thread.id, userId), {
3697
4069
  auth: true
3698
4070
  });
3699
4071
  }
@@ -3718,7 +4090,7 @@ var ThreadManager = class {
3718
4090
  });
3719
4091
  }
3720
4092
  const data = await this.channel.client.rest.post(
3721
- Routes15.channelThreads(this.channel.id),
4093
+ Routes16.channelThreads(this.channel.id),
3722
4094
  {
3723
4095
  body: toStartThreadBody(this.channel.type, options),
3724
4096
  auth: true,
@@ -3751,7 +4123,7 @@ var ThreadManager = class {
3751
4123
  if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
3752
4124
  if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
3753
4125
  const data = await this.channel.client.rest.post(
3754
- Routes15.channelThreads(this.channel.id),
4126
+ Routes16.channelThreads(this.channel.id),
3755
4127
  {
3756
4128
  body,
3757
4129
  files: prepared.files,
@@ -3770,7 +4142,7 @@ var ThreadManager = class {
3770
4142
  * `before` is an ISO-8601 archive timestamp.
3771
4143
  */
3772
4144
  async fetchArchived(options) {
3773
- const path = options.type === "private" ? Routes15.channelThreadsArchivedPrivate(this.channel.id) : Routes15.channelThreadsArchivedPublic(this.channel.id);
4145
+ const path = options.type === "private" ? Routes16.channelThreadsArchivedPrivate(this.channel.id) : Routes16.channelThreadsArchivedPublic(this.channel.id);
3774
4146
  const data = await this.channel.client.rest.get(
3775
4147
  withQuery(path, { before: options.before, limit: options.limit })
3776
4148
  );
@@ -3782,7 +4154,7 @@ var ThreadManager = class {
3782
4154
  */
3783
4155
  async fetchJoinedPrivateArchived(options) {
3784
4156
  const data = await this.channel.client.rest.get(
3785
- withQuery(Routes15.channelJoinedArchivedPrivateThreads(this.channel.id), {
4157
+ withQuery(Routes16.channelJoinedArchivedPrivateThreads(this.channel.id), {
3786
4158
  before: options?.before,
3787
4159
  limit: options?.limit
3788
4160
  })
@@ -3795,7 +4167,7 @@ var ThreadManager = class {
3795
4167
  */
3796
4168
  async search(options) {
3797
4169
  const data = await this.channel.client.rest.get(
3798
- withQuery(Routes15.channelThreadSearch(this.channel.id), {
4170
+ withQuery(Routes16.channelThreadSearch(this.channel.id), {
3799
4171
  name: options?.name,
3800
4172
  tag: options?.tag,
3801
4173
  tag_setting: options?.tagSetting,
@@ -3823,7 +4195,7 @@ var ThreadManager = class {
3823
4195
  }
3824
4196
  /** Set the auto-archive and slowmode defaults copied onto new threads. */
3825
4197
  async editDefaults(options) {
3826
- return this.channel.client.rest.patch(Routes15.channel(this.channel.id), {
4198
+ return this.channel.client.rest.patch(Routes16.channel(this.channel.id), {
3827
4199
  body: toThreadParentEditBody(options),
3828
4200
  auth: true,
3829
4201
  ...auditReasonHeaders(options.reason)
@@ -3841,7 +4213,7 @@ function isSearchNotReady(data) {
3841
4213
  return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
3842
4214
  }
3843
4215
  async function fetchActiveThreads(client, guildId) {
3844
- const data = await client.rest.get(Routes15.guildActiveThreads(guildId));
4216
+ const data = await client.rest.get(Routes16.guildActiveThreads(guildId));
3845
4217
  return fetchedThreadsFrom(client, data);
3846
4218
  }
3847
4219
 
@@ -3900,7 +4272,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3900
4272
  * `defaultForumLayout` is sent only for forum channels.
3901
4273
  */
3902
4274
  async edit(options) {
3903
- const data = await this.client.rest.patch(Routes16.channel(this.id), {
4275
+ const data = await this.client.rest.patch(Routes17.channel(this.id), {
3904
4276
  body: {
3905
4277
  ...toChannelEditBody(options),
3906
4278
  ...forumParentWire(options, this.type === ChannelType7.GuildForum)
@@ -3929,7 +4301,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3929
4301
  }
3930
4302
  /** Set the auto-archive and slowmode defaults copied onto new posts. */
3931
4303
  async editThreadDefaults(options) {
3932
- const data = await this.client.rest.patch(Routes16.channel(this.id), {
4304
+ const data = await this.client.rest.patch(Routes17.channel(this.id), {
3933
4305
  body: toThreadParentEditBody(options),
3934
4306
  auth: true,
3935
4307
  ...auditReasonHeaders(options.reason)
@@ -3939,7 +4311,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3939
4311
  }
3940
4312
  /** Create a tag. The response replaces {@link availableTags}. */
3941
4313
  async createTag(options) {
3942
- const data = await this.client.rest.post(Routes16.channelTags(this.id), {
4314
+ const data = await this.client.rest.post(Routes17.channelTags(this.id), {
3943
4315
  body: toForumTagBody(options),
3944
4316
  auth: true,
3945
4317
  ...auditReasonHeaders(options.reason)
@@ -3949,7 +4321,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3949
4321
  }
3950
4322
  /** Replace a tag. The response replaces {@link availableTags}. */
3951
4323
  async editTag(tagId, options) {
3952
- const data = await this.client.rest.put(Routes16.channelTag(this.id, tagId), {
4324
+ const data = await this.client.rest.put(Routes17.channelTag(this.id, tagId), {
3953
4325
  body: toForumTagBody(options),
3954
4326
  auth: true,
3955
4327
  ...auditReasonHeaders(options.reason)
@@ -3959,7 +4331,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3959
4331
  }
3960
4332
  /** Delete a tag. The response replaces {@link availableTags}. */
3961
4333
  async deleteTag(tagId, reason) {
3962
- const data = await this.client.rest.delete(Routes16.channelTag(this.id, tagId), {
4334
+ const data = await this.client.rest.delete(Routes17.channelTag(this.id, tagId), {
3963
4335
  auth: true,
3964
4336
  ...auditReasonHeaders(reason)
3965
4337
  });
@@ -3994,6 +4366,7 @@ var GUILD_FACTORIES = {
3994
4366
  [ChannelType8.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
3995
4367
  [ChannelType8.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3996
4368
  [ChannelType8.GuildVoice]: (c, d) => new VoiceChannel(c, d),
4369
+ [ChannelType8.GuildStageVoice]: (c, d) => new StageChannel(c, d),
3997
4370
  [ChannelType8.GuildLink]: (c, d) => new LinkChannel(c, d),
3998
4371
  [ChannelType8.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
3999
4372
  [ChannelType8.PublicThread]: (c, d) => new ThreadChannel(c, d),
@@ -4047,12 +4420,15 @@ var User = class extends Base {
4047
4420
  system;
4048
4421
  /** Banner hash for profile. */
4049
4422
  banner;
4423
+ /** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
4424
+ partial;
4050
4425
  constructor(client, data) {
4051
4426
  super();
4052
4427
  this.client = client;
4053
4428
  this.id = data.id;
4054
- this.username = data.username;
4055
- this.discriminator = data.discriminator;
4429
+ this.partial = typeof data.username !== "string" || data.username.length === 0;
4430
+ this.username = data.username ?? "Unknown";
4431
+ this.discriminator = data.discriminator ?? "0";
4056
4432
  this.globalName = data.global_name ?? null;
4057
4433
  this.avatar = data.avatar ?? null;
4058
4434
  this.bot = !!data.bot;
@@ -4063,13 +4439,18 @@ var User = class extends Base {
4063
4439
  }
4064
4440
  /** @internal */
4065
4441
  _patch(data) {
4066
- this.username = data.username;
4067
- this.discriminator = data.discriminator;
4068
- this.globalName = data.global_name ?? null;
4069
- this.avatar = data.avatar ?? null;
4442
+ if (data.username !== void 0) this.username = data.username;
4443
+ if (data.discriminator !== void 0) this.discriminator = data.discriminator;
4444
+ if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
4445
+ if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
4070
4446
  if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
4071
4447
  if (data.flags !== void 0) this.flags = data.flags;
4072
4448
  if (data.banner !== void 0) this.banner = data.banner;
4449
+ if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
4450
+ }
4451
+ /** Fetch the full user from REST when this instance is a partial stub. */
4452
+ async fetch() {
4453
+ return this.client.users.fetch(this.id, { force: true });
4073
4454
  }
4074
4455
  cdnOpts() {
4075
4456
  return {
@@ -4107,11 +4488,11 @@ var User = class extends Base {
4107
4488
  */
4108
4489
  /** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
4109
4490
  get createdTimestamp() {
4110
- return SnowflakeUtil5.timestampFromSnowflake(this.id);
4491
+ return SnowflakeUtil6.timestampFromSnowflake(this.id);
4111
4492
  }
4112
4493
  /** Date when this account was created, derived from its snowflake ID. */
4113
4494
  get createdAt() {
4114
- return SnowflakeUtil5.dateFromSnowflake(this.id);
4495
+ return SnowflakeUtil6.dateFromSnowflake(this.id);
4115
4496
  }
4116
4497
  toString() {
4117
4498
  return `<@${this.id}>`;
@@ -4121,7 +4502,7 @@ var User = class extends Base {
4121
4502
  * @returns DM channel instance (cached if already open)
4122
4503
  */
4123
4504
  async createDM() {
4124
- const data = await this.client.rest.post(Routes17.userMeChannels(), {
4505
+ const data = await this.client.rest.post(Routes18.userMeChannels(), {
4125
4506
  body: { recipient_id: this.id },
4126
4507
  auth: true
4127
4508
  });
@@ -4338,14 +4719,14 @@ var CacheController = class {
4338
4719
 
4339
4720
  // src/ClientCore/ChannelManager.ts
4340
4721
  import { LimitedCollection } from "@fluxerjs/collection";
4341
- import { Routes as Routes23 } from "@fluxerjs/types";
4722
+ import { Routes as Routes24 } from "@fluxerjs/types";
4342
4723
 
4343
4724
  // src/Domain/Guild/Cache.ts
4344
4725
  import { ChannelType as ChannelType9 } from "@fluxerjs/types";
4345
4726
 
4346
4727
  // src/Domain/Guild/GuildEmoji.ts
4347
- import { Routes as Routes18 } from "@fluxerjs/types";
4348
- import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
4728
+ import { Routes as Routes19 } from "@fluxerjs/types";
4729
+ import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
4349
4730
  var GuildEmoji = class extends Base {
4350
4731
  client;
4351
4732
  id;
@@ -4381,11 +4762,11 @@ var GuildEmoji = class extends Base {
4381
4762
  }
4382
4763
  /** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
4383
4764
  get createdTimestamp() {
4384
- return SnowflakeUtil6.timestampFromSnowflake(this.id);
4765
+ return SnowflakeUtil7.timestampFromSnowflake(this.id);
4385
4766
  }
4386
4767
  /** Date when this emoji was created, derived from its snowflake ID. */
4387
4768
  get createdAt() {
4388
- return SnowflakeUtil6.dateFromSnowflake(this.id);
4769
+ return SnowflakeUtil7.dateFromSnowflake(this.id);
4389
4770
  }
4390
4771
  /** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
4391
4772
  toString() {
@@ -4393,7 +4774,7 @@ var GuildEmoji = class extends Base {
4393
4774
  }
4394
4775
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
4395
4776
  async delete(reason) {
4396
- await this.client.rest.delete(Routes18.guildEmoji(this.guildId, this.id), {
4777
+ await this.client.rest.delete(Routes19.guildEmoji(this.guildId, this.id), {
4397
4778
  auth: true,
4398
4779
  ...auditReasonHeaders(reason)
4399
4780
  });
@@ -4406,7 +4787,7 @@ var GuildEmoji = class extends Base {
4406
4787
  */
4407
4788
  async edit(options) {
4408
4789
  const { reason, name } = options;
4409
- const data = await this.client.rest.patch(Routes18.guildEmoji(this.guildId, this.id), {
4790
+ const data = await this.client.rest.patch(Routes19.guildEmoji(this.guildId, this.id), {
4410
4791
  body: { name },
4411
4792
  auth: true,
4412
4793
  ...auditReasonHeaders(reason)
@@ -4417,7 +4798,7 @@ var GuildEmoji = class extends Base {
4417
4798
  };
4418
4799
 
4419
4800
  // src/Domain/Guild/GuildMember.ts
4420
- import { Routes as Routes20 } from "@fluxerjs/types";
4801
+ import { Routes as Routes21 } from "@fluxerjs/types";
4421
4802
  import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
4422
4803
 
4423
4804
  // src/Helpers/Permissions.ts
@@ -4441,7 +4822,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
4441
4822
 
4442
4823
  // src/Domain/Guild/GuildMemberRoleManager.ts
4443
4824
  import { Collection as Collection7 } from "@fluxerjs/collection";
4444
- import { Routes as Routes19 } from "@fluxerjs/types";
4825
+ import { Routes as Routes20 } from "@fluxerjs/types";
4445
4826
  function roleId(roleOrId) {
4446
4827
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
4447
4828
  }
@@ -4470,7 +4851,7 @@ var GuildMemberRoleManager = class {
4470
4851
  const id = roleId(roleOrId);
4471
4852
  if (this.ids.includes(id)) return;
4472
4853
  await this.member.client.rest.put(
4473
- Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
4854
+ Routes20.guildMemberRole(this.member.guild.id, this.member.id, id)
4474
4855
  );
4475
4856
  this.ids.push(id);
4476
4857
  }
@@ -4479,13 +4860,13 @@ var GuildMemberRoleManager = class {
4479
4860
  const idx = this.ids.indexOf(id);
4480
4861
  if (idx === -1) return;
4481
4862
  await this.member.client.rest.delete(
4482
- Routes19.guildMemberRole(this.member.guild.id, this.member.id, id)
4863
+ Routes20.guildMemberRole(this.member.guild.id, this.member.id, id)
4483
4864
  );
4484
4865
  this.ids.splice(idx, 1);
4485
4866
  }
4486
4867
  async set(roleIds) {
4487
4868
  const data = await this.member.client.rest.patch(
4488
- Routes19.guildMember(this.member.guild.id, this.member.id),
4869
+ Routes20.guildMember(this.member.guild.id, this.member.id),
4489
4870
  { body: { roles: roleIds }, auth: true }
4490
4871
  );
4491
4872
  this.ids = data.roles ? [...data.roles] : [];
@@ -4639,7 +5020,7 @@ var GuildMember = class _GuildMember extends Base {
4639
5020
  */
4640
5021
  async edit(options) {
4641
5022
  const isMe = this.client.user?.id === this.id;
4642
- const route = isMe ? Routes20.guildMemberMe(this.guild.id) : Routes20.guildMember(this.guild.id, this.id);
5023
+ const route = isMe ? Routes21.guildMemberMe(this.guild.id) : Routes21.guildMember(this.guild.id, this.id);
4643
5024
  const data = await this.client.rest.patch(route, {
4644
5025
  body: toMemberEditBody(options),
4645
5026
  auth: true,
@@ -4752,8 +5133,8 @@ var GuildMember = class _GuildMember extends Base {
4752
5133
  };
4753
5134
 
4754
5135
  // src/Domain/Guild/GuildSticker.ts
4755
- import { Routes as Routes21 } from "@fluxerjs/types";
4756
- import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
5136
+ import { Routes as Routes22 } from "@fluxerjs/types";
5137
+ import { SnowflakeUtil as SnowflakeUtil8 } from "@fluxerjs/util";
4757
5138
  var GuildSticker = class extends Base {
4758
5139
  client;
4759
5140
  id;
@@ -4795,15 +5176,15 @@ var GuildSticker = class extends Base {
4795
5176
  }
4796
5177
  /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
4797
5178
  get createdTimestamp() {
4798
- return SnowflakeUtil7.timestampFromSnowflake(this.id);
5179
+ return SnowflakeUtil8.timestampFromSnowflake(this.id);
4799
5180
  }
4800
5181
  /** Date when this sticker was created, derived from its snowflake ID. */
4801
5182
  get createdAt() {
4802
- return SnowflakeUtil7.dateFromSnowflake(this.id);
5183
+ return SnowflakeUtil8.dateFromSnowflake(this.id);
4803
5184
  }
4804
5185
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
4805
5186
  async delete(reason) {
4806
- await this.client.rest.delete(Routes21.guildSticker(this.guildId, this.id), {
5187
+ await this.client.rest.delete(Routes22.guildSticker(this.guildId, this.id), {
4807
5188
  auth: true,
4808
5189
  ...auditReasonHeaders(reason)
4809
5190
  });
@@ -4816,7 +5197,7 @@ var GuildSticker = class extends Base {
4816
5197
  */
4817
5198
  async edit(options) {
4818
5199
  const { reason, ...body } = options;
4819
- const data = await this.client.rest.patch(Routes21.guildSticker(this.guildId, this.id), {
5200
+ const data = await this.client.rest.patch(Routes22.guildSticker(this.guildId, this.id), {
4820
5201
  body,
4821
5202
  auth: true,
4822
5203
  ...auditReasonHeaders(reason)
@@ -4829,12 +5210,12 @@ var GuildSticker = class extends Base {
4829
5210
  };
4830
5211
 
4831
5212
  // src/Domain/Guild/Role.ts
4832
- import { Routes as Routes22 } from "@fluxerjs/types";
5213
+ import { Routes as Routes23 } from "@fluxerjs/types";
4833
5214
  import {
4834
5215
  ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
4835
5216
  PermissionFlags as PermissionFlags4,
4836
5217
  PermissionsBitField as PermissionsBitField3,
4837
- SnowflakeUtil as SnowflakeUtil8
5218
+ SnowflakeUtil as SnowflakeUtil9
4838
5219
  } from "@fluxerjs/util";
4839
5220
  var Role = class _Role extends Base {
4840
5221
  /** Parent client instance. */
@@ -4857,6 +5238,8 @@ var Role = class _Role extends Base {
4857
5238
  mentionable;
4858
5239
  /** Unicode emoji for this role (null = none). */
4859
5240
  unicodeEmoji;
5241
+ /** Role icon image hash (null = none). */
5242
+ icon;
4860
5243
  /** Hoist position (null = not hoisted). */
4861
5244
  hoistPosition;
4862
5245
  constructor(client, data, guildId) {
@@ -4864,20 +5247,26 @@ var Role = class _Role extends Base {
4864
5247
  this.client = client;
4865
5248
  this.id = data.id;
4866
5249
  this.guildId = guildId;
4867
- this.name = data.name;
4868
- this.color = data.color;
4869
- this.position = data.position;
4870
- this._permissions = data.permissions;
5250
+ this.name = data.name ?? "";
5251
+ this.color = data.color ?? 0;
5252
+ this.position = data.position ?? 0;
5253
+ this._permissions = data.permissions ?? "0";
4871
5254
  this.hoist = !!data.hoist;
4872
5255
  this.mentionable = !!data.mentionable;
4873
5256
  this.unicodeEmoji = data.unicode_emoji ?? null;
5257
+ this.icon = data.icon ?? null;
4874
5258
  this.hoistPosition = data.hoist_position ?? null;
4875
5259
  }
4876
5260
  /**
4877
5261
  * Permissions bitfield (Administrator grants all permissions).
4878
5262
  */
4879
5263
  get permissions() {
4880
- const bits = BigInt(this._permissions);
5264
+ let bits;
5265
+ try {
5266
+ bits = BigInt(this._permissions ?? "0");
5267
+ } catch {
5268
+ bits = 0n;
5269
+ }
4881
5270
  return new PermissionsBitField3(
4882
5271
  (bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
4883
5272
  );
@@ -4896,25 +5285,26 @@ var Role = class _Role extends Base {
4896
5285
  */
4897
5286
  /** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
4898
5287
  get createdTimestamp() {
4899
- return SnowflakeUtil8.timestampFromSnowflake(this.id);
5288
+ return SnowflakeUtil9.timestampFromSnowflake(this.id);
4900
5289
  }
4901
5290
  /** Date when this role was created, derived from its snowflake ID. */
4902
5291
  get createdAt() {
4903
- return SnowflakeUtil8.dateFromSnowflake(this.id);
5292
+ return SnowflakeUtil9.dateFromSnowflake(this.id);
4904
5293
  }
4905
5294
  toString() {
4906
5295
  return `<@&${this.id}>`;
4907
5296
  }
4908
5297
  /** @internal */
4909
5298
  _patch(data) {
4910
- this.name = data.name;
4911
- this.color = data.color;
4912
- this.position = data.position;
4913
- this._permissions = data.permissions;
4914
- this.hoist = !!data.hoist;
4915
- this.mentionable = !!data.mentionable;
4916
- this.unicodeEmoji = data.unicode_emoji ?? null;
4917
- this.hoistPosition = data.hoist_position ?? null;
5299
+ if (data.name !== void 0) this.name = data.name;
5300
+ if (data.color !== void 0) this.color = data.color;
5301
+ if (data.position !== void 0) this.position = data.position;
5302
+ if (data.permissions !== void 0) this._permissions = data.permissions;
5303
+ if (data.hoist !== void 0) this.hoist = !!data.hoist;
5304
+ if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
5305
+ if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
5306
+ if (data.icon !== void 0) this.icon = data.icon ?? null;
5307
+ if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
4918
5308
  }
4919
5309
  /**
4920
5310
  * Snapshot for role-update events (before in-place patch).
@@ -4932,6 +5322,7 @@ var Role = class _Role extends Base {
4932
5322
  hoist: this.hoist,
4933
5323
  mentionable: this.mentionable,
4934
5324
  unicode_emoji: this.unicodeEmoji,
5325
+ icon: this.icon,
4935
5326
  hoist_position: this.hoistPosition
4936
5327
  },
4937
5328
  this.guildId
@@ -4944,7 +5335,7 @@ var Role = class _Role extends Base {
4944
5335
  */
4945
5336
  async edit(options) {
4946
5337
  const body = toRoleEditBody(options);
4947
- const data = await this.client.rest.patch(Routes22.guildRole(this.guildId, this.id), {
5338
+ const data = await this.client.rest.patch(Routes23.guildRole(this.guildId, this.id), {
4948
5339
  body: Object.keys(body).length ? body : void 0,
4949
5340
  auth: true,
4950
5341
  ...auditReasonHeaders(options.reason)
@@ -4957,7 +5348,7 @@ var Role = class _Role extends Base {
4957
5348
  * @param reason - Audit log reason (`X-Audit-Log-Reason`)
4958
5349
  */
4959
5350
  async delete(reason) {
4960
- await this.client.rest.delete(Routes22.guildRole(this.guildId, this.id), {
5351
+ await this.client.rest.delete(Routes23.guildRole(this.guildId, this.id), {
4961
5352
  auth: true,
4962
5353
  ...auditReasonHeaders(reason)
4963
5354
  });
@@ -5109,6 +5500,7 @@ var ChannelManager = class extends LimitedCollection {
5109
5500
  });
5110
5501
  this.client = client;
5111
5502
  }
5503
+ pendingFetches = /* @__PURE__ */ new Map();
5112
5504
  /**
5113
5505
  * Remove a channel from cache. Does not delete it on the API.
5114
5506
  * Use {@link Channel.delete} after {@link fetch} to delete the channel.
@@ -5121,9 +5513,11 @@ var ChannelManager = class extends LimitedCollection {
5121
5513
  }
5122
5514
  return deleted;
5123
5515
  }
5124
- /** Retrieve from cache, otherwise {@link fetch}. */
5516
+ /** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
5125
5517
  async resolve(channelId) {
5126
- return this.get(channelId) ?? this.fetch(channelId);
5518
+ const id = normalizeSnowflakeId(channelId, "channels.resolve()");
5519
+ const cached = this.get(id);
5520
+ return cached && !cached.partial ? cached : this.fetch(id);
5127
5521
  }
5128
5522
  /**
5129
5523
  * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
@@ -5136,10 +5530,23 @@ var ChannelManager = class extends LimitedCollection {
5136
5530
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
5137
5531
  */
5138
5532
  async fetch(channelId, options) {
5139
- const cached = this.get(channelId);
5140
- if (cached && !options?.force) return cached;
5533
+ const id = normalizeSnowflakeId(channelId, "channels.fetch()");
5534
+ const cached = this.get(id);
5535
+ if (cached && !cached.partial && !options?.force) return cached;
5536
+ return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
5537
+ }
5538
+ async fetchFresh(channelId) {
5141
5539
  try {
5142
- const data = await this.client.rest.get(Routes23.channel(channelId));
5540
+ const data = assertApiObjectWithId(
5541
+ await this.client.rest.get(Routes24.channel(channelId)),
5542
+ "channels.fetch()"
5543
+ );
5544
+ const existing = this.get(channelId);
5545
+ if (existing && existing.type === data.type) {
5546
+ existing._patch(data);
5547
+ putChannel(this.client, existing);
5548
+ return existing;
5549
+ }
5143
5550
  const guildId = "guild_id" in data ? data.guild_id : void 0;
5144
5551
  if (guildId) {
5145
5552
  const guild = this.client.guilds.get(guildId);
@@ -5184,7 +5591,7 @@ var ChannelManager = class extends LimitedCollection {
5184
5591
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
5185
5592
  });
5186
5593
  const data = await this.client.rest.post(
5187
- Routes23.channelMessages(channelId),
5594
+ Routes24.channelMessages(channelId),
5188
5595
  postPayload
5189
5596
  );
5190
5597
  this.client._addMessageToCache(channelId, data);
@@ -5194,7 +5601,7 @@ var ChannelManager = class extends LimitedCollection {
5194
5601
 
5195
5602
  // src/ClientCore/ClientEmoji.ts
5196
5603
  import { Collection as Collection8 } from "@fluxerjs/collection";
5197
- import { Routes as Routes24 } from "@fluxerjs/types";
5604
+ import { Routes as Routes25 } from "@fluxerjs/types";
5198
5605
  import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
5199
5606
  async function resolveClientEmoji(client, emoji, guildId) {
5200
5607
  if (typeof emoji === "object" && emoji.id) {
@@ -5213,7 +5620,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
5213
5620
  const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
5214
5621
  if (unicodeFromShortcode) return unicodeFromShortcode;
5215
5622
  if (guildId) {
5216
- const emojis = await client.rest.get(Routes24.guildEmojis(guildId));
5623
+ const emojis = await client.rest.get(Routes25.guildEmojis(guildId));
5217
5624
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
5218
5625
  if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
5219
5626
  throw new FluxerError(
@@ -5230,26 +5637,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
5230
5637
  return parsed.name;
5231
5638
  }
5232
5639
  async function fetchInstance(client) {
5233
- const raw = await client.rest.get(Routes24.instanceDiscovery(), {
5640
+ const raw = await client.rest.get(Routes25.instanceDiscovery(), {
5234
5641
  auth: false,
5235
5642
  unversioned: true
5236
5643
  });
5237
5644
  return parseInstanceDiscovery(raw);
5238
5645
  }
5239
5646
  function fetchGatewayInfo(client) {
5240
- return client.rest.get(Routes24.gatewayBot());
5647
+ return client.rest.get(Routes25.gatewayBot());
5241
5648
  }
5242
5649
  function fetchEmojiMetadata(client, emojiId) {
5243
- return client.rest.get(Routes24.emojiMetadata(emojiId), { auth: true });
5650
+ return client.rest.get(Routes25.emojiMetadata(emojiId), { auth: true });
5244
5651
  }
5245
5652
  function fetchStickerMetadata(client, stickerId) {
5246
- return client.rest.get(Routes24.stickerMetadata(stickerId), { auth: true });
5653
+ return client.rest.get(Routes25.stickerMetadata(stickerId), { auth: true });
5247
5654
  }
5248
5655
  function fetchApplication(client) {
5249
- return client.rest.get(Routes24.applicationsMe(), { auth: true });
5656
+ return client.rest.get(Routes25.applicationsMe(), { auth: true });
5250
5657
  }
5251
5658
  async function fetchOAuthApplications(client) {
5252
- const data = await client.rest.get(Routes24.oauth2ApplicationsMe(), { auth: true });
5659
+ const data = await client.rest.get(Routes25.oauth2ApplicationsMe(), { auth: true });
5253
5660
  if (Array.isArray(data)) return data;
5254
5661
  if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
5255
5662
  return data.applications;
@@ -5268,14 +5675,14 @@ function assertChannelIdBatch(name, channelIds) {
5268
5675
  }
5269
5676
  function preloadMessages(client, channelIds) {
5270
5677
  assertChannelIdBatch("preloadMessages", channelIds);
5271
- return client.rest.post(Routes24.preloadMessages(), {
5678
+ return client.rest.post(Routes25.preloadMessages(), {
5272
5679
  body: { channels: channelIds },
5273
5680
  auth: true
5274
5681
  });
5275
5682
  }
5276
5683
  function preloadMessagesAlt(client, channelIds) {
5277
5684
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
5278
- return client.rest.post(Routes24.preloadMessagesAlt(), {
5685
+ return client.rest.post(Routes25.preloadMessagesAlt(), {
5279
5686
  body: { channels: channelIds },
5280
5687
  auth: true
5281
5688
  });
@@ -5283,7 +5690,7 @@ function preloadMessagesAlt(client, channelIds) {
5283
5690
  async function bulkFetchMessages(client, requests, options = {}) {
5284
5691
  validateBulkMessageFetchRequests(requests);
5285
5692
  const wire = toBulkFetchWire(requests);
5286
- const data = await client.rest.post(Routes24.channelsMessagesBulk(), {
5693
+ const data = await client.rest.post(Routes25.channelsMessagesBulk(), {
5287
5694
  body: { requests: wire },
5288
5695
  auth: true
5289
5696
  });
@@ -5300,12 +5707,74 @@ async function bulkFetchMessages(client, requests, options = {}) {
5300
5707
  };
5301
5708
  }
5302
5709
  async function searchMessages(client, options = {}) {
5303
- const data = await client.rest.post(Routes24.searchMessages(), {
5710
+ const data = await client.rest.post(Routes25.searchMessages(), {
5304
5711
  body: toMessageSearchBody(options),
5305
5712
  auth: true
5306
5713
  });
5307
5714
  return toMessageSearchResponse(data);
5308
5715
  }
5716
+ function fetchEmojiSource(client, emojiId) {
5717
+ return client.rest.get(
5718
+ Routes25.emojiSource(emojiId),
5719
+ { auth: true }
5720
+ );
5721
+ }
5722
+ function fetchStickerSource(client, stickerId) {
5723
+ return client.rest.get(
5724
+ Routes25.stickerSource(stickerId),
5725
+ { auth: true }
5726
+ );
5727
+ }
5728
+ function fetchDiscoveryCategories(client) {
5729
+ return client.rest.get(
5730
+ Routes25.discoveryCategories(),
5731
+ { auth: true }
5732
+ );
5733
+ }
5734
+ function searchDiscoveryGuilds(client, options = {}) {
5735
+ const params = new URLSearchParams();
5736
+ if (options.query !== void 0) params.set("query", options.query);
5737
+ if (options.category !== void 0) params.set("category", String(options.category));
5738
+ if (options.language !== void 0) params.set("language", options.language);
5739
+ if (options.tag !== void 0) params.set("tag", options.tag);
5740
+ if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
5741
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5742
+ if (options.offset !== void 0) params.set("offset", String(options.offset));
5743
+ const qs2 = params.toString();
5744
+ return client.rest.get(
5745
+ qs2 ? `${Routes25.discoveryGuilds()}?${qs2}` : Routes25.discoveryGuilds(),
5746
+ { auth: true }
5747
+ );
5748
+ }
5749
+ function fetchExperiments(client) {
5750
+ return client.rest.get(Routes25.experiments(), {
5751
+ auth: true
5752
+ });
5753
+ }
5754
+ function refreshAttachmentUrls(client, attachmentUrls) {
5755
+ return client.rest.post(
5756
+ Routes25.attachmentsRefreshUrls(),
5757
+ { body: { attachment_urls: attachmentUrls }, auth: true }
5758
+ );
5759
+ }
5760
+ function fetchInstanceBadges(client, options = {}) {
5761
+ const params = new URLSearchParams();
5762
+ if (options.ids !== void 0) params.set("ids", options.ids);
5763
+ if (options.after !== void 0) params.set("after", options.after);
5764
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5765
+ if (options.version !== void 0) params.set("version", options.version);
5766
+ const qs2 = params.toString();
5767
+ return client.rest.get(
5768
+ qs2 ? `${Routes25.instanceBadges()}?${qs2}` : Routes25.instanceBadges(),
5769
+ { auth: false }
5770
+ );
5771
+ }
5772
+ function fetchChannelPostData(client, channelId, threadIds) {
5773
+ return client.rest.post(
5774
+ Routes25.channelPostData(channelId),
5775
+ { body: { thread_ids: threadIds }, auth: true }
5776
+ );
5777
+ }
5309
5778
 
5310
5779
  // src/ClientCore/ClientEvents.ts
5311
5780
  function createEventMethods(client) {
@@ -5324,18 +5793,19 @@ function createEventMethods(client) {
5324
5793
  import { GatewayCloseCodes, WebSocketManager } from "@fluxerjs/ws";
5325
5794
 
5326
5795
  // src/Domain/Guild/Guild.ts
5327
- import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
5796
+ import { Collection as Collection9, LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
5328
5797
  import { GuildNSFWLevel } from "@fluxerjs/types";
5329
- import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
5798
+ import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
5330
5799
 
5331
5800
  // src/ClientCore/GuildMemberManager.ts
5332
5801
  import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
5333
- import { Routes as Routes25 } from "@fluxerjs/types";
5802
+ import { Routes as Routes26 } from "@fluxerjs/types";
5334
5803
  var GuildMemberManager = class extends LimitedCollection2 {
5335
5804
  constructor(guild) {
5336
5805
  super({ maxSize: guild.client.cache.limits.members });
5337
5806
  this.guild = guild;
5338
5807
  }
5808
+ pendingFetches = /* @__PURE__ */ new Map();
5339
5809
  /**
5340
5810
  * Get a guild member from cache or fetch from the API if not present.
5341
5811
  * Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
@@ -5347,7 +5817,9 @@ var GuildMemberManager = class extends LimitedCollection2 {
5347
5817
  * console.log(member.displayName);
5348
5818
  */
5349
5819
  async resolve(userId) {
5350
- return this.get(userId) ?? this.fetch(userId);
5820
+ const id = normalizeSnowflakeId(userId, "members.resolve()");
5821
+ const cached = this.get(id);
5822
+ return cached && !cached.user.partial ? cached : this.fetch(id);
5351
5823
  }
5352
5824
  /**
5353
5825
  * The current bot user as a GuildMember in this guild.
@@ -5375,10 +5847,11 @@ var GuildMemberManager = class extends LimitedCollection2 {
5375
5847
  return this.guild.fetchMe();
5376
5848
  }
5377
5849
  async fetch(userIdOrOptions, options) {
5378
- if (typeof userIdOrOptions === "string") {
5379
- const cached = this.get(userIdOrOptions);
5380
- if (cached && !options?.force) return cached;
5381
- return this.guild.fetchMember(userIdOrOptions);
5850
+ if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
5851
+ const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
5852
+ const cached = this.get(id);
5853
+ if (cached && !cached.user.partial && !options?.force) return cached;
5854
+ return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
5382
5855
  }
5383
5856
  return this.fetchMany(userIdOrOptions);
5384
5857
  }
@@ -5387,10 +5860,14 @@ var GuildMemberManager = class extends LimitedCollection2 {
5387
5860
  if (options?.limit != null) params.set("limit", String(options.limit));
5388
5861
  if (options?.after) params.set("after", options.after);
5389
5862
  const qs2 = params.toString();
5390
- const url = Routes25.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5391
- const data = await this.guild.client.rest.get(url, { auth: true });
5863
+ const url = Routes26.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5864
+ const data = assertApiArray(
5865
+ await this.guild.client.rest.get(url, { auth: true }),
5866
+ "members.fetch()"
5867
+ );
5392
5868
  const members = [];
5393
5869
  for (const m of data) {
5870
+ if (!m?.user?.id) continue;
5394
5871
  const member = new GuildMember(
5395
5872
  this.guild.client,
5396
5873
  { ...m, guild_id: this.guild.id },
@@ -5410,7 +5887,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
5410
5887
  */
5411
5888
  async search(options = {}) {
5412
5889
  const data = await this.guild.client.rest.post(
5413
- Routes25.guildMembersSearch(this.guild.id),
5890
+ Routes26.guildMembersSearch(this.guild.id),
5414
5891
  { body: toMemberSearchBody(options), auth: true }
5415
5892
  );
5416
5893
  const offset = options.offset ?? 0;
@@ -5436,7 +5913,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
5436
5913
  };
5437
5914
 
5438
5915
  // src/Domain/Guild/Admin.ts
5439
- import { Routes as Routes26 } from "@fluxerjs/types";
5916
+ import { Routes as Routes27 } from "@fluxerjs/types";
5440
5917
  function toAuditLogEntryPayload(entry, guildId) {
5441
5918
  return {
5442
5919
  id: entry.id,
@@ -5457,7 +5934,7 @@ function toVanityPayload(data) {
5457
5934
  return { code: data.code ?? null, uses: data.uses };
5458
5935
  }
5459
5936
  async function fetchAuditLogs(guild, options) {
5460
- const url = Routes26.guildAuditLogs(guild.id) + qs({
5937
+ const url = Routes27.guildAuditLogs(guild.id) + qs({
5461
5938
  limit: options?.limit,
5462
5939
  before: options?.before,
5463
5940
  after: options?.after,
@@ -5481,7 +5958,7 @@ async function fetchAuditLogs(guild, options) {
5481
5958
  };
5482
5959
  }
5483
5960
  async function editGuild(guild, options) {
5484
- const data = await guild.client.rest.patch(Routes26.guild(guild.id), {
5961
+ const data = await guild.client.rest.patch(Routes27.guild(guild.id), {
5485
5962
  body: toGuildEditBody(options),
5486
5963
  auth: true
5487
5964
  });
@@ -5489,13 +5966,13 @@ async function editGuild(guild, options) {
5489
5966
  return guild;
5490
5967
  }
5491
5968
  async function fetchVanityURL(guild) {
5492
- const data = await guild.client.rest.get(Routes26.guildVanityUrl(guild.id), {
5969
+ const data = await guild.client.rest.get(Routes27.guildVanityUrl(guild.id), {
5493
5970
  auth: true
5494
5971
  });
5495
5972
  return toVanityPayload(data);
5496
5973
  }
5497
5974
  async function editVanityURL(guild, code) {
5498
- const data = await guild.client.rest.patch(Routes26.guildVanityUrl(guild.id), {
5975
+ const data = await guild.client.rest.patch(Routes27.guildVanityUrl(guild.id), {
5499
5976
  body: { code },
5500
5977
  auth: true
5501
5978
  });
@@ -5503,14 +5980,14 @@ async function editVanityURL(guild, code) {
5503
5980
  return toVanityPayload(data);
5504
5981
  }
5505
5982
  async function fetchDiscoveryStatus(guild) {
5506
- const data = await guild.client.rest.get(Routes26.guildDiscovery(guild.id), {
5983
+ const data = await guild.client.rest.get(Routes27.guildDiscovery(guild.id), {
5507
5984
  auth: true
5508
5985
  });
5509
5986
  return toDiscoveryStatusPayload(data);
5510
5987
  }
5511
5988
  async function applyForDiscovery(guild, options) {
5512
5989
  const data = await guild.client.rest.post(
5513
- Routes26.guildDiscovery(guild.id),
5990
+ Routes27.guildDiscovery(guild.id),
5514
5991
  {
5515
5992
  body: toDiscoveryBody(options),
5516
5993
  auth: true
@@ -5520,7 +5997,7 @@ async function applyForDiscovery(guild, options) {
5520
5997
  }
5521
5998
  async function editDiscoveryApplication(guild, options) {
5522
5999
  const data = await guild.client.rest.patch(
5523
- Routes26.guildDiscovery(guild.id),
6000
+ Routes27.guildDiscovery(guild.id),
5524
6001
  {
5525
6002
  body: toDiscoveryBody(options),
5526
6003
  auth: true
@@ -5529,34 +6006,39 @@ async function editDiscoveryApplication(guild, options) {
5529
6006
  return toDiscoveryApplicationPayload(data);
5530
6007
  }
5531
6008
  async function withdrawDiscoveryApplication(guild) {
5532
- await guild.client.rest.delete(Routes26.guildDiscovery(guild.id), { auth: true });
6009
+ await guild.client.rest.delete(Routes27.guildDiscovery(guild.id), { auth: true });
5533
6010
  }
5534
6011
  async function deleteGuild(guild, options) {
5535
6012
  const body = options ? toSudoBody(options) : {};
5536
- await guild.client.rest.post(Routes26.guildDelete(guild.id), {
6013
+ await guild.client.rest.post(Routes27.guildDelete(guild.id), {
5537
6014
  body,
5538
6015
  auth: true
5539
6016
  });
5540
6017
  guild.client.guilds.delete(guild.id);
5541
6018
  }
5542
6019
  async function transferOwnership(guild, newOwnerId, password) {
5543
- await guild.client.rest.post(Routes26.guildTransferOwnership(guild.id), {
6020
+ await guild.client.rest.post(Routes27.guildTransferOwnership(guild.id), {
5544
6021
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
5545
6022
  auth: true
5546
6023
  });
5547
6024
  }
5548
6025
 
5549
6026
  // src/Domain/Guild/Channels.ts
5550
- import { Routes as Routes27 } from "@fluxerjs/types";
6027
+ import { Routes as Routes28 } from "@fluxerjs/types";
5551
6028
  async function createChannel(guild, options) {
5552
- const created = await guild.client.rest.post(Routes27.guildChannels(guild.id), {
6029
+ const created = await guild.client.rest.post(Routes28.guildChannels(guild.id), {
5553
6030
  body: toChannelCreateBody(options),
5554
6031
  auth: true
5555
6032
  });
5556
6033
  return cacheChannel(guild, created);
5557
6034
  }
5558
6035
  async function fetchChannels(guild) {
5559
- const data = await guild.client.rest.get(Routes27.guildChannels(guild.id));
6036
+ const raw = await guild.client.rest.get(Routes28.guildChannels(guild.id));
6037
+ if (!Array.isArray(raw))
6038
+ throw new TypeError(
6039
+ "guild.fetchChannels() received an invalid API payload (expected an array)"
6040
+ );
6041
+ const data = raw;
5560
6042
  const channels = [];
5561
6043
  for (const ch of data) {
5562
6044
  const channel = cacheChannel(guild, ch);
@@ -5565,17 +6047,17 @@ async function fetchChannels(guild) {
5565
6047
  return channels;
5566
6048
  }
5567
6049
  async function setChannelPositions(guild, updates) {
5568
- await guild.client.rest.patch(Routes27.guildChannels(guild.id), {
6050
+ await guild.client.rest.patch(Routes28.guildChannels(guild.id), {
5569
6051
  body: toChannelPositionBody(updates),
5570
6052
  auth: true
5571
6053
  });
5572
6054
  }
5573
6055
  async function fetchWebhooks(guild) {
5574
- const data = await guild.client.rest.get(Routes27.guildWebhooks(guild.id));
6056
+ const data = await guild.client.rest.get(Routes28.guildWebhooks(guild.id));
5575
6057
  return data.map((w) => new Webhook(guild.client, w));
5576
6058
  }
5577
6059
  async function fetchInvites(guild) {
5578
- const data = await guild.client.rest.get(Routes27.guildInvites(guild.id));
6060
+ const data = await guild.client.rest.get(Routes28.guildInvites(guild.id));
5579
6061
  return data.map((invite) => new Invite(guild.client, invite));
5580
6062
  }
5581
6063
  async function fetchInvite(guild, codeOrUrl) {
@@ -5595,14 +6077,14 @@ function resolveGuildOnlineCount(data) {
5595
6077
  }
5596
6078
 
5597
6079
  // src/Domain/Guild/Emojis.ts
5598
- import { Routes as Routes28 } from "@fluxerjs/types";
6080
+ import { Routes as Routes29 } from "@fluxerjs/types";
5599
6081
  async function fetchEmojis(guild) {
5600
- const data = await guild.client.rest.get(Routes28.guildEmojis(guild.id));
6082
+ const data = await guild.client.rest.get(Routes29.guildEmojis(guild.id));
5601
6083
  return data.map((e) => cacheEmoji(guild, e));
5602
6084
  }
5603
6085
  async function fetchEmoji(guild, emojiId) {
5604
6086
  try {
5605
- const data = await guild.client.rest.get(Routes28.guildEmoji(guild.id, emojiId));
6087
+ const data = await guild.client.rest.get(Routes29.guildEmoji(guild.id, emojiId));
5606
6088
  return cacheEmoji(guild, data);
5607
6089
  } catch (err) {
5608
6090
  rethrowMapped(err, {
@@ -5613,7 +6095,7 @@ async function fetchEmoji(guild, emojiId) {
5613
6095
  }
5614
6096
  async function createEmoji(guild, options) {
5615
6097
  const { reason, ...body } = options;
5616
- const data = await guild.client.rest.post(Routes28.guildEmojis(guild.id), {
6098
+ const data = await guild.client.rest.post(Routes29.guildEmojis(guild.id), {
5617
6099
  body,
5618
6100
  auth: true,
5619
6101
  ...auditReasonHeaders(reason)
@@ -5621,7 +6103,7 @@ async function createEmoji(guild, options) {
5621
6103
  return cacheEmoji(guild, data);
5622
6104
  }
5623
6105
  async function cloneEmoji(guild, sourceEmojiId) {
5624
- const data = await guild.client.rest.post(Routes28.guildEmojisClone(guild.id), {
6106
+ const data = await guild.client.rest.post(Routes29.guildEmojisClone(guild.id), {
5625
6107
  body: { source_emoji_id: sourceEmojiId },
5626
6108
  auth: true
5627
6109
  });
@@ -5629,7 +6111,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
5629
6111
  }
5630
6112
  async function createEmojisBulk(guild, emojis) {
5631
6113
  const data = await guild.client.rest.post(
5632
- Routes28.guildEmojisBulk(guild.id),
6114
+ Routes29.guildEmojisBulk(guild.id),
5633
6115
  { body: { emojis }, auth: true }
5634
6116
  );
5635
6117
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
@@ -5649,18 +6131,22 @@ var GuildRoleManager = class extends LimitedCollection3 {
5649
6131
  };
5650
6132
 
5651
6133
  // src/Domain/Guild/MemberHttp.ts
5652
- import { Routes as Routes29 } from "@fluxerjs/types";
6134
+ import { Routes as Routes30 } from "@fluxerjs/types";
5653
6135
  async function fetchMember(guild, userId) {
6136
+ const id = normalizeSnowflakeId(userId, "members.fetch()");
5654
6137
  try {
5655
6138
  const data = await guild.client.rest.get(
5656
- Routes29.guildMember(guild.id, userId)
6139
+ Routes30.guildMember(guild.id, id)
5657
6140
  );
6141
+ if (!data?.user?.id) {
6142
+ throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
6143
+ }
5658
6144
  return cacheMember(guild, data);
5659
6145
  } catch (err) {
5660
6146
  rethrowMapped(err, {
5661
6147
  notFound: {
5662
6148
  code: ErrorCodes.MemberNotFound,
5663
- message: `Member ${userId} not found in guild`
6149
+ message: `Member ${id} not found in guild`
5664
6150
  },
5665
6151
  fallback: "Failed to fetch guild member"
5666
6152
  });
@@ -5668,17 +6154,20 @@ async function fetchMember(guild, userId) {
5668
6154
  }
5669
6155
  async function fetchMe(guild) {
5670
6156
  const data = await guild.client.rest.get(
5671
- Routes29.guildMemberMe(guild.id),
6157
+ Routes30.guildMemberMe(guild.id),
5672
6158
  { auth: true }
5673
6159
  );
6160
+ if (!data?.user?.id) {
6161
+ throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
6162
+ }
5674
6163
  return cacheMember(guild, data);
5675
6164
  }
5676
6165
 
5677
6166
  // src/Domain/Guild/Moderation.ts
5678
- import { Routes as Routes31 } from "@fluxerjs/types";
6167
+ import { Routes as Routes32 } from "@fluxerjs/types";
5679
6168
 
5680
6169
  // src/Domain/Guild/GuildBan.ts
5681
- import { Routes as Routes30 } from "@fluxerjs/types";
6170
+ import { Routes as Routes31 } from "@fluxerjs/types";
5682
6171
  function parseOptionalDate2(value) {
5683
6172
  if (value == null || value === "") return null;
5684
6173
  const date = new Date(value);
@@ -5705,7 +6194,7 @@ var GuildBan = class extends Base {
5705
6194
  * Requires Ban Members permission.
5706
6195
  */
5707
6196
  async unban(reason) {
5708
- await this.client.rest.delete(Routes30.guildBan(this.guildId, this.user.id), {
6197
+ await this.client.rest.delete(Routes31.guildBan(this.guildId, this.user.id), {
5709
6198
  auth: true,
5710
6199
  ...auditReasonHeaders(reason)
5711
6200
  });
@@ -5715,35 +6204,39 @@ var GuildBan = class extends Base {
5715
6204
  // src/Domain/Guild/Moderation.ts
5716
6205
  async function ban(guild, userId, options) {
5717
6206
  const body = options ? toGuildBanBody(options) : {};
5718
- await guild.client.rest.put(Routes31.guildBan(guild.id, userId), {
6207
+ await guild.client.rest.put(Routes32.guildBan(guild.id, userId), {
5719
6208
  body: Object.keys(body).length ? body : void 0,
5720
6209
  auth: true,
5721
6210
  ...auditReasonHeaders(options?.reason)
5722
6211
  });
5723
6212
  }
6213
+ async function fetchBan(guild, userId) {
6214
+ const data = await guild.client.rest.get(Routes32.guildBan(guild.id, userId));
6215
+ return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
6216
+ }
5724
6217
  async function fetchBans(guild) {
5725
- const data = await guild.client.rest.get(Routes31.guildBans(guild.id));
6218
+ const data = await guild.client.rest.get(Routes32.guildBans(guild.id));
5726
6219
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
5727
6220
  }
5728
6221
  async function unban(guild, userId, reason) {
5729
- await guild.client.rest.delete(Routes31.guildBan(guild.id, userId), {
6222
+ await guild.client.rest.delete(Routes32.guildBan(guild.id, userId), {
5730
6223
  auth: true,
5731
6224
  ...auditReasonHeaders(reason)
5732
6225
  });
5733
6226
  }
5734
6227
  async function kick(guild, userId, reason) {
5735
- await guild.client.rest.delete(Routes31.guildMember(guild.id, userId), {
6228
+ await guild.client.rest.delete(Routes32.guildMember(guild.id, userId), {
5736
6229
  auth: true,
5737
6230
  ...auditReasonHeaders(reason)
5738
6231
  });
5739
6232
  }
5740
6233
 
5741
6234
  // src/Domain/Guild/Roles.ts
5742
- import { Routes as Routes32 } from "@fluxerjs/types";
6235
+ import { Routes as Routes33 } from "@fluxerjs/types";
5743
6236
  import { parseRoleMention } from "@fluxerjs/util";
5744
6237
  async function createRole(guild, options = {}) {
5745
6238
  const body = toRoleCreateBody(options);
5746
- const data = await guild.client.rest.post(Routes32.guildRoles(guild.id), {
6239
+ const data = await guild.client.rest.post(Routes33.guildRoles(guild.id), {
5747
6240
  body: Object.keys(body).length ? body : void 0,
5748
6241
  auth: true,
5749
6242
  ...auditReasonHeaders(options.reason)
@@ -5751,12 +6244,14 @@ async function createRole(guild, options = {}) {
5751
6244
  return cacheRole(guild, data);
5752
6245
  }
5753
6246
  async function fetchRoles(guild) {
5754
- const data = await guild.client.rest.get(Routes32.guildRoles(guild.id));
6247
+ const data = await guild.client.rest.get(Routes33.guildRoles(guild.id));
6248
+ if (!Array.isArray(data))
6249
+ throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
5755
6250
  return data.map((r) => cacheRole(guild, r));
5756
6251
  }
5757
6252
  async function fetchRole(guild, roleId2) {
5758
6253
  try {
5759
- const data = await guild.client.rest.get(Routes32.guildRole(guild.id, roleId2));
6254
+ const data = await guild.client.rest.get(Routes33.guildRole(guild.id, roleId2));
5760
6255
  return cacheRole(guild, data);
5761
6256
  } catch (err) {
5762
6257
  rethrowMapped(err, {
@@ -5773,7 +6268,7 @@ async function resolveRoleId(guild, arg) {
5773
6268
  const needle = trimmed.toLowerCase();
5774
6269
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
5775
6270
  if (cached) return cached.id;
5776
- const roles = await guild.client.rest.get(Routes32.guildRoles(guild.id));
6271
+ const roles = await guild.client.rest.get(Routes33.guildRoles(guild.id));
5777
6272
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
5778
6273
  if (!role) return null;
5779
6274
  cacheRole(guild, role);
@@ -5782,7 +6277,7 @@ async function resolveRoleId(guild, arg) {
5782
6277
  async function setRolePositions(guild, updates) {
5783
6278
  return replaceRoles(
5784
6279
  guild,
5785
- await guild.client.rest.patch(Routes32.guildRoles(guild.id), {
6280
+ await guild.client.rest.patch(Routes33.guildRoles(guild.id), {
5786
6281
  body: updates,
5787
6282
  auth: true
5788
6283
  })
@@ -5791,7 +6286,7 @@ async function setRolePositions(guild, updates) {
5791
6286
  async function setRoleHoistPositions(guild, updates) {
5792
6287
  return replaceRoles(
5793
6288
  guild,
5794
- await guild.client.rest.patch(Routes32.guildRolesHoistPositions(guild.id), {
6289
+ await guild.client.rest.patch(Routes33.guildRolesHoistPositions(guild.id), {
5795
6290
  body: updates.map((u) => ({
5796
6291
  id: u.id,
5797
6292
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -5803,17 +6298,17 @@ async function setRoleHoistPositions(guild, updates) {
5803
6298
  async function resetRoleHoistPositions(guild) {
5804
6299
  return replaceRoles(
5805
6300
  guild,
5806
- await guild.client.rest.delete(Routes32.guildRolesHoistPositions(guild.id), {
6301
+ await guild.client.rest.delete(Routes33.guildRolesHoistPositions(guild.id), {
5807
6302
  auth: true
5808
6303
  })
5809
6304
  );
5810
6305
  }
5811
6306
 
5812
6307
  // src/Domain/Guild/Stickers.ts
5813
- import { Routes as Routes33 } from "@fluxerjs/types";
6308
+ import { Routes as Routes34 } from "@fluxerjs/types";
5814
6309
  async function createSticker(guild, options) {
5815
6310
  const { reason, ...body } = options;
5816
- const data = await guild.client.rest.post(Routes33.guildStickers(guild.id), {
6311
+ const data = await guild.client.rest.post(Routes34.guildStickers(guild.id), {
5817
6312
  body,
5818
6313
  auth: true,
5819
6314
  ...auditReasonHeaders(reason)
@@ -5821,7 +6316,7 @@ async function createSticker(guild, options) {
5821
6316
  return cacheSticker(guild, data);
5822
6317
  }
5823
6318
  async function cloneSticker(guild, sourceStickerId) {
5824
- const data = await guild.client.rest.post(Routes33.guildStickersClone(guild.id), {
6319
+ const data = await guild.client.rest.post(Routes34.guildStickersClone(guild.id), {
5825
6320
  body: { source_sticker_id: sourceStickerId },
5826
6321
  auth: true
5827
6322
  });
@@ -5829,17 +6324,17 @@ async function cloneSticker(guild, sourceStickerId) {
5829
6324
  }
5830
6325
  async function createStickersBulk(guild, stickers) {
5831
6326
  const data = await guild.client.rest.post(
5832
- Routes33.guildStickersBulk(guild.id),
6327
+ Routes34.guildStickersBulk(guild.id),
5833
6328
  { body: { stickers }, auth: true }
5834
6329
  );
5835
6330
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
5836
6331
  }
5837
6332
  async function fetchStickers(guild) {
5838
- const data = await guild.client.rest.get(Routes33.guildStickers(guild.id));
6333
+ const data = await guild.client.rest.get(Routes34.guildStickers(guild.id));
5839
6334
  return data.map((s) => cacheSticker(guild, s));
5840
6335
  }
5841
6336
  async function fetchSticker(guild, stickerId) {
5842
- const data = await guild.client.rest.get(Routes33.guildSticker(guild.id, stickerId));
6337
+ const data = await guild.client.rest.get(Routes34.guildSticker(guild.id, stickerId));
5843
6338
  return cacheSticker(guild, data);
5844
6339
  }
5845
6340
 
@@ -5851,6 +6346,11 @@ var Guild = class extends Base {
5851
6346
  id;
5852
6347
  /** Whether the guild is currently available through the gateway. */
5853
6348
  available = true;
6349
+ /**
6350
+ * True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
6351
+ * and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
6352
+ */
6353
+ partial = true;
5854
6354
  /** Guild name. */
5855
6355
  name;
5856
6356
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -5923,6 +6423,10 @@ var Guild = class extends Base {
5923
6423
  emojis;
5924
6424
  /** Cached stickers in this guild. */
5925
6425
  stickers;
6426
+ /** Live stages in this guild's stage channels, keyed by stage instance ID. */
6427
+ stageInstances;
6428
+ /** Most participants a stage can have while speakers use video, or null if unknown. */
6429
+ maxStageVideoChannelUsers;
5926
6430
  /**
5927
6431
  * Construct a guild from API data.
5928
6432
  * @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE
@@ -5939,6 +6443,7 @@ var Guild = class extends Base {
5939
6443
  this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
5940
6444
  this.emojis = new LimitedCollection4({ maxSize: client.cache.limits.emojis });
5941
6445
  this.stickers = new LimitedCollection4({ maxSize: client.cache.limits.stickers });
6446
+ this.stageInstances = new Collection9();
5942
6447
  this.name = data.name ?? "";
5943
6448
  this.icon = data.icon ?? null;
5944
6449
  this.banner = data.banner ?? null;
@@ -5968,6 +6473,7 @@ var Guild = class extends Base {
5968
6473
  this.bannerHeight = data.banner_height ?? null;
5969
6474
  this.splashWidth = data.splash_width ?? null;
5970
6475
  this.splashHeight = data.splash_height ?? null;
6476
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
5971
6477
  this.memberCount = resolveGuildMemberCount(data) ?? null;
5972
6478
  this.onlineCount = resolveGuildOnlineCount(data) ?? null;
5973
6479
  for (const r of data.roles ?? []) {
@@ -6024,6 +6530,9 @@ var Guild = class extends Base {
6024
6530
  if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
6025
6531
  if (data.splash_width !== void 0) this.splashWidth = data.splash_width ?? null;
6026
6532
  if (data.splash_height !== void 0) this.splashHeight = data.splash_height ?? null;
6533
+ if (data.max_stage_video_channel_users !== void 0) {
6534
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
6535
+ }
6027
6536
  const memberCount = resolveGuildMemberCount(data);
6028
6537
  if (memberCount !== void 0) this.memberCount = memberCount;
6029
6538
  const onlineCount = resolveGuildOnlineCount(data);
@@ -6039,11 +6548,11 @@ var Guild = class extends Base {
6039
6548
  }
6040
6549
  /** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
6041
6550
  get createdTimestamp() {
6042
- return SnowflakeUtil9.timestampFromSnowflake(this.id);
6551
+ return SnowflakeUtil10.timestampFromSnowflake(this.id);
6043
6552
  }
6044
6553
  /** Date when this guild was created, derived from its snowflake ID. */
6045
6554
  get createdAt() {
6046
- return SnowflakeUtil9.dateFromSnowflake(this.id);
6555
+ return SnowflakeUtil10.dateFromSnowflake(this.id);
6047
6556
  }
6048
6557
  /** The guild's name. */
6049
6558
  toString() {
@@ -6145,6 +6654,10 @@ var Guild = class extends Base {
6145
6654
  ban(userId, options) {
6146
6655
  return ban(this, userId, options);
6147
6656
  }
6657
+ /** Fetch a single ban by user ID. Requires Ban Members. */
6658
+ fetchBan(userId) {
6659
+ return fetchBan(this, userId);
6660
+ }
6148
6661
  /** Fetch all bans in this guild. Requires Ban Members. */
6149
6662
  fetchBans() {
6150
6663
  return fetchBans(this);
@@ -6325,6 +6838,9 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
6325
6838
  if (resources.members !== void 0) mergeMembers(guild, resources.members);
6326
6839
  if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
6327
6840
  if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
6841
+ if (resources.stageInstances !== void 0) syncStageInstances(guild, resources.stageInstances);
6842
+ if (resources.stageCounts !== void 0) applyStageCounts(guild, resources.stageCounts);
6843
+ if (resources.channels !== void 0) guild.partial = false;
6328
6844
  return { guild, created, recovered };
6329
6845
  }
6330
6846
  function applyGuildSnapshotFromGateway(client, raw) {
@@ -6338,7 +6854,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
6338
6854
  emojis: g.emojis,
6339
6855
  stickers: g.stickers,
6340
6856
  // A channel list without `threads` means this session has no viewable threads.
6341
- threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
6857
+ threads: g.channels !== void 0 ? g.threads ?? [] : g.threads,
6858
+ stageInstances: g.stage_instances,
6859
+ stageCounts: g.stage_counts
6342
6860
  });
6343
6861
  if (g.voice_states?.length) {
6344
6862
  client.emit(Events.VoiceStatesSync, {
@@ -6350,7 +6868,7 @@ function applyGuildSnapshotFromGateway(client, raw) {
6350
6868
  }
6351
6869
 
6352
6870
  // src/ClientCore/ClientUser.ts
6353
- import { GatewayOpcodes, Routes as Routes34 } from "@fluxerjs/types";
6871
+ import { GatewayOpcodes, Routes as Routes35 } from "@fluxerjs/types";
6354
6872
  var ClientUser = class extends User {
6355
6873
  /** Broadcast presence (gateway opcode 3) on all shards. */
6356
6874
  setPresence(presence) {
@@ -6360,13 +6878,13 @@ var ClientUser = class extends User {
6360
6878
  }
6361
6879
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
6362
6880
  async fetch() {
6363
- const data = await this.client.rest.get(Routes34.currentUser(), { auth: true });
6881
+ const data = await this.client.rest.get(Routes35.currentUser(), { auth: true });
6364
6882
  this._patch(data);
6365
6883
  return this;
6366
6884
  }
6367
6885
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
6368
6886
  async fetchGuilds(options) {
6369
- const path = Routes34.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6887
+ const path = Routes35.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6370
6888
  const data = await this.client.rest.get(path, { auth: true });
6371
6889
  return data.map((g) => ({
6372
6890
  id: g.id,
@@ -6390,7 +6908,7 @@ var ClientUser = class extends User {
6390
6908
  */
6391
6909
  async leaveGuild(guildId, options) {
6392
6910
  const body = options ? toSudoBody(options) : void 0;
6393
- await this.client.rest.delete(Routes34.leaveGuild(guildId), {
6911
+ await this.client.rest.delete(Routes35.leaveGuild(guildId), {
6394
6912
  body: body && Object.keys(body).length ? body : void 0,
6395
6913
  auth: true
6396
6914
  });
@@ -6398,7 +6916,7 @@ var ClientUser = class extends User {
6398
6916
  /** Delete every message authored by the caller across a guild (sudo). */
6399
6917
  async bulkDeleteMyMessagesInGuild(guildId, options) {
6400
6918
  const body = options ? toSudoBody(options) : void 0;
6401
- await this.client.rest.post(Routes34.guildBulkDeleteMine(guildId), {
6919
+ await this.client.rest.post(Routes35.guildBulkDeleteMine(guildId), {
6402
6920
  body: body && Object.keys(body).length ? body : void 0,
6403
6921
  auth: true
6404
6922
  });
@@ -6408,15 +6926,7 @@ var ClientUser = class extends User {
6408
6926
  // src/ClientCore/EventHandlers/Helpers.ts
6409
6927
  import { asRecord, num, str } from "@fluxerjs/util";
6410
6928
  function unknownUser(id) {
6411
- return {
6412
- id,
6413
- username: "Unknown",
6414
- discriminator: "0",
6415
- global_name: null,
6416
- avatar: null,
6417
- avatar_color: null,
6418
- flags: 0
6419
- };
6929
+ return { id };
6420
6930
  }
6421
6931
  function indexMember(_client, guild, data) {
6422
6932
  if (!data.user?.id) return null;
@@ -6878,7 +7388,7 @@ var memberHandlers = {
6878
7388
  };
6879
7389
 
6880
7390
  // src/ClientCore/EventHandlers/Messages.ts
6881
- import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
7391
+ import { SnowflakeUtil as SnowflakeUtil11 } from "@fluxerjs/util";
6882
7392
  function cachedTextChannel(client, channelId) {
6883
7393
  const channel = client.channels.get(channelId);
6884
7394
  return channel?.isTextBased() ? channel : null;
@@ -6894,7 +7404,7 @@ function toPartialMessage(client, args) {
6894
7404
  const cached = args.cached;
6895
7405
  const authorId = args.authorId ?? cached?.author?.id ?? null;
6896
7406
  const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
6897
- const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil10.isValid(args.id) ? SnowflakeUtil10.dateFromSnowflake(args.id) : null;
7407
+ const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil11.isValid(args.id) ? SnowflakeUtil11.dateFromSnowflake(args.id) : null;
6898
7408
  return new PartialMessage(client, {
6899
7409
  id: args.id,
6900
7410
  channelId: args.channelId,
@@ -7100,6 +7610,9 @@ var passthroughHandlers = {
7100
7610
  VOICE_SERVER_UPDATE: pass(Events.VoiceServerUpdate),
7101
7611
  VOICE_STATE_ACK: pass(Events.VoiceStateAck),
7102
7612
  ENTRANCE_SOUND_PLAY: pass(Events.EntranceSoundPlay),
7613
+ VOICE_SIGNAL: pass(Events.VoiceSignal),
7614
+ GUILD_HEALTH_UPDATE: pass(Events.GuildHealthUpdate),
7615
+ OPERATOR_PASS_UPDATE: pass(Events.OperatorPassUpdate),
7103
7616
  TYPING_START(client, d) {
7104
7617
  const data = d;
7105
7618
  const payload = {
@@ -7155,6 +7668,46 @@ var passthroughHandlers = {
7155
7668
  WEBAUTHN_CREDENTIALS_UPDATE: pass(Events.WebAuthnCredentialsUpdate)
7156
7669
  };
7157
7670
 
7671
+ // src/ClientCore/EventHandlers/Stages.ts
7672
+ var stageHandlers = {
7673
+ STAGE_INSTANCE_CREATE(client, d) {
7674
+ const instance = cacheStageInstance(client, d);
7675
+ client.emit(Events.StageInstanceCreate, instance);
7676
+ },
7677
+ STAGE_INSTANCE_UPDATE(client, d) {
7678
+ const data = d;
7679
+ const cached = client.guilds.get(data.guild_id)?.stageInstances.get(data.id);
7680
+ const old = cached ? new StageInstance(client, cached.toJSON()) : null;
7681
+ const instance = cacheStageInstance(client, data);
7682
+ client.emit(Events.StageInstanceUpdate, old, instance);
7683
+ },
7684
+ STAGE_INSTANCE_DELETE(client, d) {
7685
+ const data = d;
7686
+ const guild = client.guilds.get(data.guild_id);
7687
+ const instance = guild?.stageInstances.get(data.id) ?? new StageInstance(client, data);
7688
+ instance._patch(data);
7689
+ guild?.stageInstances.delete(data.id);
7690
+ client.emit(Events.StageInstanceDelete, instance);
7691
+ },
7692
+ STAGE_COUNTS_UPDATE(client, d) {
7693
+ const data = d;
7694
+ const channel = client.channels.get(data.channel_id);
7695
+ if (channel?.isStage()) channel._patchCounts(data);
7696
+ const payload = {
7697
+ guildId: data.guild_id,
7698
+ channelId: data.channel_id,
7699
+ listenerCount: data.listener_count,
7700
+ speakerCount: data.speaker_count,
7701
+ requestCount: data.request_count,
7702
+ videoEnabled: data.video_enabled ?? null
7703
+ };
7704
+ client.emit(Events.StageCountsUpdate, payload);
7705
+ },
7706
+ STAGE_VOICE_STATES_SYNC: pass(Events.StageVoiceStatesSync),
7707
+ STAGE_AUDIENCE_LIST_UPDATE: pass(Events.StageAudienceListUpdate),
7708
+ VOICE_JOIN_QUEUED: pass(Events.VoiceJoinQueued)
7709
+ };
7710
+
7158
7711
  // src/ClientCore/EventHandlers/Threads.ts
7159
7712
  function cachedChannel(client, id) {
7160
7713
  const direct = client.channels.get(id);
@@ -7265,7 +7818,8 @@ var eventHandlers = buildRegistry(
7265
7818
  inviteHandlers,
7266
7819
  guildResourceHandlers,
7267
7820
  passthroughHandlers,
7268
- threadHandlers
7821
+ threadHandlers,
7822
+ stageHandlers
7269
7823
  );
7270
7824
 
7271
7825
  // src/ClientCore/GatewayDispatch.ts
@@ -7290,29 +7844,63 @@ function handleGatewayDispatch(client, payload, deferred) {
7290
7844
  }
7291
7845
  return dispatchGatewayPayload(client, payload);
7292
7846
  }
7293
- function dispatchGatewayPayload(client, payload) {
7847
+ var dispatchQueues = /* @__PURE__ */ new WeakMap();
7848
+ function queueFor(client) {
7849
+ let queue = dispatchQueues.get(client);
7850
+ if (!queue) {
7851
+ queue = { tail: Promise.resolve(), pending: 0 };
7852
+ dispatchQueues.set(client, queue);
7853
+ }
7854
+ return queue;
7855
+ }
7856
+ async function runGatewayHandler(client, payload) {
7294
7857
  const event = payload.t;
7295
- if (!event) return Promise.resolve();
7858
+ if (!event) return;
7296
7859
  const handler = eventHandlers.get(event);
7297
7860
  if (!handler) {
7298
7861
  client.emit(Events.Debug, `[Gateway] Unhandled dispatch: ${event}`);
7299
- return Promise.resolve();
7862
+ return;
7300
7863
  }
7301
- const run = async () => {
7302
- try {
7303
- await handler(client, payload.d);
7304
- } catch (err) {
7305
- emitClientError(client, err);
7306
- }
7307
- };
7308
- if (client.options.gatewayDeferHandlers === false) return run();
7309
- return new Promise((resolve, reject) => {
7310
- const start = () => {
7311
- void run().then(resolve).catch(reject);
7312
- };
7313
- if (typeof setImmediate === "function") setImmediate(start);
7314
- else setTimeout(start, 0);
7864
+ if (payload.d !== null && payload.d !== void 0 && typeof payload.d !== "object") {
7865
+ client.emit(
7866
+ Events.Debug,
7867
+ `[Gateway] Ignoring malformed dispatch ${event}: payload is not an object`
7868
+ );
7869
+ return;
7870
+ }
7871
+ if (client.options.gatewayDeferHandlers !== false) {
7872
+ await new Promise((resolve) => {
7873
+ if (typeof setImmediate === "function") setImmediate(resolve);
7874
+ else setTimeout(resolve, 0);
7875
+ });
7876
+ }
7877
+ try {
7878
+ await handler(client, payload.d);
7879
+ } catch (err) {
7880
+ emitClientError(client, err);
7881
+ }
7882
+ }
7883
+ function dispatchGatewayPayload(client, payload) {
7884
+ const queue = queueFor(client);
7885
+ if (client.options.gatewayDeferHandlers === false && queue.pending === 0) {
7886
+ queue.pending++;
7887
+ const run = runGatewayHandler(client, payload).finally(() => {
7888
+ queue.pending--;
7889
+ });
7890
+ queue.tail = run.catch(() => {
7891
+ });
7892
+ return run;
7893
+ }
7894
+ queue.pending++;
7895
+ const next = queue.tail.then(
7896
+ () => runGatewayHandler(client, payload),
7897
+ () => runGatewayHandler(client, payload)
7898
+ ).finally(() => {
7899
+ queue.pending--;
7900
+ });
7901
+ queue.tail = next.catch(() => {
7315
7902
  });
7903
+ return next;
7316
7904
  }
7317
7905
  async function flushDeferredGatewayDispatches(client, deferred) {
7318
7906
  while (deferred.length > 0) {
@@ -7491,7 +8079,7 @@ async function connectClientGateway(client, token, signal) {
7491
8079
 
7492
8080
  // src/ClientCore/GuildManager.ts
7493
8081
  import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
7494
- import { Routes as Routes35 } from "@fluxerjs/types";
8082
+ import { Routes as Routes36 } from "@fluxerjs/types";
7495
8083
  var GuildManager = class extends LimitedCollection5 {
7496
8084
  constructor(client) {
7497
8085
  super({
@@ -7500,6 +8088,7 @@ var GuildManager = class extends LimitedCollection5 {
7500
8088
  });
7501
8089
  this.client = client;
7502
8090
  }
8091
+ pendingFetches = /* @__PURE__ */ new Map();
7503
8092
  /**
7504
8093
  * Remove a guild from cache and cascade its channels / message caches.
7505
8094
  * Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
@@ -7514,35 +8103,73 @@ var GuildManager = class extends LimitedCollection5 {
7514
8103
  }
7515
8104
  /**
7516
8105
  * Get a guild from cache or fetch from the API if not present.
8106
+ * Partial (metadata-only) cached guilds are hydrated first.
7517
8107
  * @param guildId - Snowflake of the guild
7518
8108
  * @returns The guild
7519
8109
  * @throws FluxerError with GUILD_NOT_FOUND if missing
7520
8110
  */
7521
8111
  async resolve(guildId) {
7522
- return this.get(guildId) ?? this.fetch(guildId);
8112
+ const id = normalizeSnowflakeId(guildId, "guilds.resolve()");
8113
+ const cached = this.get(id);
8114
+ if (cached && !cached.partial) return cached;
8115
+ if (cached) {
8116
+ await dedupeFetch(this.pendingFetches, id, async () => {
8117
+ await this.hydrate(cached);
8118
+ return cached;
8119
+ });
8120
+ return cached;
8121
+ }
8122
+ const guild = await this.fetch(id);
8123
+ await dedupeFetch(this.pendingFetches, id, async () => {
8124
+ await this.hydrate(guild);
8125
+ return guild;
8126
+ });
8127
+ return guild;
7523
8128
  }
7524
8129
  /**
7525
8130
  * Fetch a guild by ID.
7526
- * Returns the cached guild unless `force` is set, in which case REST metadata is applied via `_patch`.
8131
+ * Returns the cached guild unless `force` is set, in which case REST metadata
8132
+ * is applied via `_patch`. Use {@link resolve} to also hydrate nested caches.
7527
8133
  * @throws FluxerError with GUILD_NOT_FOUND if missing
7528
8134
  */
7529
8135
  async fetch(guildId, options) {
7530
- const cached = this.get(guildId);
8136
+ const id = normalizeSnowflakeId(guildId, "guilds.fetch()");
8137
+ const cached = this.get(id);
7531
8138
  if (cached && !options?.force) return cached;
7532
- try {
7533
- const data = await this.client.rest.get(Routes35.guild(guildId));
7534
- if (cached) {
7535
- cached._patch(data);
7536
- return cached;
8139
+ return dedupeFetch(this.pendingFetches, id, async () => {
8140
+ try {
8141
+ const data = assertApiObjectWithId(
8142
+ await this.client.rest.get(Routes36.guild(id)),
8143
+ "guilds.fetch()"
8144
+ );
8145
+ let guild;
8146
+ const existing = this.get(id);
8147
+ if (existing) {
8148
+ existing._patch(data);
8149
+ guild = existing;
8150
+ } else {
8151
+ guild = new Guild(this.client, data);
8152
+ this.set(guild.id, guild);
8153
+ }
8154
+ return guild;
8155
+ } catch (err) {
8156
+ rethrowMapped(err, {
8157
+ notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${id} not found` },
8158
+ fallback: `Failed to fetch guild ${id}`
8159
+ });
7537
8160
  }
7538
- const guild = new Guild(this.client, data);
7539
- this.set(guild.id, guild);
7540
- return guild;
8161
+ });
8162
+ }
8163
+ /** Best-effort nested sync for a metadata-only guild. Failures keep `partial` set. */
8164
+ async hydrate(guild) {
8165
+ try {
8166
+ await Promise.all([guild.fetchChannels(), guild.fetchRoles()]);
8167
+ guild.partial = false;
7541
8168
  } catch (err) {
7542
- rethrowMapped(err, {
7543
- notFound: { code: ErrorCodes.GuildNotFound, message: `Guild ${guildId} not found` },
7544
- fallback: `Failed to fetch guild ${guildId}`
7545
- });
8169
+ this.client.emit(
8170
+ Events.Debug,
8171
+ `[GuildManager] Could not fully hydrate guild ${guild.id}: ${err instanceof Error ? err.message : String(err)}`
8172
+ );
7546
8173
  }
7547
8174
  }
7548
8175
  };
@@ -7567,6 +8194,10 @@ var MessageCache = class {
7567
8194
  if (limit === false) return;
7568
8195
  if (!this.caches) this.caches = /* @__PURE__ */ new Map();
7569
8196
  let cache = this.caches.get(channelId);
8197
+ if (cache) {
8198
+ this.caches.delete(channelId);
8199
+ this.caches.set(channelId, cache);
8200
+ }
7570
8201
  if (!cache) {
7571
8202
  const channelLimit = this.getChannelLimit();
7572
8203
  if (Number.isFinite(channelLimit) && channelLimit > 0 && this.caches.size >= channelLimit) {
@@ -7618,7 +8249,7 @@ var MessageCache = class {
7618
8249
  // src/ClientCore/UserManager.ts
7619
8250
  import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
7620
8251
  import {
7621
- Routes as Routes36
8252
+ Routes as Routes37
7622
8253
  } from "@fluxerjs/types";
7623
8254
  var soft = (p) => p.catch(() => null);
7624
8255
  var UserManager = class extends LimitedCollection6 {
@@ -7626,6 +8257,7 @@ var UserManager = class extends LimitedCollection6 {
7626
8257
  super({ maxSize: client.cache.limits.users });
7627
8258
  this.client = client;
7628
8259
  }
8260
+ pendingFetches = /* @__PURE__ */ new Map();
7629
8261
  /** Remove matching users (skips `client.user`). Returns count removed. */
7630
8262
  sweep(filter) {
7631
8263
  let removed = 0;
@@ -7639,16 +8271,30 @@ var UserManager = class extends LimitedCollection6 {
7639
8271
  }
7640
8272
  return removed;
7641
8273
  }
7642
- /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
8274
+ /**
8275
+ * Fetch a user by ID and update cache. Returns the cached user unless `force` is set
8276
+ * or the cached entry is only a partial stub (e.g. from a reaction event).
8277
+ */
7643
8278
  async fetch(userId, options) {
7644
- const cached = this.get(userId);
7645
- if (cached && !options?.force) return cached;
7646
- const data = await this.client.rest.get(Routes36.user(userId));
7647
- return this.client.getOrCreateUser(data);
8279
+ const id = normalizeSnowflakeId(userId, "users.fetch()");
8280
+ const cached = this.get(id);
8281
+ if (cached && !cached.partial && !options?.force) return cached;
8282
+ return dedupeFetch(
8283
+ this.pendingFetches,
8284
+ id,
8285
+ async () => this.client.getOrCreateUser(
8286
+ assertApiObjectWithId(
8287
+ await this.client.rest.get(Routes37.user(id)),
8288
+ "users.fetch()"
8289
+ )
8290
+ )
8291
+ );
7648
8292
  }
7649
- /** Return a cached user, otherwise {@link fetch}. */
8293
+ /** Return a cached (non-partial) user, otherwise {@link fetch}. */
7650
8294
  async resolve(userId) {
7651
- return this.get(userId) ?? this.fetch(userId);
8295
+ const id = normalizeSnowflakeId(userId, "users.resolve()");
8296
+ const cached = this.get(id);
8297
+ return cached && !cached.partial ? cached : this.fetch(id);
7652
8298
  }
7653
8299
  /**
7654
8300
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
@@ -7661,10 +8307,10 @@ var UserManager = class extends LimitedCollection6 {
7661
8307
  async fetchWithProfile(userId, options) {
7662
8308
  const guildId = options?.guildId ?? void 0;
7663
8309
  const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
7664
- this.client.rest.get(Routes36.user(userId)),
7665
- soft(this.client.rest.get(Routes36.userProfile(userId))),
7666
- guildId ? soft(this.client.rest.get(Routes36.userProfile(userId, guildId))) : null,
7667
- guildId ? soft(this.client.rest.get(Routes36.guildMember(guildId, userId))) : null
8310
+ this.client.rest.get(Routes37.user(userId)),
8311
+ soft(this.client.rest.get(Routes37.userProfile(userId))),
8312
+ guildId ? soft(this.client.rest.get(Routes37.userProfile(userId, guildId))) : null,
8313
+ guildId ? soft(this.client.rest.get(Routes37.guildMember(guildId, userId))) : null
7668
8314
  ]);
7669
8315
  const user = this.client.getOrCreateUser(userData);
7670
8316
  let member = null;
@@ -7789,7 +8435,7 @@ var Client = class _Client extends EventEmitter3 {
7789
8435
  * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
7790
8436
  * Does not log in. Call {@link login} with a token afterward.
7791
8437
  *
7792
- * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
8438
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
7793
8439
  * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
7794
8440
  * @param connectOptions - Optional abort signal for the discovery request
7795
8441
  */
@@ -7866,6 +8512,38 @@ var Client = class _Client extends EventEmitter3 {
7866
8512
  fetchStickerMetadata(stickerId) {
7867
8513
  return fetchStickerMetadata(this, stickerId);
7868
8514
  }
8515
+ /** Fetch the source guild of a custom emoji. */
8516
+ fetchEmojiSource(emojiId) {
8517
+ return fetchEmojiSource(this, emojiId);
8518
+ }
8519
+ /** Fetch the source guild of a custom sticker. */
8520
+ fetchStickerSource(stickerId) {
8521
+ return fetchStickerSource(this, stickerId);
8522
+ }
8523
+ /** List discovery categories. */
8524
+ fetchDiscoveryCategories() {
8525
+ return fetchDiscoveryCategories(this);
8526
+ }
8527
+ /** Search discoverable guilds. */
8528
+ searchDiscoveryGuilds(options) {
8529
+ return searchDiscoveryGuilds(this, options);
8530
+ }
8531
+ /** Fetch experiment assignments for this account. */
8532
+ fetchExperiments() {
8533
+ return fetchExperiments(this);
8534
+ }
8535
+ /** Refresh expiring attachment CDN URLs. */
8536
+ refreshAttachmentUrls(attachmentUrls) {
8537
+ return refreshAttachmentUrls(this, attachmentUrls);
8538
+ }
8539
+ /** List instance custom guild badges (`GET /instance/badges`). */
8540
+ fetchInstanceBadges(options) {
8541
+ return fetchInstanceBadges(this, options);
8542
+ }
8543
+ /** Fetch forum/media thread post data for a channel. */
8544
+ fetchChannelPostData(channelId, threadIds) {
8545
+ return fetchChannelPostData(this, channelId, threadIds);
8546
+ }
7869
8547
  /**
7870
8548
  * Fetch the current application (`/applications/@me`).
7871
8549
  * @returns Application metadata (owner, flags, RPC origins, etc.)
@@ -7960,6 +8638,9 @@ var Client = class _Client extends EventEmitter3 {
7960
8638
  * @internal
7961
8639
  */
7962
8640
  getOrCreateUser(data) {
8641
+ if (!data || typeof data.id !== "string" || data.id.length === 0) {
8642
+ throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
8643
+ }
7963
8644
  const existing = this.users.get(data.id);
7964
8645
  if (existing) {
7965
8646
  existing._patch(data);
@@ -8212,7 +8893,7 @@ var Client = class _Client extends EventEmitter3 {
8212
8893
  * @see {@link Routes}
8213
8894
  */
8214
8895
  static get Routes() {
8215
- return Routes37;
8896
+ return Routes38;
8216
8897
  }
8217
8898
  };
8218
8899