@fluxerjs/core 3.3.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -28,8 +28,8 @@ module.exports = __toCommonJS(SubpathClient_exports);
28
28
  // src/ClientCore/Client.ts
29
29
  var import_node_events3 = require("events");
30
30
  var import_rest3 = require("@fluxerjs/rest");
31
- var import_types45 = require("@fluxerjs/types");
32
- var import_util26 = require("@fluxerjs/util");
31
+ var import_types46 = require("@fluxerjs/types");
32
+ var import_util27 = require("@fluxerjs/util");
33
33
 
34
34
  // src/Domain/Message/Message.ts
35
35
  var import_builders3 = require("@fluxerjs/builders");
@@ -969,6 +969,7 @@ var Events = {
969
969
  GuildEmojisUpdate: "guildEmojisUpdate",
970
970
  GuildStickersUpdate: "guildStickersUpdate",
971
971
  GuildCountsUpdate: "guildCountsUpdate",
972
+ GuildHealthUpdate: "guildHealthUpdate",
972
973
  ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
973
974
  GuildMemberAdd: "guildMemberAdd",
974
975
  GuildMemberUpdate: "guildMemberUpdate",
@@ -1003,7 +1004,16 @@ var Events = {
1003
1004
  VoiceStateAck: "voiceStateAck",
1004
1005
  VoiceServerUpdate: "voiceServerUpdate",
1005
1006
  EntranceSoundPlay: "entranceSoundPlay",
1007
+ VoiceSignal: "voiceSignal",
1008
+ OperatorPassUpdate: "operatorPassUpdate",
1006
1009
  VoiceStatesSync: "voiceStatesSync",
1010
+ VoiceJoinQueued: "voiceJoinQueued",
1011
+ StageInstanceCreate: "stageInstanceCreate",
1012
+ StageInstanceUpdate: "stageInstanceUpdate",
1013
+ StageInstanceDelete: "stageInstanceDelete",
1014
+ StageCountsUpdate: "stageCountsUpdate",
1015
+ StageVoiceStatesSync: "stageVoiceStatesSync",
1016
+ StageAudienceListUpdate: "stageAudienceListUpdate",
1007
1017
  WebhooksUpdate: "webhooksUpdate",
1008
1018
  Resumed: "resumed",
1009
1019
  Error: "error",
@@ -1132,6 +1142,45 @@ var import_util5 = require("@fluxerjs/util");
1132
1142
  // src/ClientCore/MessageManager.ts
1133
1143
  var import_collection2 = require("@fluxerjs/collection");
1134
1144
  var import_types5 = require("@fluxerjs/types");
1145
+
1146
+ // src/ClientCore/Resolve.ts
1147
+ function normalizeSnowflakeId(value, label) {
1148
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
1149
+ throw new TypeError(
1150
+ `${label} received an unsafe numeric ID; pass snowflakes as strings to avoid precision loss`
1151
+ );
1152
+ }
1153
+ const id = typeof value === "bigint" ? value.toString() : String(value ?? "").trim();
1154
+ if (!id || id === "undefined" || id === "null" || id === "[object Object]") {
1155
+ throw new TypeError(`${label} requires a non-empty ID`);
1156
+ }
1157
+ return id;
1158
+ }
1159
+ function assertApiObjectWithId(data, label) {
1160
+ if (!data || typeof data !== "object" || typeof data.id !== "string" || data.id.length === 0) {
1161
+ throw new TypeError(`${label} received an invalid API payload (missing string id)`);
1162
+ }
1163
+ return data;
1164
+ }
1165
+ function assertApiArray(data, label) {
1166
+ if (!Array.isArray(data)) {
1167
+ throw new TypeError(`${label} received an invalid API payload (expected an array)`);
1168
+ }
1169
+ return data;
1170
+ }
1171
+ async function dedupeFetch(pending, key, fn) {
1172
+ const existing = pending.get(key);
1173
+ if (existing) return existing;
1174
+ const request = fn();
1175
+ pending.set(key, request);
1176
+ try {
1177
+ return await request;
1178
+ } finally {
1179
+ if (pending.get(key) === request) pending.delete(key);
1180
+ }
1181
+ }
1182
+
1183
+ // src/ClientCore/MessageManager.ts
1135
1184
  var BULK = {
1136
1185
  requests: { min: 1, max: 25 },
1137
1186
  limit: { min: 1, max: 25 },
@@ -1167,25 +1216,32 @@ var MessageManager = class {
1167
1216
  }
1168
1217
  /** Structure cache keyed by message id (identity for {@link get}). */
1169
1218
  _structures = new import_collection2.Collection();
1219
+ pendingFetches = /* @__PURE__ */ new Map();
1170
1220
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
1171
1221
  get(messageId) {
1172
- const data = this.client._getMessageCache(this.channelId)?.get(messageId);
1222
+ const id = String(messageId ?? "").trim();
1223
+ if (!id) return void 0;
1224
+ const data = this.client._getMessageCache(this.channelId)?.get(id);
1173
1225
  if (!data) {
1174
- this._structures.delete(messageId);
1226
+ this._structures.delete(id);
1175
1227
  return void 0;
1176
1228
  }
1177
- const existing = this._structures.get(messageId);
1178
- if (existing) return existing;
1229
+ const existing = this._structures.get(id);
1230
+ if (existing) {
1231
+ existing._patch(data);
1232
+ return existing;
1233
+ }
1179
1234
  const message = new Message(this.client, data);
1180
- this._structures.set(messageId, message);
1235
+ this._structures.set(id, message);
1181
1236
  return message;
1182
1237
  }
1183
1238
  /** Retrieve from cache, otherwise {@link fetch}. */
1184
1239
  async resolve(messageId) {
1185
- return this.get(messageId) ?? this.fetch(messageId);
1240
+ const id = normalizeSnowflakeId(messageId, "messages.resolve()");
1241
+ return this.get(id) ?? this.fetch(id);
1186
1242
  }
1187
1243
  async fetch(idOrOptions) {
1188
- return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
1244
+ return typeof idOrOptions === "string" || typeof idOrOptions === "number" ? this.fetchOne(normalizeSnowflakeId(idOrOptions, "messages.fetch()")) : this.fetchMany(idOrOptions);
1189
1245
  }
1190
1246
  /** Cache API data and return a {@link Message} (reusing identity when present). */
1191
1247
  wrap(data) {
@@ -1202,9 +1258,13 @@ var MessageManager = class {
1202
1258
  }
1203
1259
  /** Fetch a single message from the API. */
1204
1260
  async fetchOne(messageId) {
1261
+ return dedupeFetch(this.pendingFetches, messageId, async () => this.fetchOneFresh(messageId));
1262
+ }
1263
+ async fetchOneFresh(messageId) {
1205
1264
  try {
1206
- const data = await this.client.rest.get(
1207
- import_types5.Routes.channelMessage(this.channelId, messageId)
1265
+ const data = assertApiObjectWithId(
1266
+ await this.client.rest.get(import_types5.Routes.channelMessage(this.channelId, messageId)),
1267
+ "messages.fetch()"
1208
1268
  );
1209
1269
  return this.wrap(data);
1210
1270
  } catch (err) {
@@ -1230,9 +1290,15 @@ var MessageManager = class {
1230
1290
  if (value != null && value !== "") qs2.set(key, String(value));
1231
1291
  }
1232
1292
  const base = import_types5.Routes.channelMessages(this.channelId);
1233
- const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
1293
+ const data = assertApiArray(
1294
+ await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base),
1295
+ "messages.fetch()"
1296
+ );
1234
1297
  const collection = new import_collection2.Collection();
1235
- for (const msg of data) collection.set(msg.id, this.wrap(msg));
1298
+ for (const msg of data) {
1299
+ if (!msg?.id) continue;
1300
+ collection.set(msg.id, this.wrap(msg));
1301
+ }
1236
1302
  return collection;
1237
1303
  }
1238
1304
  };
@@ -1436,6 +1502,9 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1436
1502
  }
1437
1503
 
1438
1504
  // src/Domain/Channel/Base.ts
1505
+ function isFullChannelData(data) {
1506
+ 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;
1507
+ }
1439
1508
  var Channel = class extends Base {
1440
1509
  #messages;
1441
1510
  /** The {@link Client} that instantiated this channel. */
@@ -1450,6 +1519,11 @@ var Channel = class extends Base {
1450
1519
  icon;
1451
1520
  /** ISO8601 timestamp of the last pinned message update. */
1452
1521
  lastPinTimestamp;
1522
+ /**
1523
+ * True when built from a partial payload (e.g. a DM stub) and not yet hydrated
1524
+ * with a full channel object. `channels.resolve()` refetches partial channels.
1525
+ */
1526
+ partial;
1453
1527
  constructor(client, data) {
1454
1528
  super();
1455
1529
  this.client = client;
@@ -1458,6 +1532,7 @@ var Channel = class extends Base {
1458
1532
  this.name = data.name ?? null;
1459
1533
  this.icon = data.icon ?? null;
1460
1534
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1535
+ this.partial = !isFullChannelData(data);
1461
1536
  }
1462
1537
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
1463
1538
  get createdTimestamp() {
@@ -1478,6 +1553,7 @@ var Channel = class extends Base {
1478
1553
  if ("last_pin_timestamp" in data && data.last_pin_timestamp !== void 0) {
1479
1554
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1480
1555
  }
1556
+ if (isFullChannelData(data)) this.partial = false;
1481
1557
  }
1482
1558
  /** @internal Factory wired after subclasses load. */
1483
1559
  static from(_c, _d) {
@@ -1497,11 +1573,11 @@ var Channel = class extends Base {
1497
1573
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
1498
1574
  */
1499
1575
  isTextBased() {
1500
- return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.DM || this.type === import_types7.ChannelType.GroupDM || this.type === import_types7.ChannelType.DMPersonalNotes || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread;
1576
+ return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildStageVoice || this.type === import_types7.ChannelType.DM || this.type === import_types7.ChannelType.GroupDM || this.type === import_types7.ChannelType.DMPersonalNotes || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread;
1501
1577
  }
1502
1578
  /** Check if this is a guild channel, including threads, forums, and media channels. */
1503
1579
  isGuild() {
1504
- return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildCategory || this.type === import_types7.ChannelType.GuildLink || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread || this.type === import_types7.ChannelType.GuildForum || this.type === import_types7.ChannelType.GuildMedia;
1580
+ return this.type === import_types7.ChannelType.GuildText || this.type === import_types7.ChannelType.GuildAnnouncement || this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildStageVoice || this.type === import_types7.ChannelType.GuildCategory || this.type === import_types7.ChannelType.GuildLink || this.type === import_types7.ChannelType.AnnouncementThread || this.type === import_types7.ChannelType.PublicThread || this.type === import_types7.ChannelType.PrivateThread || this.type === import_types7.ChannelType.GuildForum || this.type === import_types7.ChannelType.GuildMedia;
1505
1581
  }
1506
1582
  /** Check if this is a thread (public, private, or announcement). */
1507
1583
  isThread() {
@@ -1535,10 +1611,18 @@ var Channel = class extends Base {
1535
1611
  isPersonalNotes() {
1536
1612
  return this.type === import_types7.ChannelType.DMPersonalNotes;
1537
1613
  }
1538
- /** Check if this is a voice channel. */
1614
+ /** Check if this is a voice channel (type 2 only; see {@link isVoiceBased} to include stages). */
1539
1615
  isVoice() {
1540
1616
  return this.type === import_types7.ChannelType.GuildVoice;
1541
1617
  }
1618
+ /** Check if this is a stage channel (type 13). */
1619
+ isStage() {
1620
+ return this.type === import_types7.ChannelType.GuildStageVoice;
1621
+ }
1622
+ /** Check if this is a voice or stage channel, i.e. one `@fluxerjs/voice` can join. */
1623
+ isVoiceBased() {
1624
+ return this.type === import_types7.ChannelType.GuildVoice || this.type === import_types7.ChannelType.GuildStageVoice;
1625
+ }
1542
1626
  /** Check if this is a link channel. */
1543
1627
  isLink() {
1544
1628
  return this.type === import_types7.ChannelType.GuildLink;
@@ -2253,10 +2337,10 @@ var Message = class _Message extends Base {
2253
2337
  this.channelId = data.channel_id;
2254
2338
  this.guildId = data.guild_id ?? null;
2255
2339
  this.author = client.getOrCreateUser(data.author);
2256
- this.content = data.content;
2257
- this.createdAt = new Date(data.timestamp);
2340
+ this.content = data.content ?? "";
2341
+ this.createdAt = data.timestamp ? new Date(data.timestamp) : /* @__PURE__ */ new Date(0);
2258
2342
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2259
- this.pinned = data.pinned;
2343
+ this.pinned = data.pinned ?? false;
2260
2344
  this.attachments = new import_collection5.Collection();
2261
2345
  for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2262
2346
  this.type = data.type ?? import_types10.MessageType.Default;
@@ -2288,33 +2372,47 @@ var Message = class _Message extends Base {
2288
2372
  * @internal
2289
2373
  */
2290
2374
  _patch(data) {
2291
- this.content = data.content;
2292
- this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2293
- this.pinned = data.pinned;
2294
- this.attachments.clear();
2295
- for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2296
- this.flags = new import_util7.MessageFlagsBitField(BigInt(data.flags ?? 0));
2297
- this.mentionEveryone = data.mention_everyone ?? false;
2298
- this.tts = data.tts ?? false;
2299
- this.embeds = (data.embeds ?? []).map(toMessageEmbed);
2300
- this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
2301
- this.reactions._patch(data.reactions);
2302
- this.messageReference = data.message_reference ? {
2303
- channelId: data.message_reference.channel_id,
2304
- messageId: data.message_reference.message_id,
2305
- guildId: data.message_reference.guild_id ?? null,
2306
- ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
2307
- } : null;
2308
- this.messageSnapshots = (data.message_snapshots ?? []).map(
2309
- (s) => toMessageSnapshot(this.client, s)
2310
- );
2311
- this.call = data.call ? toMessageCall(data.call) : null;
2312
- this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
2313
- this.webhookId = data.webhook_id ?? null;
2314
- this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
2315
- this.mentionRoles = data.mention_roles ?? [];
2316
- this.nonce = data.nonce ?? null;
2317
- this.nsfwEmojis = data.nsfw_emojis ?? [];
2375
+ if (data.content !== void 0) this.content = data.content ?? "";
2376
+ if (data.edited_timestamp !== void 0) {
2377
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
2378
+ }
2379
+ if (data.pinned !== void 0) this.pinned = data.pinned;
2380
+ if (data.attachments !== void 0) {
2381
+ this.attachments.clear();
2382
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
2383
+ }
2384
+ if (data.flags !== void 0) this.flags = new import_util7.MessageFlagsBitField(BigInt(data.flags ?? 0));
2385
+ if (data.mention_everyone !== void 0) this.mentionEveryone = data.mention_everyone;
2386
+ if (data.tts !== void 0) this.tts = data.tts;
2387
+ if (data.embeds !== void 0) this.embeds = (data.embeds ?? []).map(toMessageEmbed);
2388
+ if (data.stickers !== void 0) {
2389
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
2390
+ }
2391
+ if (data.reactions !== void 0) this.reactions._patch(data.reactions);
2392
+ if (data.message_reference !== void 0) {
2393
+ this.messageReference = data.message_reference ? {
2394
+ channelId: data.message_reference.channel_id,
2395
+ messageId: data.message_reference.message_id,
2396
+ guildId: data.message_reference.guild_id ?? null,
2397
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
2398
+ } : null;
2399
+ }
2400
+ if (data.message_snapshots !== void 0) {
2401
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
2402
+ (s) => toMessageSnapshot(this.client, s)
2403
+ );
2404
+ }
2405
+ if (data.call !== void 0) this.call = data.call ? toMessageCall(data.call) : null;
2406
+ if (data.referenced_message !== void 0) {
2407
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
2408
+ }
2409
+ if (data.webhook_id !== void 0) this.webhookId = data.webhook_id ?? null;
2410
+ if (data.mentions !== void 0) {
2411
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
2412
+ }
2413
+ if (data.mention_roles !== void 0) this.mentionRoles = data.mention_roles ?? [];
2414
+ if (data.nonce !== void 0) this.nonce = data.nonce ?? null;
2415
+ if (data.nsfw_emojis !== void 0) this.nsfwEmojis = data.nsfw_emojis ?? [];
2318
2416
  if (data.thread) this.thread = cacheThread(this.client, data.thread);
2319
2417
  }
2320
2418
  /**
@@ -2415,6 +2513,23 @@ var Message = class _Message extends Base {
2415
2513
  async fetch() {
2416
2514
  return this.client.channels.fetchMessage(this.channelId, this.id);
2417
2515
  }
2516
+ /** Publish this announcement message to channels following its channel. */
2517
+ async crosspost() {
2518
+ const data = await this.client.rest.post(
2519
+ import_types10.Routes.channelMessageCrosspost(this.channelId, this.id),
2520
+ { auth: true }
2521
+ );
2522
+ const published = new _Message(this.client, data);
2523
+ this.client._addMessageToCache(this.channelId, data);
2524
+ return published;
2525
+ }
2526
+ /** Fetch the source guild of a crossposted (followed-channel) message. */
2527
+ async fetchCrosspostSource() {
2528
+ return this.client.rest.get(
2529
+ import_types10.Routes.channelMessageCrosspostSource(this.channelId, this.id),
2530
+ { auth: true }
2531
+ );
2532
+ }
2418
2533
  /** Delete this message. */
2419
2534
  async delete(reason) {
2420
2535
  await this.client.rest.delete(import_types10.Routes.channelMessage(this.channelId, this.id), {
@@ -2518,8 +2633,8 @@ var PartialMessage = class {
2518
2633
  };
2519
2634
 
2520
2635
  // src/Domain/User.ts
2521
- var import_types21 = require("@fluxerjs/types");
2522
- var import_util14 = require("@fluxerjs/util");
2636
+ var import_types22 = require("@fluxerjs/types");
2637
+ var import_util15 = require("@fluxerjs/util");
2523
2638
 
2524
2639
  // src/Domain/Channel/Dm.ts
2525
2640
  var import_types12 = require("@fluxerjs/types");
@@ -2578,7 +2693,7 @@ var DMChannel = class extends TextCapable(Channel) {
2578
2693
  const full = data;
2579
2694
  this.lastMessageId = full.last_message_id ?? null;
2580
2695
  this.ownerId = full.owner_id ?? null;
2581
- this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
2696
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => client.getOrCreateUser(u));
2582
2697
  this.nicks = full.nicks ?? {};
2583
2698
  }
2584
2699
  /**
@@ -2593,7 +2708,7 @@ var DMChannel = class extends TextCapable(Channel) {
2593
2708
  }
2594
2709
  if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2595
2710
  if ("recipients" in full && full.recipients !== void 0) {
2596
- this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2711
+ this.recipients = (full.recipients ?? []).filter((u) => typeof u?.id === "string").map((u) => this.client.getOrCreateUser(u));
2597
2712
  }
2598
2713
  if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2599
2714
  }
@@ -2658,11 +2773,11 @@ var DMChannel = class extends TextCapable(Channel) {
2658
2773
  };
2659
2774
 
2660
2775
  // src/Domain/Channel/Forum.ts
2661
- var import_types19 = require("@fluxerjs/types");
2776
+ var import_types20 = require("@fluxerjs/types");
2662
2777
 
2663
2778
  // src/Domain/Channel/Guild.ts
2664
- var import_types16 = require("@fluxerjs/types");
2665
- var import_util13 = require("@fluxerjs/util");
2779
+ var import_types17 = require("@fluxerjs/types");
2780
+ var import_util14 = require("@fluxerjs/util");
2666
2781
 
2667
2782
  // src/Domain/Invite.ts
2668
2783
  var import_types13 = require("@fluxerjs/types");
@@ -2670,17 +2785,19 @@ var import_types13 = require("@fluxerjs/types");
2670
2785
  // src/Helpers/Instance.ts
2671
2786
  var import_util9 = require("@fluxerjs/util");
2672
2787
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2673
- api: "https://web.fluxer.app/api",
2674
- api_client: "https://web.fluxer.app/api",
2675
- api_public: "https://api.fluxer.app",
2676
- gateway: "wss://gateway.fluxer.app",
2788
+ api: "https://fluxer.com/api",
2789
+ api_client: "https://fluxer.com/api",
2790
+ api_public: "https://fluxer.com/api",
2791
+ gateway: "wss://gateway.fluxer.com",
2677
2792
  media: CDN_URL,
2793
+ upload_relay: "https://uploads.fluxer.app",
2678
2794
  static_cdn: STATIC_CDN_URL,
2679
- marketing: "https://fluxer.app",
2795
+ marketing: "https://fluxer.com",
2796
+ docs: "https://docs.fluxer.com",
2680
2797
  admin: "https://admin.fluxer.app",
2681
2798
  invite: "https://fluxer.gg",
2682
2799
  gift: "https://fluxer.gift",
2683
- webapp: "https://web.fluxer.app"
2800
+ webapp: "https://fluxer.com"
2684
2801
  });
2685
2802
  var ENDPOINT_KEYS = [
2686
2803
  "api",
@@ -2695,6 +2812,11 @@ var ENDPOINT_KEYS = [
2695
2812
  "gift",
2696
2813
  "webapp"
2697
2814
  ];
2815
+ var OPTIONAL_ENDPOINT_KEYS = [
2816
+ "api_transport",
2817
+ "upload_relay",
2818
+ "docs"
2819
+ ];
2698
2820
  function requireString(obj, key, path) {
2699
2821
  const value = obj[key];
2700
2822
  if (typeof value !== "string" || value.length === 0) {
@@ -2735,6 +2857,10 @@ function parseInstanceDiscovery(raw) {
2735
2857
  for (const key of ENDPOINT_KEYS) {
2736
2858
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2737
2859
  }
2860
+ for (const key of OPTIONAL_ENDPOINT_KEYS) {
2861
+ const value = raw.endpoints[key];
2862
+ if (typeof value === "string" && value.length > 0) endpoints[key] = value;
2863
+ }
2738
2864
  endpoints.api = normalizeApiOrigin(endpoints.api);
2739
2865
  endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2740
2866
  endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
@@ -2788,7 +2914,21 @@ function parseInstanceDiscovery(raw) {
2788
2914
  defaultsHash: ""
2789
2915
  },
2790
2916
  push: raw.push ?? { public_vapid_key: null },
2791
- app_public: raw.app_public ?? {}
2917
+ app_public: raw.app_public ?? {},
2918
+ ...typeof raw.codename === "string" ? { codename: raw.codename } : {},
2919
+ age_policy: (0, import_util9.isRecord)(raw.age_policy) ? raw.age_policy : { geos: [] },
2920
+ ...raw.notice === null || (0, import_util9.isRecord)(raw.notice) ? { notice: raw.notice } : {},
2921
+ ...(0, import_util9.isRecord)(raw.domain_migration) ? { domain_migration: raw.domain_migration } : {},
2922
+ ...Array.isArray(raw.guild_badges) ? { guild_badges: raw.guild_badges } : {},
2923
+ ...typeof raw.guild_badges_partial === "boolean" ? { guild_badges_partial: raw.guild_badges_partial } : {},
2924
+ ...typeof raw.custom_badges_version === "string" ? { custom_badges_version: raw.custom_badges_version } : {},
2925
+ ...(0, import_util9.isRecord)(raw.built_in_guild_badge_images) ? {
2926
+ built_in_guild_badge_images: raw.built_in_guild_badge_images
2927
+ } : {},
2928
+ ...Array.isArray(raw.hidden_built_in_guild_badges) ? {
2929
+ hidden_built_in_guild_badges: raw.hidden_built_in_guild_badges
2930
+ } : {},
2931
+ ...Array.isArray(raw.voice_origins) ? { voice_origins: raw.voice_origins } : {}
2792
2932
  };
2793
2933
  }
2794
2934
  function resolveInstanceEndpoints(input) {
@@ -2808,7 +2948,7 @@ function resolveInstanceEndpoints(input) {
2808
2948
  }
2809
2949
  const partial = input;
2810
2950
  const merged = { ...DEFAULT_INSTANCE_ENDPOINTS };
2811
- for (const key of ENDPOINT_KEYS) {
2951
+ for (const key of [...ENDPOINT_KEYS, ...OPTIONAL_ENDPOINT_KEYS]) {
2812
2952
  const value = partial[key];
2813
2953
  if (typeof value === "string" && value.length > 0) {
2814
2954
  merged[key] = value;
@@ -3227,6 +3367,127 @@ var PermissionOverwriteManager = class {
3227
3367
  }
3228
3368
  };
3229
3369
 
3370
+ // src/Domain/StageInstance.ts
3371
+ var import_types16 = require("@fluxerjs/types");
3372
+ var import_util13 = require("@fluxerjs/util");
3373
+ var StageInstance = class extends Base {
3374
+ client;
3375
+ id;
3376
+ guildId;
3377
+ channelId;
3378
+ topic;
3379
+ /** Always {@link StageInstancePrivacyLevel.GuildOnly} on Fluxer. */
3380
+ privacyLevel;
3381
+ /** Always `true` on Fluxer. */
3382
+ discoverableDisabled;
3383
+ /** Always null on Fluxer. */
3384
+ guildScheduledEventId;
3385
+ constructor(client, data) {
3386
+ super();
3387
+ this.client = client;
3388
+ this.id = data.id;
3389
+ this.guildId = data.guild_id;
3390
+ this.channelId = data.channel_id;
3391
+ this.topic = data.topic;
3392
+ this.privacyLevel = data.privacy_level ?? import_types16.StageInstancePrivacyLevel.GuildOnly;
3393
+ this.discoverableDisabled = data.discoverable_disabled ?? true;
3394
+ this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
3395
+ }
3396
+ /** @internal Patch in place from a newer payload. */
3397
+ _patch(data) {
3398
+ if (data.topic !== void 0) this.topic = data.topic;
3399
+ if (data.privacy_level !== void 0) this.privacyLevel = data.privacy_level;
3400
+ if (data.discoverable_disabled !== void 0) {
3401
+ this.discoverableDisabled = data.discoverable_disabled;
3402
+ }
3403
+ if (data.guild_scheduled_event_id !== void 0) {
3404
+ this.guildScheduledEventId = data.guild_scheduled_event_id ?? null;
3405
+ }
3406
+ }
3407
+ get guild() {
3408
+ return this.client.guilds.get(this.guildId) ?? null;
3409
+ }
3410
+ get channel() {
3411
+ const channel = this.client.channels.get(this.channelId);
3412
+ return channel?.isStage() ? channel : null;
3413
+ }
3414
+ /** Unix timestamp (ms) when the stage started, from its snowflake ID. */
3415
+ get createdTimestamp() {
3416
+ return import_util13.SnowflakeUtil.timestampFromSnowflake(this.id);
3417
+ }
3418
+ get createdAt() {
3419
+ return import_util13.SnowflakeUtil.dateFromSnowflake(this.id);
3420
+ }
3421
+ /**
3422
+ * Change the live stage. Needs a stage moderator.
3423
+ * Fires `STAGE_INSTANCE_UPDATE`.
3424
+ */
3425
+ async edit(options) {
3426
+ const body = {};
3427
+ if (options.topic !== void 0) body.topic = options.topic;
3428
+ const data = await this.client.rest.patch(
3429
+ import_types16.Routes.stageInstance(this.channelId),
3430
+ { body, auth: true, ...auditReasonHeaders(options.reason) }
3431
+ );
3432
+ this._patch(data);
3433
+ return this;
3434
+ }
3435
+ /** Change the stage topic. Shorthand for {@link edit}. */
3436
+ async setTopic(topic, reason) {
3437
+ return this.edit({ topic, reason });
3438
+ }
3439
+ /**
3440
+ * End the stage. Needs a stage moderator. Speakers move to the audience, raised hands are
3441
+ * lowered, and everyone stays connected unless `disconnectAll` is set.
3442
+ */
3443
+ async delete(options = {}) {
3444
+ const route = import_types16.Routes.stageInstance(this.channelId) + (options.disconnectAll ? "?disconnect_all=true" : "");
3445
+ await this.client.rest.delete(route, { auth: true, ...auditReasonHeaders(options.reason) });
3446
+ }
3447
+ toJSON() {
3448
+ return {
3449
+ id: this.id,
3450
+ guild_id: this.guildId,
3451
+ channel_id: this.channelId,
3452
+ topic: this.topic,
3453
+ privacy_level: this.privacyLevel,
3454
+ discoverable_disabled: this.discoverableDisabled,
3455
+ guild_scheduled_event_id: this.guildScheduledEventId
3456
+ };
3457
+ }
3458
+ };
3459
+
3460
+ // src/Domain/Channel/StageSync.ts
3461
+ function syncStageInstances(guild, instances) {
3462
+ const seen = /* @__PURE__ */ new Set();
3463
+ for (const data of instances) {
3464
+ seen.add(data.id);
3465
+ const existing = guild.stageInstances.get(data.id);
3466
+ if (existing) existing._patch(data);
3467
+ else guild.stageInstances.set(data.id, new StageInstance(guild.client, data));
3468
+ }
3469
+ for (const id of [...guild.stageInstances.keys()]) {
3470
+ if (!seen.has(id)) guild.stageInstances.delete(id);
3471
+ }
3472
+ }
3473
+ function applyStageCounts(guild, counts) {
3474
+ for (const count of counts) {
3475
+ const channel = guild.channels.get(count.channel_id);
3476
+ if (channel?.isStage()) channel._patchCounts(count);
3477
+ }
3478
+ }
3479
+ function cacheStageInstance(client, data) {
3480
+ const guild = client.guilds.get(data.guild_id);
3481
+ const existing = guild?.stageInstances.get(data.id);
3482
+ if (existing) {
3483
+ existing._patch(data);
3484
+ return existing;
3485
+ }
3486
+ const instance = new StageInstance(client, data);
3487
+ guild?.stageInstances.set(instance.id, instance);
3488
+ return instance;
3489
+ }
3490
+
3230
3491
  // src/Domain/Channel/ThreadBind.ts
3231
3492
  var factory;
3232
3493
  var managers = /* @__PURE__ */ new WeakMap();
@@ -3281,7 +3542,7 @@ var GuildChannel = class extends Channel {
3281
3542
  }
3282
3543
  /** Create a webhook for this channel. Requires Manage Webhooks. */
3283
3544
  async createWebhook(options) {
3284
- const data = await this.client.rest.post(import_types16.Routes.channelWebhooks(this.id), {
3545
+ const data = await this.client.rest.post(import_types17.Routes.channelWebhooks(this.id), {
3285
3546
  body: options,
3286
3547
  auth: true
3287
3548
  });
@@ -3289,13 +3550,13 @@ var GuildChannel = class extends Channel {
3289
3550
  }
3290
3551
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
3291
3552
  async fetchWebhooks() {
3292
- const data = await this.client.rest.get(import_types16.Routes.channelWebhooks(this.id));
3553
+ const data = await this.client.rest.get(import_types17.Routes.channelWebhooks(this.id));
3293
3554
  return data.map((w) => new Webhook(this.client, w));
3294
3555
  }
3295
3556
  /** Create an invite for this channel. Requires Create Instant Invite. */
3296
3557
  async createInvite(options) {
3297
3558
  const body = options ? toChannelInviteBody(options) : {};
3298
- const data = await this.client.rest.post(import_types16.Routes.channelInvites(this.id), {
3559
+ const data = await this.client.rest.post(import_types17.Routes.channelInvites(this.id), {
3299
3560
  body: Object.keys(body).length ? body : void 0,
3300
3561
  auth: true
3301
3562
  });
@@ -3303,7 +3564,7 @@ var GuildChannel = class extends Channel {
3303
3564
  }
3304
3565
  /** Fetch all invites for this channel. Requires Manage Channels. */
3305
3566
  async fetchInvites() {
3306
- const data = await this.client.rest.get(import_types16.Routes.channelInvites(this.id));
3567
+ const data = await this.client.rest.get(import_types17.Routes.channelInvites(this.id));
3307
3568
  return data.map((i) => new Invite(this.client, i));
3308
3569
  }
3309
3570
  /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
@@ -3312,7 +3573,7 @@ var GuildChannel = class extends Channel {
3312
3573
  const me = this.client.guilds.get(this.guildId)?.members.me;
3313
3574
  if (!me) return false;
3314
3575
  const perms = me.permissionsIn(this);
3315
- return perms.has(import_util13.PermissionFlags.ViewChannel) && perms.has(import_util13.PermissionFlags.SendMessages);
3576
+ return perms.has(import_util14.PermissionFlags.ViewChannel) && perms.has(import_util14.PermissionFlags.SendMessages);
3316
3577
  }
3317
3578
  /**
3318
3579
  * Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
@@ -3333,7 +3594,7 @@ var GuildChannel = class extends Channel {
3333
3594
  }
3334
3595
  /** Edit this channel's settings. Requires Manage Channels. */
3335
3596
  async edit(options) {
3336
- const data = await this.client.rest.patch(import_types16.Routes.channel(this.id), {
3597
+ const data = await this.client.rest.patch(import_types17.Routes.channel(this.id), {
3337
3598
  body: toChannelEditBody(options),
3338
3599
  auth: true,
3339
3600
  ...auditReasonHeaders(options.reason)
@@ -3415,7 +3676,7 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3415
3676
  * Sends only those fields. The thread-parent update body does not accept a channel rename.
3416
3677
  */
3417
3678
  async editThreadDefaults(options) {
3418
- const data = await this.client.rest.patch(import_types16.Routes.channel(this.id), {
3679
+ const data = await this.client.rest.patch(import_types17.Routes.channel(this.id), {
3419
3680
  body: toThreadParentEditBody(options),
3420
3681
  auth: true,
3421
3682
  ...auditReasonHeaders(options.reason)
@@ -3425,6 +3686,23 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3425
3686
  }
3426
3687
  };
3427
3688
  var AnnouncementChannel = class extends TextChannel {
3689
+ /**
3690
+ * Follow this announcement channel into `webhookChannelId` (a channel in a guild
3691
+ * where the bot can manage webhooks). Published messages are copied there.
3692
+ */
3693
+ async follow(webhookChannelId) {
3694
+ return this.client.rest.post(
3695
+ import_types17.Routes.channelFollowers(this.id),
3696
+ { body: { webhook_channel_id: webhookChannelId }, auth: true }
3697
+ );
3698
+ }
3699
+ /** Fetch follower counts for this announcement channel. */
3700
+ async fetchFollowerStats() {
3701
+ return this.client.rest.get(
3702
+ import_types17.Routes.channelFollowerStats(this.id),
3703
+ { auth: true }
3704
+ );
3705
+ }
3428
3706
  };
3429
3707
  var CategoryChannel = class extends GuildChannel {
3430
3708
  };
@@ -3451,6 +3729,8 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3451
3729
  voiceConnectionLimit;
3452
3730
  /** RTC region override for this channel. */
3453
3731
  rtcRegion;
3732
+ /** Whether voice in this channel is peer-to-peer (`rtc_p2p`). */
3733
+ rtcP2p;
3454
3734
  constructor(client, data) {
3455
3735
  super(client, data);
3456
3736
  this.topic = data.topic ?? null;
@@ -3464,6 +3744,7 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3464
3744
  this.userLimit = data.user_limit ?? null;
3465
3745
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3466
3746
  this.rtcRegion = data.rtc_region ?? null;
3747
+ this.rtcP2p = data.rtc_p2p ?? false;
3467
3748
  }
3468
3749
  /**
3469
3750
  * Set slowmode (seconds between messages). Pass `0` to disable.
@@ -3490,6 +3771,97 @@ var VoiceChannel = class extends TextCapable(GuildChannel) {
3490
3771
  this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3491
3772
  }
3492
3773
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
3774
+ if ("rtc_p2p" in data) this.rtcP2p = data.rtc_p2p ?? false;
3775
+ }
3776
+ };
3777
+ var StageChannel = class extends VoiceChannel {
3778
+ /** Last known stage counts, or null until Fluxer sends them. */
3779
+ counts = null;
3780
+ /** The cached live stage of this channel, or null when the stage isn't live (or not cached). */
3781
+ get stageInstance() {
3782
+ const guild = this.client.guilds.get(this.guildId);
3783
+ if (!guild) return null;
3784
+ for (const instance of guild.stageInstances.values()) {
3785
+ if (instance.channelId === this.id) return instance;
3786
+ }
3787
+ return null;
3788
+ }
3789
+ /** Whether the stage is live according to the cache. */
3790
+ get isLive() {
3791
+ return this.stageInstance !== null;
3792
+ }
3793
+ /**
3794
+ * Start a stage in this channel. Needs a stage moderator (`MANAGE_CHANNELS`, `MUTE_MEMBERS` and
3795
+ * `MOVE_MEMBERS`). When the caller is connected to the stage, they become a speaker.
3796
+ */
3797
+ async createStageInstance(options) {
3798
+ const body = { channel_id: this.id, topic: options.topic };
3799
+ if (options.sendStartNotification !== void 0) {
3800
+ body.send_start_notification = options.sendStartNotification;
3801
+ }
3802
+ const data = await this.client.rest.post(import_types17.Routes.stageInstances(), {
3803
+ body,
3804
+ auth: true,
3805
+ ...auditReasonHeaders(options.reason)
3806
+ });
3807
+ return cacheStageInstance(this.client, data);
3808
+ }
3809
+ /** Fetch the live stage of this channel. Rejects with `UNKNOWN_STAGE_INSTANCE` when not live. */
3810
+ async fetchStageInstance() {
3811
+ const data = await this.client.rest.get(import_types17.Routes.stageInstance(this.id), {
3812
+ auth: true
3813
+ });
3814
+ return cacheStageInstance(this.client, data);
3815
+ }
3816
+ /**
3817
+ * Move a member (or yourself when `user` is omitted) between the audience and the speakers.
3818
+ *
3819
+ * - Yourself, `false`: become a speaker (needs `MUTE_MEMBERS`), or accept an open invite.
3820
+ * - Yourself, `true`: move to the audience, or decline an invite.
3821
+ * - Another member, `false`: invite them to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`.
3822
+ * - Another member, `true`: move them to the audience and clear a raised hand or invite.
3823
+ */
3824
+ async setSuppressed(suppressed, user) {
3825
+ const userId = user === void 0 ? "@me" : typeof user === "string" ? user : user.id;
3826
+ const body = {
3827
+ channel_id: this.id,
3828
+ suppress: suppressed
3829
+ };
3830
+ await this.client.rest.patch(import_types17.Routes.guildVoiceState(this.guildId, userId), {
3831
+ body,
3832
+ auth: true
3833
+ });
3834
+ }
3835
+ /** Invite a member to speak (a bot becomes a speaker at once). Needs `MUTE_MEMBERS`. */
3836
+ async inviteToSpeak(user) {
3837
+ await this.setSuppressed(false, user);
3838
+ }
3839
+ /** Move a speaker (or yourself when `user` is omitted) to the audience. */
3840
+ async moveToAudience(user) {
3841
+ await this.setSuppressed(true, user);
3842
+ }
3843
+ /**
3844
+ * Raise (`true`) or lower (`false`) your hand. Raising needs a live stage and
3845
+ * `REQUEST_TO_SPEAK`; lowering also accepts an open invite to speak.
3846
+ */
3847
+ async setRequestToSpeak(raised = true) {
3848
+ const body = {
3849
+ channel_id: this.id,
3850
+ request_to_speak_timestamp: raised ? (/* @__PURE__ */ new Date()).toISOString() : null
3851
+ };
3852
+ await this.client.rest.patch(import_types17.Routes.guildVoiceState(this.guildId, "@me"), {
3853
+ body,
3854
+ auth: true
3855
+ });
3856
+ }
3857
+ /** @internal Apply a stage count object. */
3858
+ _patchCounts(data) {
3859
+ this.counts = {
3860
+ listenerCount: data.listener_count,
3861
+ speakerCount: data.speaker_count,
3862
+ requestCount: data.request_count,
3863
+ videoEnabled: data.video_enabled ?? null
3864
+ };
3493
3865
  }
3494
3866
  };
3495
3867
  var LinkChannel = class extends GuildChannel {
@@ -3505,10 +3877,10 @@ var LinkChannel = class extends GuildChannel {
3505
3877
  };
3506
3878
 
3507
3879
  // src/Domain/Channel/ThreadManager.ts
3508
- var import_types18 = require("@fluxerjs/types");
3880
+ var import_types19 = require("@fluxerjs/types");
3509
3881
 
3510
3882
  // src/Domain/Channel/ThreadChannel.ts
3511
- var import_types17 = require("@fluxerjs/types");
3883
+ var import_types18 = require("@fluxerjs/types");
3512
3884
  var ThreadMember = class {
3513
3885
  /** Thread ID. */
3514
3886
  id;
@@ -3635,7 +4007,7 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
3635
4007
  * `appliedTags` is sent for public and announcement threads. `invitable` is sent for private threads.
3636
4008
  */
3637
4009
  async edit(options) {
3638
- const data = await this.client.rest.patch(import_types17.Routes.channel(this.id), {
4010
+ const data = await this.client.rest.patch(import_types18.Routes.channel(this.id), {
3639
4011
  body: toThreadEditBody(this.type, threadEditFields(options)),
3640
4012
  auth: true,
3641
4013
  ...auditReasonHeaders(options.reason)
@@ -3653,16 +4025,16 @@ var ThreadChannel = class extends TextCapable(GuildChannel) {
3653
4025
  }
3654
4026
  /** Join this thread. */
3655
4027
  async join() {
3656
- await this.client.rest.put(import_types17.Routes.channelThreadMemberMe(this.id), { auth: true });
4028
+ await this.client.rest.put(import_types18.Routes.channelThreadMemberMe(this.id), { auth: true });
3657
4029
  }
3658
4030
  /** Leave this thread. */
3659
4031
  async leave() {
3660
- await this.client.rest.delete(import_types17.Routes.channelThreadMemberMe(this.id), { auth: true });
4032
+ await this.client.rest.delete(import_types18.Routes.channelThreadMemberMe(this.id), { auth: true });
3661
4033
  }
3662
4034
  /** Update the current user's notification settings for this thread. */
3663
4035
  async editSelf(options) {
3664
4036
  const data = await this.client.rest.patch(
3665
- import_types17.Routes.channelThreadMemberMeSettings(this.id),
4037
+ import_types18.Routes.channelThreadMemberMeSettings(this.id),
3666
4038
  { body: toThreadMemberSettingsBody(options), auth: true }
3667
4039
  );
3668
4040
  this.member = data ? new ThreadMember(data) : null;
@@ -3676,7 +4048,7 @@ var ThreadMemberManager = class {
3676
4048
  /** List members of this thread. */
3677
4049
  async fetch(options) {
3678
4050
  const data = await this.thread.client.rest.get(
3679
- withQuery(import_types17.Routes.channelThreadMembers(this.thread.id), {
4051
+ withQuery(import_types18.Routes.channelThreadMembers(this.thread.id), {
3680
4052
  with_member: options?.withMember === void 0 ? void 0 : String(options.withMember),
3681
4053
  after: options?.after,
3682
4054
  limit: options?.limit
@@ -3687,7 +4059,7 @@ var ThreadMemberManager = class {
3687
4059
  /** Fetch one member of this thread. */
3688
4060
  async fetchOne(userId, options) {
3689
4061
  const data = await this.thread.client.rest.get(
3690
- withQuery(import_types17.Routes.channelThreadMember(this.thread.id, userId), {
4062
+ withQuery(import_types18.Routes.channelThreadMember(this.thread.id, userId), {
3691
4063
  with_member: options?.withMember === void 0 ? void 0 : String(options.withMember)
3692
4064
  })
3693
4065
  );
@@ -3695,19 +4067,19 @@ var ThreadMemberManager = class {
3695
4067
  }
3696
4068
  /** Add a user to this thread. Private threads only, unless the caller can manage the parent. */
3697
4069
  async add(userId) {
3698
- await this.thread.client.rest.put(import_types17.Routes.channelThreadMember(this.thread.id, userId), {
4070
+ await this.thread.client.rest.put(import_types18.Routes.channelThreadMember(this.thread.id, userId), {
3699
4071
  auth: true
3700
4072
  });
3701
4073
  }
3702
4074
  /** Remove a user from this thread. */
3703
4075
  async remove(userId) {
3704
- await this.thread.client.rest.delete(import_types17.Routes.channelThreadMember(this.thread.id, userId), {
4076
+ await this.thread.client.rest.delete(import_types18.Routes.channelThreadMember(this.thread.id, userId), {
3705
4077
  auth: true
3706
4078
  });
3707
4079
  }
3708
4080
  };
3709
4081
  function isThreadType(type) {
3710
- return type === import_types17.ChannelType.AnnouncementThread || type === import_types17.ChannelType.PublicThread || type === import_types17.ChannelType.PrivateThread;
4082
+ return type === import_types18.ChannelType.AnnouncementThread || type === import_types18.ChannelType.PublicThread || type === import_types18.ChannelType.PrivateThread;
3711
4083
  }
3712
4084
 
3713
4085
  // src/Domain/Channel/ThreadManager.ts
@@ -3720,13 +4092,13 @@ var ThreadManager = class {
3720
4092
  * Forum and media channels must use {@link createPost}.
3721
4093
  */
3722
4094
  async create(options) {
3723
- if (this.channel.type === import_types18.ChannelType.GuildForum || this.channel.type === import_types18.ChannelType.GuildMedia) {
4095
+ if (this.channel.type === import_types19.ChannelType.GuildForum || this.channel.type === import_types19.ChannelType.GuildMedia) {
3724
4096
  throw new import_util4.FluxerError("Forum and media channels start posts with createPost", {
3725
4097
  code: import_util3.ErrorCodes.InvalidChannelType
3726
4098
  });
3727
4099
  }
3728
4100
  const data = await this.channel.client.rest.post(
3729
- import_types18.Routes.channelThreads(this.channel.id),
4101
+ import_types19.Routes.channelThreads(this.channel.id),
3730
4102
  {
3731
4103
  body: toStartThreadBody(this.channel.type, options),
3732
4104
  auth: true,
@@ -3740,7 +4112,7 @@ var ThreadManager = class {
3740
4112
  * The post is a public thread. `message` is its first message.
3741
4113
  */
3742
4114
  async createPost(options) {
3743
- if (this.channel.type !== import_types18.ChannelType.GuildForum && this.channel.type !== import_types18.ChannelType.GuildMedia) {
4115
+ if (this.channel.type !== import_types19.ChannelType.GuildForum && this.channel.type !== import_types19.ChannelType.GuildMedia) {
3744
4116
  throw new import_util4.FluxerError("createPost is for forum and media channels", {
3745
4117
  code: import_util3.ErrorCodes.InvalidChannelType
3746
4118
  });
@@ -3750,7 +4122,7 @@ var ThreadManager = class {
3750
4122
  });
3751
4123
  const body = {
3752
4124
  name: options.name,
3753
- type: import_types18.ChannelType.PublicThread,
4125
+ type: import_types19.ChannelType.PublicThread,
3754
4126
  message: toForumThreadMessage(prepared.body)
3755
4127
  };
3756
4128
  if (options.autoArchiveDuration !== void 0) {
@@ -3759,7 +4131,7 @@ var ThreadManager = class {
3759
4131
  if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
3760
4132
  if (options.appliedTags !== void 0) body.applied_tags = options.appliedTags;
3761
4133
  const data = await this.channel.client.rest.post(
3762
- import_types18.Routes.channelThreads(this.channel.id),
4134
+ import_types19.Routes.channelThreads(this.channel.id),
3763
4135
  {
3764
4136
  body,
3765
4137
  files: prepared.files,
@@ -3778,7 +4150,7 @@ var ThreadManager = class {
3778
4150
  * `before` is an ISO-8601 archive timestamp.
3779
4151
  */
3780
4152
  async fetchArchived(options) {
3781
- const path = options.type === "private" ? import_types18.Routes.channelThreadsArchivedPrivate(this.channel.id) : import_types18.Routes.channelThreadsArchivedPublic(this.channel.id);
4153
+ const path = options.type === "private" ? import_types19.Routes.channelThreadsArchivedPrivate(this.channel.id) : import_types19.Routes.channelThreadsArchivedPublic(this.channel.id);
3782
4154
  const data = await this.channel.client.rest.get(
3783
4155
  withQuery(path, { before: options.before, limit: options.limit })
3784
4156
  );
@@ -3790,7 +4162,7 @@ var ThreadManager = class {
3790
4162
  */
3791
4163
  async fetchJoinedPrivateArchived(options) {
3792
4164
  const data = await this.channel.client.rest.get(
3793
- withQuery(import_types18.Routes.channelJoinedArchivedPrivateThreads(this.channel.id), {
4165
+ withQuery(import_types19.Routes.channelJoinedArchivedPrivateThreads(this.channel.id), {
3794
4166
  before: options?.before,
3795
4167
  limit: options?.limit
3796
4168
  })
@@ -3803,7 +4175,7 @@ var ThreadManager = class {
3803
4175
  */
3804
4176
  async search(options) {
3805
4177
  const data = await this.channel.client.rest.get(
3806
- withQuery(import_types18.Routes.channelThreadSearch(this.channel.id), {
4178
+ withQuery(import_types19.Routes.channelThreadSearch(this.channel.id), {
3807
4179
  name: options?.name,
3808
4180
  tag: options?.tag,
3809
4181
  tag_setting: options?.tagSetting,
@@ -3831,7 +4203,7 @@ var ThreadManager = class {
3831
4203
  }
3832
4204
  /** Set the auto-archive and slowmode defaults copied onto new threads. */
3833
4205
  async editDefaults(options) {
3834
- return this.channel.client.rest.patch(import_types18.Routes.channel(this.channel.id), {
4206
+ return this.channel.client.rest.patch(import_types19.Routes.channel(this.channel.id), {
3835
4207
  body: toThreadParentEditBody(options),
3836
4208
  auth: true,
3837
4209
  ...auditReasonHeaders(options.reason)
@@ -3849,7 +4221,7 @@ function isSearchNotReady(data) {
3849
4221
  return "code" in data && data.code === "SEARCH_INDEX_NOT_READY";
3850
4222
  }
3851
4223
  async function fetchActiveThreads(client, guildId) {
3852
- const data = await client.rest.get(import_types18.Routes.guildActiveThreads(guildId));
4224
+ const data = await client.rest.get(import_types19.Routes.guildActiveThreads(guildId));
3853
4225
  return fetchedThreadsFrom(client, data);
3854
4226
  }
3855
4227
 
@@ -3908,10 +4280,10 @@ var ThreadOnlyChannel = class extends GuildChannel {
3908
4280
  * `defaultForumLayout` is sent only for forum channels.
3909
4281
  */
3910
4282
  async edit(options) {
3911
- const data = await this.client.rest.patch(import_types19.Routes.channel(this.id), {
4283
+ const data = await this.client.rest.patch(import_types20.Routes.channel(this.id), {
3912
4284
  body: {
3913
4285
  ...toChannelEditBody(options),
3914
- ...forumParentWire(options, this.type === import_types19.ChannelType.GuildForum)
4286
+ ...forumParentWire(options, this.type === import_types20.ChannelType.GuildForum)
3915
4287
  },
3916
4288
  auth: true,
3917
4289
  ...auditReasonHeaders(options.reason)
@@ -3937,7 +4309,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3937
4309
  }
3938
4310
  /** Set the auto-archive and slowmode defaults copied onto new posts. */
3939
4311
  async editThreadDefaults(options) {
3940
- const data = await this.client.rest.patch(import_types19.Routes.channel(this.id), {
4312
+ const data = await this.client.rest.patch(import_types20.Routes.channel(this.id), {
3941
4313
  body: toThreadParentEditBody(options),
3942
4314
  auth: true,
3943
4315
  ...auditReasonHeaders(options.reason)
@@ -3947,7 +4319,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3947
4319
  }
3948
4320
  /** Create a tag. The response replaces {@link availableTags}. */
3949
4321
  async createTag(options) {
3950
- const data = await this.client.rest.post(import_types19.Routes.channelTags(this.id), {
4322
+ const data = await this.client.rest.post(import_types20.Routes.channelTags(this.id), {
3951
4323
  body: toForumTagBody(options),
3952
4324
  auth: true,
3953
4325
  ...auditReasonHeaders(options.reason)
@@ -3957,7 +4329,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3957
4329
  }
3958
4330
  /** Replace a tag. The response replaces {@link availableTags}. */
3959
4331
  async editTag(tagId, options) {
3960
- const data = await this.client.rest.put(import_types19.Routes.channelTag(this.id, tagId), {
4332
+ const data = await this.client.rest.put(import_types20.Routes.channelTag(this.id, tagId), {
3961
4333
  body: toForumTagBody(options),
3962
4334
  auth: true,
3963
4335
  ...auditReasonHeaders(options.reason)
@@ -3967,7 +4339,7 @@ var ThreadOnlyChannel = class extends GuildChannel {
3967
4339
  }
3968
4340
  /** Delete a tag. The response replaces {@link availableTags}. */
3969
4341
  async deleteTag(tagId, reason) {
3970
- const data = await this.client.rest.delete(import_types19.Routes.channelTag(this.id, tagId), {
4342
+ const data = await this.client.rest.delete(import_types20.Routes.channelTag(this.id, tagId), {
3971
4343
  auth: true,
3972
4344
  ...auditReasonHeaders(reason)
3973
4345
  });
@@ -3996,23 +4368,24 @@ var MediaChannel = class extends ThreadOnlyChannel {
3996
4368
  };
3997
4369
 
3998
4370
  // src/Domain/Channel/Factory.ts
3999
- var import_types20 = require("@fluxerjs/types");
4371
+ var import_types21 = require("@fluxerjs/types");
4000
4372
  var GUILD_FACTORIES = {
4001
- [import_types20.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
4002
- [import_types20.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
4003
- [import_types20.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
4004
- [import_types20.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
4005
- [import_types20.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d),
4006
- [import_types20.ChannelType.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
4007
- [import_types20.ChannelType.PublicThread]: (c, d) => new ThreadChannel(c, d),
4008
- [import_types20.ChannelType.PrivateThread]: (c, d) => new ThreadChannel(c, d),
4009
- [import_types20.ChannelType.GuildForum]: (c, d) => new ForumChannel(c, d),
4010
- [import_types20.ChannelType.GuildMedia]: (c, d) => new MediaChannel(c, d)
4373
+ [import_types21.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
4374
+ [import_types21.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
4375
+ [import_types21.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
4376
+ [import_types21.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
4377
+ [import_types21.ChannelType.GuildStageVoice]: (c, d) => new StageChannel(c, d),
4378
+ [import_types21.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d),
4379
+ [import_types21.ChannelType.AnnouncementThread]: (c, d) => new ThreadChannel(c, d),
4380
+ [import_types21.ChannelType.PublicThread]: (c, d) => new ThreadChannel(c, d),
4381
+ [import_types21.ChannelType.PrivateThread]: (c, d) => new ThreadChannel(c, d),
4382
+ [import_types21.ChannelType.GuildForum]: (c, d) => new ForumChannel(c, d),
4383
+ [import_types21.ChannelType.GuildMedia]: (c, d) => new MediaChannel(c, d)
4011
4384
  };
4012
4385
  var DM_TYPES = /* @__PURE__ */ new Set([
4013
- import_types20.ChannelType.DM,
4014
- import_types20.ChannelType.GroupDM,
4015
- import_types20.ChannelType.DMPersonalNotes
4386
+ import_types21.ChannelType.DM,
4387
+ import_types21.ChannelType.GroupDM,
4388
+ import_types21.ChannelType.DMPersonalNotes
4016
4389
  ]);
4017
4390
  function createDM(client, data) {
4018
4391
  return new DMChannel(client, data);
@@ -4055,12 +4428,15 @@ var User = class extends Base {
4055
4428
  system;
4056
4429
  /** Banner hash for profile. */
4057
4430
  banner;
4431
+ /** True when this user was created from an ID-only stub and not yet hydrated from REST/gateway. */
4432
+ partial;
4058
4433
  constructor(client, data) {
4059
4434
  super();
4060
4435
  this.client = client;
4061
4436
  this.id = data.id;
4062
- this.username = data.username;
4063
- this.discriminator = data.discriminator;
4437
+ this.partial = typeof data.username !== "string" || data.username.length === 0;
4438
+ this.username = data.username ?? "Unknown";
4439
+ this.discriminator = data.discriminator ?? "0";
4064
4440
  this.globalName = data.global_name ?? null;
4065
4441
  this.avatar = data.avatar ?? null;
4066
4442
  this.bot = !!data.bot;
@@ -4071,13 +4447,18 @@ var User = class extends Base {
4071
4447
  }
4072
4448
  /** @internal */
4073
4449
  _patch(data) {
4074
- this.username = data.username;
4075
- this.discriminator = data.discriminator;
4076
- this.globalName = data.global_name ?? null;
4077
- this.avatar = data.avatar ?? null;
4450
+ if (data.username !== void 0) this.username = data.username;
4451
+ if (data.discriminator !== void 0) this.discriminator = data.discriminator;
4452
+ if (data.global_name !== void 0) this.globalName = data.global_name ?? null;
4453
+ if (data.avatar !== void 0) this.avatar = data.avatar ?? null;
4078
4454
  if (data.avatar_color !== void 0) this.avatarColor = data.avatar_color;
4079
4455
  if (data.flags !== void 0) this.flags = data.flags;
4080
4456
  if (data.banner !== void 0) this.banner = data.banner;
4457
+ if (typeof data.username === "string" && data.username.length > 0) this.partial = false;
4458
+ }
4459
+ /** Fetch the full user from REST when this instance is a partial stub. */
4460
+ async fetch() {
4461
+ return this.client.users.fetch(this.id, { force: true });
4081
4462
  }
4082
4463
  cdnOpts() {
4083
4464
  return {
@@ -4115,11 +4496,11 @@ var User = class extends Base {
4115
4496
  */
4116
4497
  /** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
4117
4498
  get createdTimestamp() {
4118
- return import_util14.SnowflakeUtil.timestampFromSnowflake(this.id);
4499
+ return import_util15.SnowflakeUtil.timestampFromSnowflake(this.id);
4119
4500
  }
4120
4501
  /** Date when this account was created, derived from its snowflake ID. */
4121
4502
  get createdAt() {
4122
- return import_util14.SnowflakeUtil.dateFromSnowflake(this.id);
4503
+ return import_util15.SnowflakeUtil.dateFromSnowflake(this.id);
4123
4504
  }
4124
4505
  toString() {
4125
4506
  return `<@${this.id}>`;
@@ -4129,7 +4510,7 @@ var User = class extends Base {
4129
4510
  * @returns DM channel instance (cached if already open)
4130
4511
  */
4131
4512
  async createDM() {
4132
- const data = await this.client.rest.post(import_types21.Routes.userMeChannels(), {
4513
+ const data = await this.client.rest.post(import_types22.Routes.userMeChannels(), {
4133
4514
  body: { recipient_id: this.id },
4134
4515
  auth: true
4135
4516
  });
@@ -4346,14 +4727,14 @@ var CacheController = class {
4346
4727
 
4347
4728
  // src/ClientCore/ChannelManager.ts
4348
4729
  var import_collection8 = require("@fluxerjs/collection");
4349
- var import_types29 = require("@fluxerjs/types");
4730
+ var import_types30 = require("@fluxerjs/types");
4350
4731
 
4351
4732
  // src/Domain/Guild/Cache.ts
4352
- var import_types28 = require("@fluxerjs/types");
4733
+ var import_types29 = require("@fluxerjs/types");
4353
4734
 
4354
4735
  // src/Domain/Guild/GuildEmoji.ts
4355
- var import_types22 = require("@fluxerjs/types");
4356
- var import_util15 = require("@fluxerjs/util");
4736
+ var import_types23 = require("@fluxerjs/types");
4737
+ var import_util16 = require("@fluxerjs/util");
4357
4738
  var GuildEmoji = class extends Base {
4358
4739
  client;
4359
4740
  id;
@@ -4389,11 +4770,11 @@ var GuildEmoji = class extends Base {
4389
4770
  }
4390
4771
  /** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
4391
4772
  get createdTimestamp() {
4392
- return import_util15.SnowflakeUtil.timestampFromSnowflake(this.id);
4773
+ return import_util16.SnowflakeUtil.timestampFromSnowflake(this.id);
4393
4774
  }
4394
4775
  /** Date when this emoji was created, derived from its snowflake ID. */
4395
4776
  get createdAt() {
4396
- return import_util15.SnowflakeUtil.dateFromSnowflake(this.id);
4777
+ return import_util16.SnowflakeUtil.dateFromSnowflake(this.id);
4397
4778
  }
4398
4779
  /** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
4399
4780
  toString() {
@@ -4401,7 +4782,7 @@ var GuildEmoji = class extends Base {
4401
4782
  }
4402
4783
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
4403
4784
  async delete(reason) {
4404
- await this.client.rest.delete(import_types22.Routes.guildEmoji(this.guildId, this.id), {
4785
+ await this.client.rest.delete(import_types23.Routes.guildEmoji(this.guildId, this.id), {
4405
4786
  auth: true,
4406
4787
  ...auditReasonHeaders(reason)
4407
4788
  });
@@ -4414,7 +4795,7 @@ var GuildEmoji = class extends Base {
4414
4795
  */
4415
4796
  async edit(options) {
4416
4797
  const { reason, name } = options;
4417
- const data = await this.client.rest.patch(import_types22.Routes.guildEmoji(this.guildId, this.id), {
4798
+ const data = await this.client.rest.patch(import_types23.Routes.guildEmoji(this.guildId, this.id), {
4418
4799
  body: { name },
4419
4800
  auth: true,
4420
4801
  ...auditReasonHeaders(reason)
@@ -4425,20 +4806,20 @@ var GuildEmoji = class extends Base {
4425
4806
  };
4426
4807
 
4427
4808
  // src/Domain/Guild/GuildMember.ts
4428
- var import_types25 = require("@fluxerjs/types");
4429
- var import_util17 = require("@fluxerjs/util");
4809
+ var import_types26 = require("@fluxerjs/types");
4810
+ var import_util18 = require("@fluxerjs/util");
4430
4811
 
4431
4812
  // src/Helpers/Permissions.ts
4432
- var import_types23 = require("@fluxerjs/types");
4433
- var import_util16 = require("@fluxerjs/util");
4813
+ var import_types24 = require("@fluxerjs/types");
4814
+ var import_util17 = require("@fluxerjs/util");
4434
4815
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
4435
- if (isOwner) return import_util16.ALL_PERMISSIONS_BIGINT;
4436
- if ((basePermissions & import_util16.PermissionFlags.Administrator) !== 0n) {
4437
- return import_util16.ALL_PERMISSIONS_BIGINT;
4816
+ if (isOwner) return import_util17.ALL_PERMISSIONS_BIGINT;
4817
+ if ((basePermissions & import_util17.PermissionFlags.Administrator) !== 0n) {
4818
+ return import_util17.ALL_PERMISSIONS_BIGINT;
4438
4819
  }
4439
4820
  let perms = basePermissions;
4440
4821
  for (const overwrite of overwrites ?? []) {
4441
- const applies = overwrite.type === import_types23.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types23.OverwriteType.Member && overwrite.id === memberId;
4822
+ const applies = overwrite.type === import_types24.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types24.OverwriteType.Member && overwrite.id === memberId;
4442
4823
  if (!applies) continue;
4443
4824
  const allow = BigInt(overwrite.allow || "0");
4444
4825
  const deny = BigInt(overwrite.deny || "0");
@@ -4449,7 +4830,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
4449
4830
 
4450
4831
  // src/Domain/Guild/GuildMemberRoleManager.ts
4451
4832
  var import_collection7 = require("@fluxerjs/collection");
4452
- var import_types24 = require("@fluxerjs/types");
4833
+ var import_types25 = require("@fluxerjs/types");
4453
4834
  function roleId(roleOrId) {
4454
4835
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
4455
4836
  }
@@ -4478,7 +4859,7 @@ var GuildMemberRoleManager = class {
4478
4859
  const id = roleId(roleOrId);
4479
4860
  if (this.ids.includes(id)) return;
4480
4861
  await this.member.client.rest.put(
4481
- import_types24.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
4862
+ import_types25.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
4482
4863
  );
4483
4864
  this.ids.push(id);
4484
4865
  }
@@ -4487,13 +4868,13 @@ var GuildMemberRoleManager = class {
4487
4868
  const idx = this.ids.indexOf(id);
4488
4869
  if (idx === -1) return;
4489
4870
  await this.member.client.rest.delete(
4490
- import_types24.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
4871
+ import_types25.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
4491
4872
  );
4492
4873
  this.ids.splice(idx, 1);
4493
4874
  }
4494
4875
  async set(roleIds) {
4495
4876
  const data = await this.member.client.rest.patch(
4496
- import_types24.Routes.guildMember(this.member.guild.id, this.member.id),
4877
+ import_types25.Routes.guildMember(this.member.guild.id, this.member.id),
4497
4878
  { body: { roles: roleIds }, auth: true }
4498
4879
  );
4499
4880
  this.ids = data.roles ? [...data.roles] : [];
@@ -4647,7 +5028,7 @@ var GuildMember = class _GuildMember extends Base {
4647
5028
  */
4648
5029
  async edit(options) {
4649
5030
  const isMe = this.client.user?.id === this.id;
4650
- const route = isMe ? import_types25.Routes.guildMemberMe(this.guild.id) : import_types25.Routes.guildMember(this.guild.id, this.id);
5031
+ const route = isMe ? import_types26.Routes.guildMemberMe(this.guild.id) : import_types26.Routes.guildMember(this.guild.id, this.id);
4651
5032
  const data = await this.client.rest.patch(route, {
4652
5033
  body: toMemberEditBody(options),
4653
5034
  auth: true,
@@ -4664,7 +5045,7 @@ var GuildMember = class _GuildMember extends Base {
4664
5045
  * @see {@link permissionsIn} for channel-specific permissions
4665
5046
  */
4666
5047
  get permissions() {
4667
- return new import_util17.PermissionsBitField(this._effectivePermissions([], []));
5048
+ return new import_util18.PermissionsBitField(this._effectivePermissions([], []));
4668
5049
  }
4669
5050
  /**
4670
5051
  * Effective permissions in a channel (roles + overwrites).
@@ -4672,7 +5053,7 @@ var GuildMember = class _GuildMember extends Base {
4672
5053
  * @returns Computed permissions bitfield
4673
5054
  */
4674
5055
  permissionsIn(channel) {
4675
- return new import_util17.PermissionsBitField(
5056
+ return new import_util18.PermissionsBitField(
4676
5057
  this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
4677
5058
  );
4678
5059
  }
@@ -4697,19 +5078,19 @@ var GuildMember = class _GuildMember extends Base {
4697
5078
  * False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
4698
5079
  */
4699
5080
  get kickable() {
4700
- return this._moderatableWith(import_util17.PermissionFlags.KickMembers);
5081
+ return this._moderatableWith(import_util18.PermissionFlags.KickMembers);
4701
5082
  }
4702
5083
  /**
4703
5084
  * Whether the bot can ban this member (cache-only; needs `members.me`).
4704
5085
  */
4705
5086
  get bannable() {
4706
- return this._moderatableWith(import_util17.PermissionFlags.BanMembers);
5087
+ return this._moderatableWith(import_util18.PermissionFlags.BanMembers);
4707
5088
  }
4708
5089
  /**
4709
5090
  * Whether the bot can timeout this member (cache-only; needs `members.me`).
4710
5091
  */
4711
5092
  get moderatable() {
4712
- return this._moderatableWith(import_util17.PermissionFlags.ModerateMembers);
5093
+ return this._moderatableWith(import_util18.PermissionFlags.ModerateMembers);
4713
5094
  }
4714
5095
  _moderatableWith(flag) {
4715
5096
  const me = this.guild.members.me;
@@ -4760,8 +5141,8 @@ var GuildMember = class _GuildMember extends Base {
4760
5141
  };
4761
5142
 
4762
5143
  // src/Domain/Guild/GuildSticker.ts
4763
- var import_types26 = require("@fluxerjs/types");
4764
- var import_util18 = require("@fluxerjs/util");
5144
+ var import_types27 = require("@fluxerjs/types");
5145
+ var import_util19 = require("@fluxerjs/util");
4765
5146
  var GuildSticker = class extends Base {
4766
5147
  client;
4767
5148
  id;
@@ -4803,15 +5184,15 @@ var GuildSticker = class extends Base {
4803
5184
  }
4804
5185
  /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
4805
5186
  get createdTimestamp() {
4806
- return import_util18.SnowflakeUtil.timestampFromSnowflake(this.id);
5187
+ return import_util19.SnowflakeUtil.timestampFromSnowflake(this.id);
4807
5188
  }
4808
5189
  /** Date when this sticker was created, derived from its snowflake ID. */
4809
5190
  get createdAt() {
4810
- return import_util18.SnowflakeUtil.dateFromSnowflake(this.id);
5191
+ return import_util19.SnowflakeUtil.dateFromSnowflake(this.id);
4811
5192
  }
4812
5193
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
4813
5194
  async delete(reason) {
4814
- await this.client.rest.delete(import_types26.Routes.guildSticker(this.guildId, this.id), {
5195
+ await this.client.rest.delete(import_types27.Routes.guildSticker(this.guildId, this.id), {
4815
5196
  auth: true,
4816
5197
  ...auditReasonHeaders(reason)
4817
5198
  });
@@ -4824,7 +5205,7 @@ var GuildSticker = class extends Base {
4824
5205
  */
4825
5206
  async edit(options) {
4826
5207
  const { reason, ...body } = options;
4827
- const data = await this.client.rest.patch(import_types26.Routes.guildSticker(this.guildId, this.id), {
5208
+ const data = await this.client.rest.patch(import_types27.Routes.guildSticker(this.guildId, this.id), {
4828
5209
  body,
4829
5210
  auth: true,
4830
5211
  ...auditReasonHeaders(reason)
@@ -4837,8 +5218,8 @@ var GuildSticker = class extends Base {
4837
5218
  };
4838
5219
 
4839
5220
  // src/Domain/Guild/Role.ts
4840
- var import_types27 = require("@fluxerjs/types");
4841
- var import_util19 = require("@fluxerjs/util");
5221
+ var import_types28 = require("@fluxerjs/types");
5222
+ var import_util20 = require("@fluxerjs/util");
4842
5223
  var Role = class _Role extends Base {
4843
5224
  /** Parent client instance. */
4844
5225
  client;
@@ -4860,6 +5241,8 @@ var Role = class _Role extends Base {
4860
5241
  mentionable;
4861
5242
  /** Unicode emoji for this role (null = none). */
4862
5243
  unicodeEmoji;
5244
+ /** Role icon image hash (null = none). */
5245
+ icon;
4863
5246
  /** Hoist position (null = not hoisted). */
4864
5247
  hoistPosition;
4865
5248
  constructor(client, data, guildId) {
@@ -4867,22 +5250,28 @@ var Role = class _Role extends Base {
4867
5250
  this.client = client;
4868
5251
  this.id = data.id;
4869
5252
  this.guildId = guildId;
4870
- this.name = data.name;
4871
- this.color = data.color;
4872
- this.position = data.position;
4873
- this._permissions = data.permissions;
5253
+ this.name = data.name ?? "";
5254
+ this.color = data.color ?? 0;
5255
+ this.position = data.position ?? 0;
5256
+ this._permissions = data.permissions ?? "0";
4874
5257
  this.hoist = !!data.hoist;
4875
5258
  this.mentionable = !!data.mentionable;
4876
5259
  this.unicodeEmoji = data.unicode_emoji ?? null;
5260
+ this.icon = data.icon ?? null;
4877
5261
  this.hoistPosition = data.hoist_position ?? null;
4878
5262
  }
4879
5263
  /**
4880
5264
  * Permissions bitfield (Administrator grants all permissions).
4881
5265
  */
4882
5266
  get permissions() {
4883
- const bits = BigInt(this._permissions);
4884
- return new import_util19.PermissionsBitField(
4885
- (bits & import_util19.PermissionFlags.Administrator) !== 0n ? import_util19.ALL_PERMISSIONS_BIGINT : bits
5267
+ let bits;
5268
+ try {
5269
+ bits = BigInt(this._permissions ?? "0");
5270
+ } catch {
5271
+ bits = 0n;
5272
+ }
5273
+ return new import_util20.PermissionsBitField(
5274
+ (bits & import_util20.PermissionFlags.Administrator) !== 0n ? import_util20.ALL_PERMISSIONS_BIGINT : bits
4886
5275
  );
4887
5276
  }
4888
5277
  /**
@@ -4899,25 +5288,26 @@ var Role = class _Role extends Base {
4899
5288
  */
4900
5289
  /** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
4901
5290
  get createdTimestamp() {
4902
- return import_util19.SnowflakeUtil.timestampFromSnowflake(this.id);
5291
+ return import_util20.SnowflakeUtil.timestampFromSnowflake(this.id);
4903
5292
  }
4904
5293
  /** Date when this role was created, derived from its snowflake ID. */
4905
5294
  get createdAt() {
4906
- return import_util19.SnowflakeUtil.dateFromSnowflake(this.id);
5295
+ return import_util20.SnowflakeUtil.dateFromSnowflake(this.id);
4907
5296
  }
4908
5297
  toString() {
4909
5298
  return `<@&${this.id}>`;
4910
5299
  }
4911
5300
  /** @internal */
4912
5301
  _patch(data) {
4913
- this.name = data.name;
4914
- this.color = data.color;
4915
- this.position = data.position;
4916
- this._permissions = data.permissions;
4917
- this.hoist = !!data.hoist;
4918
- this.mentionable = !!data.mentionable;
4919
- this.unicodeEmoji = data.unicode_emoji ?? null;
4920
- this.hoistPosition = data.hoist_position ?? null;
5302
+ if (data.name !== void 0) this.name = data.name;
5303
+ if (data.color !== void 0) this.color = data.color;
5304
+ if (data.position !== void 0) this.position = data.position;
5305
+ if (data.permissions !== void 0) this._permissions = data.permissions;
5306
+ if (data.hoist !== void 0) this.hoist = !!data.hoist;
5307
+ if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
5308
+ if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
5309
+ if (data.icon !== void 0) this.icon = data.icon ?? null;
5310
+ if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
4921
5311
  }
4922
5312
  /**
4923
5313
  * Snapshot for role-update events (before in-place patch).
@@ -4935,6 +5325,7 @@ var Role = class _Role extends Base {
4935
5325
  hoist: this.hoist,
4936
5326
  mentionable: this.mentionable,
4937
5327
  unicode_emoji: this.unicodeEmoji,
5328
+ icon: this.icon,
4938
5329
  hoist_position: this.hoistPosition
4939
5330
  },
4940
5331
  this.guildId
@@ -4947,7 +5338,7 @@ var Role = class _Role extends Base {
4947
5338
  */
4948
5339
  async edit(options) {
4949
5340
  const body = toRoleEditBody(options);
4950
- const data = await this.client.rest.patch(import_types27.Routes.guildRole(this.guildId, this.id), {
5341
+ const data = await this.client.rest.patch(import_types28.Routes.guildRole(this.guildId, this.id), {
4951
5342
  body: Object.keys(body).length ? body : void 0,
4952
5343
  auth: true,
4953
5344
  ...auditReasonHeaders(options.reason)
@@ -4960,7 +5351,7 @@ var Role = class _Role extends Base {
4960
5351
  * @param reason - Audit log reason (`X-Audit-Log-Reason`)
4961
5352
  */
4962
5353
  async delete(reason) {
4963
- await this.client.rest.delete(import_types27.Routes.guildRole(this.guildId, this.id), {
5354
+ await this.client.rest.delete(import_types28.Routes.guildRole(this.guildId, this.id), {
4964
5355
  auth: true,
4965
5356
  ...auditReasonHeaders(reason)
4966
5357
  });
@@ -5061,7 +5452,7 @@ function syncChannels(guild, channels) {
5061
5452
  }
5062
5453
  }
5063
5454
  function isThreadChannelType(type) {
5064
- return type === import_types28.ChannelType.AnnouncementThread || type === import_types28.ChannelType.PublicThread || type === import_types28.ChannelType.PrivateThread;
5455
+ return type === import_types29.ChannelType.AnnouncementThread || type === import_types29.ChannelType.PublicThread || type === import_types29.ChannelType.PrivateThread;
5065
5456
  }
5066
5457
  function syncThreads(guild, threads, alsoKeep = /* @__PURE__ */ new Set()) {
5067
5458
  const keep = new Set(alsoKeep);
@@ -5112,6 +5503,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
5112
5503
  });
5113
5504
  this.client = client;
5114
5505
  }
5506
+ pendingFetches = /* @__PURE__ */ new Map();
5115
5507
  /**
5116
5508
  * Remove a channel from cache. Does not delete it on the API.
5117
5509
  * Use {@link Channel.delete} after {@link fetch} to delete the channel.
@@ -5124,9 +5516,11 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
5124
5516
  }
5125
5517
  return deleted;
5126
5518
  }
5127
- /** Retrieve from cache, otherwise {@link fetch}. */
5519
+ /** Retrieve from cache (hydrating partial stubs), otherwise {@link fetch}. */
5128
5520
  async resolve(channelId) {
5129
- return this.get(channelId) ?? this.fetch(channelId);
5521
+ const id = normalizeSnowflakeId(channelId, "channels.resolve()");
5522
+ const cached = this.get(id);
5523
+ return cached && !cached.partial ? cached : this.fetch(id);
5130
5524
  }
5131
5525
  /**
5132
5526
  * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
@@ -5139,10 +5533,23 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
5139
5533
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
5140
5534
  */
5141
5535
  async fetch(channelId, options) {
5142
- const cached = this.get(channelId);
5143
- if (cached && !options?.force) return cached;
5536
+ const id = normalizeSnowflakeId(channelId, "channels.fetch()");
5537
+ const cached = this.get(id);
5538
+ if (cached && !cached.partial && !options?.force) return cached;
5539
+ return dedupeFetch(this.pendingFetches, id, async () => this.fetchFresh(id));
5540
+ }
5541
+ async fetchFresh(channelId) {
5144
5542
  try {
5145
- const data = await this.client.rest.get(import_types29.Routes.channel(channelId));
5543
+ const data = assertApiObjectWithId(
5544
+ await this.client.rest.get(import_types30.Routes.channel(channelId)),
5545
+ "channels.fetch()"
5546
+ );
5547
+ const existing = this.get(channelId);
5548
+ if (existing && existing.type === data.type) {
5549
+ existing._patch(data);
5550
+ putChannel(this.client, existing);
5551
+ return existing;
5552
+ }
5146
5553
  const guildId = "guild_id" in data ? data.guild_id : void 0;
5147
5554
  if (guildId) {
5148
5555
  const guild = this.client.guilds.get(guildId);
@@ -5187,7 +5594,7 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
5187
5594
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
5188
5595
  });
5189
5596
  const data = await this.client.rest.post(
5190
- import_types29.Routes.channelMessages(channelId),
5597
+ import_types30.Routes.channelMessages(channelId),
5191
5598
  postPayload
5192
5599
  );
5193
5600
  this.client._addMessageToCache(channelId, data);
@@ -5197,28 +5604,28 @@ var ChannelManager = class extends import_collection8.LimitedCollection {
5197
5604
 
5198
5605
  // src/ClientCore/ClientEmoji.ts
5199
5606
  var import_collection9 = require("@fluxerjs/collection");
5200
- var import_types30 = require("@fluxerjs/types");
5201
- var import_util20 = require("@fluxerjs/util");
5607
+ var import_types31 = require("@fluxerjs/types");
5608
+ var import_util21 = require("@fluxerjs/util");
5202
5609
  async function resolveClientEmoji(client, emoji, guildId) {
5203
5610
  if (typeof emoji === "object" && emoji.id) {
5204
- return (0, import_util20.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
5611
+ return (0, import_util21.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
5205
5612
  }
5206
- const parsed = (0, import_util20.parseEmoji)(
5613
+ const parsed = (0, import_util21.parseEmoji)(
5207
5614
  typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
5208
5615
  );
5209
5616
  if (!parsed) {
5210
5617
  throw new import_util4.FluxerError("Invalid emoji", { code: import_util3.ErrorCodes.InvalidEmoji });
5211
5618
  }
5212
5619
  if (parsed.id) {
5213
- return (0, import_util20.formatEmoji)(parsed);
5620
+ return (0, import_util21.formatEmoji)(parsed);
5214
5621
  }
5215
5622
  if (!/^\w+$/.test(parsed.name)) return parsed.name;
5216
- const unicodeFromShortcode = (0, import_util20.getUnicodeFromShortcode)(parsed.name);
5623
+ const unicodeFromShortcode = (0, import_util21.getUnicodeFromShortcode)(parsed.name);
5217
5624
  if (unicodeFromShortcode) return unicodeFromShortcode;
5218
5625
  if (guildId) {
5219
- const emojis = await client.rest.get(import_types30.Routes.guildEmojis(guildId));
5626
+ const emojis = await client.rest.get(import_types31.Routes.guildEmojis(guildId));
5220
5627
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
5221
- if (found) return (0, import_util20.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
5628
+ if (found) return (0, import_util21.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
5222
5629
  throw new import_util4.FluxerError(
5223
5630
  `Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format.`,
5224
5631
  { code: import_util3.ErrorCodes.EmojiNotFound }
@@ -5233,26 +5640,26 @@ async function resolveClientEmoji(client, emoji, guildId) {
5233
5640
  return parsed.name;
5234
5641
  }
5235
5642
  async function fetchInstance(client) {
5236
- const raw = await client.rest.get(import_types30.Routes.instanceDiscovery(), {
5643
+ const raw = await client.rest.get(import_types31.Routes.instanceDiscovery(), {
5237
5644
  auth: false,
5238
5645
  unversioned: true
5239
5646
  });
5240
5647
  return parseInstanceDiscovery(raw);
5241
5648
  }
5242
5649
  function fetchGatewayInfo(client) {
5243
- return client.rest.get(import_types30.Routes.gatewayBot());
5650
+ return client.rest.get(import_types31.Routes.gatewayBot());
5244
5651
  }
5245
5652
  function fetchEmojiMetadata(client, emojiId) {
5246
- return client.rest.get(import_types30.Routes.emojiMetadata(emojiId), { auth: true });
5653
+ return client.rest.get(import_types31.Routes.emojiMetadata(emojiId), { auth: true });
5247
5654
  }
5248
5655
  function fetchStickerMetadata(client, stickerId) {
5249
- return client.rest.get(import_types30.Routes.stickerMetadata(stickerId), { auth: true });
5656
+ return client.rest.get(import_types31.Routes.stickerMetadata(stickerId), { auth: true });
5250
5657
  }
5251
5658
  function fetchApplication(client) {
5252
- return client.rest.get(import_types30.Routes.applicationsMe(), { auth: true });
5659
+ return client.rest.get(import_types31.Routes.applicationsMe(), { auth: true });
5253
5660
  }
5254
5661
  async function fetchOAuthApplications(client) {
5255
- const data = await client.rest.get(import_types30.Routes.oauth2ApplicationsMe(), { auth: true });
5662
+ const data = await client.rest.get(import_types31.Routes.oauth2ApplicationsMe(), { auth: true });
5256
5663
  if (Array.isArray(data)) return data;
5257
5664
  if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
5258
5665
  return data.applications;
@@ -5271,14 +5678,14 @@ function assertChannelIdBatch(name, channelIds) {
5271
5678
  }
5272
5679
  function preloadMessages(client, channelIds) {
5273
5680
  assertChannelIdBatch("preloadMessages", channelIds);
5274
- return client.rest.post(import_types30.Routes.preloadMessages(), {
5681
+ return client.rest.post(import_types31.Routes.preloadMessages(), {
5275
5682
  body: { channels: channelIds },
5276
5683
  auth: true
5277
5684
  });
5278
5685
  }
5279
5686
  function preloadMessagesAlt(client, channelIds) {
5280
5687
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
5281
- return client.rest.post(import_types30.Routes.preloadMessagesAlt(), {
5688
+ return client.rest.post(import_types31.Routes.preloadMessagesAlt(), {
5282
5689
  body: { channels: channelIds },
5283
5690
  auth: true
5284
5691
  });
@@ -5286,7 +5693,7 @@ function preloadMessagesAlt(client, channelIds) {
5286
5693
  async function bulkFetchMessages(client, requests, options = {}) {
5287
5694
  validateBulkMessageFetchRequests(requests);
5288
5695
  const wire = toBulkFetchWire(requests);
5289
- const data = await client.rest.post(import_types30.Routes.channelsMessagesBulk(), {
5696
+ const data = await client.rest.post(import_types31.Routes.channelsMessagesBulk(), {
5290
5697
  body: { requests: wire },
5291
5698
  auth: true
5292
5699
  });
@@ -5303,12 +5710,74 @@ async function bulkFetchMessages(client, requests, options = {}) {
5303
5710
  };
5304
5711
  }
5305
5712
  async function searchMessages(client, options = {}) {
5306
- const data = await client.rest.post(import_types30.Routes.searchMessages(), {
5713
+ const data = await client.rest.post(import_types31.Routes.searchMessages(), {
5307
5714
  body: toMessageSearchBody(options),
5308
5715
  auth: true
5309
5716
  });
5310
5717
  return toMessageSearchResponse(data);
5311
5718
  }
5719
+ function fetchEmojiSource(client, emojiId) {
5720
+ return client.rest.get(
5721
+ import_types31.Routes.emojiSource(emojiId),
5722
+ { auth: true }
5723
+ );
5724
+ }
5725
+ function fetchStickerSource(client, stickerId) {
5726
+ return client.rest.get(
5727
+ import_types31.Routes.stickerSource(stickerId),
5728
+ { auth: true }
5729
+ );
5730
+ }
5731
+ function fetchDiscoveryCategories(client) {
5732
+ return client.rest.get(
5733
+ import_types31.Routes.discoveryCategories(),
5734
+ { auth: true }
5735
+ );
5736
+ }
5737
+ function searchDiscoveryGuilds(client, options = {}) {
5738
+ const params = new URLSearchParams();
5739
+ if (options.query !== void 0) params.set("query", options.query);
5740
+ if (options.category !== void 0) params.set("category", String(options.category));
5741
+ if (options.language !== void 0) params.set("language", options.language);
5742
+ if (options.tag !== void 0) params.set("tag", options.tag);
5743
+ if (options.sort_by !== void 0) params.set("sort_by", options.sort_by);
5744
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5745
+ if (options.offset !== void 0) params.set("offset", String(options.offset));
5746
+ const qs2 = params.toString();
5747
+ return client.rest.get(
5748
+ qs2 ? `${import_types31.Routes.discoveryGuilds()}?${qs2}` : import_types31.Routes.discoveryGuilds(),
5749
+ { auth: true }
5750
+ );
5751
+ }
5752
+ function fetchExperiments(client) {
5753
+ return client.rest.get(import_types31.Routes.experiments(), {
5754
+ auth: true
5755
+ });
5756
+ }
5757
+ function refreshAttachmentUrls(client, attachmentUrls) {
5758
+ return client.rest.post(
5759
+ import_types31.Routes.attachmentsRefreshUrls(),
5760
+ { body: { attachment_urls: attachmentUrls }, auth: true }
5761
+ );
5762
+ }
5763
+ function fetchInstanceBadges(client, options = {}) {
5764
+ const params = new URLSearchParams();
5765
+ if (options.ids !== void 0) params.set("ids", options.ids);
5766
+ if (options.after !== void 0) params.set("after", options.after);
5767
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
5768
+ if (options.version !== void 0) params.set("version", options.version);
5769
+ const qs2 = params.toString();
5770
+ return client.rest.get(
5771
+ qs2 ? `${import_types31.Routes.instanceBadges()}?${qs2}` : import_types31.Routes.instanceBadges(),
5772
+ { auth: false }
5773
+ );
5774
+ }
5775
+ function fetchChannelPostData(client, channelId, threadIds) {
5776
+ return client.rest.post(
5777
+ import_types31.Routes.channelPostData(channelId),
5778
+ { body: { thread_ids: threadIds }, auth: true }
5779
+ );
5780
+ }
5312
5781
 
5313
5782
  // src/ClientCore/ClientEvents.ts
5314
5783
  function createEventMethods(client) {
@@ -5328,17 +5797,18 @@ var import_ws = require("@fluxerjs/ws");
5328
5797
 
5329
5798
  // src/Domain/Guild/Guild.ts
5330
5799
  var import_collection12 = require("@fluxerjs/collection");
5331
- var import_types40 = require("@fluxerjs/types");
5332
- var import_util22 = require("@fluxerjs/util");
5800
+ var import_types41 = require("@fluxerjs/types");
5801
+ var import_util23 = require("@fluxerjs/util");
5333
5802
 
5334
5803
  // src/ClientCore/GuildMemberManager.ts
5335
5804
  var import_collection10 = require("@fluxerjs/collection");
5336
- var import_types31 = require("@fluxerjs/types");
5805
+ var import_types32 = require("@fluxerjs/types");
5337
5806
  var GuildMemberManager = class extends import_collection10.LimitedCollection {
5338
5807
  constructor(guild) {
5339
5808
  super({ maxSize: guild.client.cache.limits.members });
5340
5809
  this.guild = guild;
5341
5810
  }
5811
+ pendingFetches = /* @__PURE__ */ new Map();
5342
5812
  /**
5343
5813
  * Get a guild member from cache or fetch from the API if not present.
5344
5814
  * Convenience helper to avoid repeating `guild.members.get(userId) ?? (await guild.fetchMember(userId))`.
@@ -5350,7 +5820,9 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
5350
5820
  * console.log(member.displayName);
5351
5821
  */
5352
5822
  async resolve(userId) {
5353
- return this.get(userId) ?? this.fetch(userId);
5823
+ const id = normalizeSnowflakeId(userId, "members.resolve()");
5824
+ const cached = this.get(id);
5825
+ return cached && !cached.user.partial ? cached : this.fetch(id);
5354
5826
  }
5355
5827
  /**
5356
5828
  * The current bot user as a GuildMember in this guild.
@@ -5378,10 +5850,11 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
5378
5850
  return this.guild.fetchMe();
5379
5851
  }
5380
5852
  async fetch(userIdOrOptions, options) {
5381
- if (typeof userIdOrOptions === "string") {
5382
- const cached = this.get(userIdOrOptions);
5383
- if (cached && !options?.force) return cached;
5384
- return this.guild.fetchMember(userIdOrOptions);
5853
+ if (typeof userIdOrOptions === "string" || typeof userIdOrOptions === "number") {
5854
+ const id = normalizeSnowflakeId(userIdOrOptions, "members.fetch()");
5855
+ const cached = this.get(id);
5856
+ if (cached && !cached.user.partial && !options?.force) return cached;
5857
+ return dedupeFetch(this.pendingFetches, id, async () => this.guild.fetchMember(id));
5385
5858
  }
5386
5859
  return this.fetchMany(userIdOrOptions);
5387
5860
  }
@@ -5390,10 +5863,14 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
5390
5863
  if (options?.limit != null) params.set("limit", String(options.limit));
5391
5864
  if (options?.after) params.set("after", options.after);
5392
5865
  const qs2 = params.toString();
5393
- const url = import_types31.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5394
- const data = await this.guild.client.rest.get(url, { auth: true });
5866
+ const url = import_types32.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
5867
+ const data = assertApiArray(
5868
+ await this.guild.client.rest.get(url, { auth: true }),
5869
+ "members.fetch()"
5870
+ );
5395
5871
  const members = [];
5396
5872
  for (const m of data) {
5873
+ if (!m?.user?.id) continue;
5397
5874
  const member = new GuildMember(
5398
5875
  this.guild.client,
5399
5876
  { ...m, guild_id: this.guild.id },
@@ -5413,7 +5890,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
5413
5890
  */
5414
5891
  async search(options = {}) {
5415
5892
  const data = await this.guild.client.rest.post(
5416
- import_types31.Routes.guildMembersSearch(this.guild.id),
5893
+ import_types32.Routes.guildMembersSearch(this.guild.id),
5417
5894
  { body: toMemberSearchBody(options), auth: true }
5418
5895
  );
5419
5896
  const offset = options.offset ?? 0;
@@ -5439,7 +5916,7 @@ var GuildMemberManager = class extends import_collection10.LimitedCollection {
5439
5916
  };
5440
5917
 
5441
5918
  // src/Domain/Guild/Admin.ts
5442
- var import_types32 = require("@fluxerjs/types");
5919
+ var import_types33 = require("@fluxerjs/types");
5443
5920
  function toAuditLogEntryPayload(entry, guildId) {
5444
5921
  return {
5445
5922
  id: entry.id,
@@ -5460,7 +5937,7 @@ function toVanityPayload(data) {
5460
5937
  return { code: data.code ?? null, uses: data.uses };
5461
5938
  }
5462
5939
  async function fetchAuditLogs(guild, options) {
5463
- const url = import_types32.Routes.guildAuditLogs(guild.id) + qs({
5940
+ const url = import_types33.Routes.guildAuditLogs(guild.id) + qs({
5464
5941
  limit: options?.limit,
5465
5942
  before: options?.before,
5466
5943
  after: options?.after,
@@ -5484,7 +5961,7 @@ async function fetchAuditLogs(guild, options) {
5484
5961
  };
5485
5962
  }
5486
5963
  async function editGuild(guild, options) {
5487
- const data = await guild.client.rest.patch(import_types32.Routes.guild(guild.id), {
5964
+ const data = await guild.client.rest.patch(import_types33.Routes.guild(guild.id), {
5488
5965
  body: toGuildEditBody(options),
5489
5966
  auth: true
5490
5967
  });
@@ -5492,13 +5969,13 @@ async function editGuild(guild, options) {
5492
5969
  return guild;
5493
5970
  }
5494
5971
  async function fetchVanityURL(guild) {
5495
- const data = await guild.client.rest.get(import_types32.Routes.guildVanityUrl(guild.id), {
5972
+ const data = await guild.client.rest.get(import_types33.Routes.guildVanityUrl(guild.id), {
5496
5973
  auth: true
5497
5974
  });
5498
5975
  return toVanityPayload(data);
5499
5976
  }
5500
5977
  async function editVanityURL(guild, code) {
5501
- const data = await guild.client.rest.patch(import_types32.Routes.guildVanityUrl(guild.id), {
5978
+ const data = await guild.client.rest.patch(import_types33.Routes.guildVanityUrl(guild.id), {
5502
5979
  body: { code },
5503
5980
  auth: true
5504
5981
  });
@@ -5506,14 +5983,14 @@ async function editVanityURL(guild, code) {
5506
5983
  return toVanityPayload(data);
5507
5984
  }
5508
5985
  async function fetchDiscoveryStatus(guild) {
5509
- const data = await guild.client.rest.get(import_types32.Routes.guildDiscovery(guild.id), {
5986
+ const data = await guild.client.rest.get(import_types33.Routes.guildDiscovery(guild.id), {
5510
5987
  auth: true
5511
5988
  });
5512
5989
  return toDiscoveryStatusPayload(data);
5513
5990
  }
5514
5991
  async function applyForDiscovery(guild, options) {
5515
5992
  const data = await guild.client.rest.post(
5516
- import_types32.Routes.guildDiscovery(guild.id),
5993
+ import_types33.Routes.guildDiscovery(guild.id),
5517
5994
  {
5518
5995
  body: toDiscoveryBody(options),
5519
5996
  auth: true
@@ -5523,7 +6000,7 @@ async function applyForDiscovery(guild, options) {
5523
6000
  }
5524
6001
  async function editDiscoveryApplication(guild, options) {
5525
6002
  const data = await guild.client.rest.patch(
5526
- import_types32.Routes.guildDiscovery(guild.id),
6003
+ import_types33.Routes.guildDiscovery(guild.id),
5527
6004
  {
5528
6005
  body: toDiscoveryBody(options),
5529
6006
  auth: true
@@ -5532,34 +6009,39 @@ async function editDiscoveryApplication(guild, options) {
5532
6009
  return toDiscoveryApplicationPayload(data);
5533
6010
  }
5534
6011
  async function withdrawDiscoveryApplication(guild) {
5535
- await guild.client.rest.delete(import_types32.Routes.guildDiscovery(guild.id), { auth: true });
6012
+ await guild.client.rest.delete(import_types33.Routes.guildDiscovery(guild.id), { auth: true });
5536
6013
  }
5537
6014
  async function deleteGuild(guild, options) {
5538
6015
  const body = options ? toSudoBody(options) : {};
5539
- await guild.client.rest.post(import_types32.Routes.guildDelete(guild.id), {
6016
+ await guild.client.rest.post(import_types33.Routes.guildDelete(guild.id), {
5540
6017
  body,
5541
6018
  auth: true
5542
6019
  });
5543
6020
  guild.client.guilds.delete(guild.id);
5544
6021
  }
5545
6022
  async function transferOwnership(guild, newOwnerId, password) {
5546
- await guild.client.rest.post(import_types32.Routes.guildTransferOwnership(guild.id), {
6023
+ await guild.client.rest.post(import_types33.Routes.guildTransferOwnership(guild.id), {
5547
6024
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
5548
6025
  auth: true
5549
6026
  });
5550
6027
  }
5551
6028
 
5552
6029
  // src/Domain/Guild/Channels.ts
5553
- var import_types33 = require("@fluxerjs/types");
6030
+ var import_types34 = require("@fluxerjs/types");
5554
6031
  async function createChannel(guild, options) {
5555
- const created = await guild.client.rest.post(import_types33.Routes.guildChannels(guild.id), {
6032
+ const created = await guild.client.rest.post(import_types34.Routes.guildChannels(guild.id), {
5556
6033
  body: toChannelCreateBody(options),
5557
6034
  auth: true
5558
6035
  });
5559
6036
  return cacheChannel(guild, created);
5560
6037
  }
5561
6038
  async function fetchChannels(guild) {
5562
- const data = await guild.client.rest.get(import_types33.Routes.guildChannels(guild.id));
6039
+ const raw = await guild.client.rest.get(import_types34.Routes.guildChannels(guild.id));
6040
+ if (!Array.isArray(raw))
6041
+ throw new TypeError(
6042
+ "guild.fetchChannels() received an invalid API payload (expected an array)"
6043
+ );
6044
+ const data = raw;
5563
6045
  const channels = [];
5564
6046
  for (const ch of data) {
5565
6047
  const channel = cacheChannel(guild, ch);
@@ -5568,17 +6050,17 @@ async function fetchChannels(guild) {
5568
6050
  return channels;
5569
6051
  }
5570
6052
  async function setChannelPositions(guild, updates) {
5571
- await guild.client.rest.patch(import_types33.Routes.guildChannels(guild.id), {
6053
+ await guild.client.rest.patch(import_types34.Routes.guildChannels(guild.id), {
5572
6054
  body: toChannelPositionBody(updates),
5573
6055
  auth: true
5574
6056
  });
5575
6057
  }
5576
6058
  async function fetchWebhooks(guild) {
5577
- const data = await guild.client.rest.get(import_types33.Routes.guildWebhooks(guild.id));
6059
+ const data = await guild.client.rest.get(import_types34.Routes.guildWebhooks(guild.id));
5578
6060
  return data.map((w) => new Webhook(guild.client, w));
5579
6061
  }
5580
6062
  async function fetchInvites(guild) {
5581
- const data = await guild.client.rest.get(import_types33.Routes.guildInvites(guild.id));
6063
+ const data = await guild.client.rest.get(import_types34.Routes.guildInvites(guild.id));
5582
6064
  return data.map((invite) => new Invite(guild.client, invite));
5583
6065
  }
5584
6066
  async function fetchInvite(guild, codeOrUrl) {
@@ -5598,14 +6080,14 @@ function resolveGuildOnlineCount(data) {
5598
6080
  }
5599
6081
 
5600
6082
  // src/Domain/Guild/Emojis.ts
5601
- var import_types34 = require("@fluxerjs/types");
6083
+ var import_types35 = require("@fluxerjs/types");
5602
6084
  async function fetchEmojis(guild) {
5603
- const data = await guild.client.rest.get(import_types34.Routes.guildEmojis(guild.id));
6085
+ const data = await guild.client.rest.get(import_types35.Routes.guildEmojis(guild.id));
5604
6086
  return data.map((e) => cacheEmoji(guild, e));
5605
6087
  }
5606
6088
  async function fetchEmoji(guild, emojiId) {
5607
6089
  try {
5608
- const data = await guild.client.rest.get(import_types34.Routes.guildEmoji(guild.id, emojiId));
6090
+ const data = await guild.client.rest.get(import_types35.Routes.guildEmoji(guild.id, emojiId));
5609
6091
  return cacheEmoji(guild, data);
5610
6092
  } catch (err) {
5611
6093
  rethrowMapped(err, {
@@ -5616,7 +6098,7 @@ async function fetchEmoji(guild, emojiId) {
5616
6098
  }
5617
6099
  async function createEmoji(guild, options) {
5618
6100
  const { reason, ...body } = options;
5619
- const data = await guild.client.rest.post(import_types34.Routes.guildEmojis(guild.id), {
6101
+ const data = await guild.client.rest.post(import_types35.Routes.guildEmojis(guild.id), {
5620
6102
  body,
5621
6103
  auth: true,
5622
6104
  ...auditReasonHeaders(reason)
@@ -5624,7 +6106,7 @@ async function createEmoji(guild, options) {
5624
6106
  return cacheEmoji(guild, data);
5625
6107
  }
5626
6108
  async function cloneEmoji(guild, sourceEmojiId) {
5627
- const data = await guild.client.rest.post(import_types34.Routes.guildEmojisClone(guild.id), {
6109
+ const data = await guild.client.rest.post(import_types35.Routes.guildEmojisClone(guild.id), {
5628
6110
  body: { source_emoji_id: sourceEmojiId },
5629
6111
  auth: true
5630
6112
  });
@@ -5632,7 +6114,7 @@ async function cloneEmoji(guild, sourceEmojiId) {
5632
6114
  }
5633
6115
  async function createEmojisBulk(guild, emojis) {
5634
6116
  const data = await guild.client.rest.post(
5635
- import_types34.Routes.guildEmojisBulk(guild.id),
6117
+ import_types35.Routes.guildEmojisBulk(guild.id),
5636
6118
  { body: { emojis }, auth: true }
5637
6119
  );
5638
6120
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
@@ -5652,18 +6134,22 @@ var GuildRoleManager = class extends import_collection11.LimitedCollection {
5652
6134
  };
5653
6135
 
5654
6136
  // src/Domain/Guild/MemberHttp.ts
5655
- var import_types35 = require("@fluxerjs/types");
6137
+ var import_types36 = require("@fluxerjs/types");
5656
6138
  async function fetchMember(guild, userId) {
6139
+ const id = normalizeSnowflakeId(userId, "members.fetch()");
5657
6140
  try {
5658
6141
  const data = await guild.client.rest.get(
5659
- import_types35.Routes.guildMember(guild.id, userId)
6142
+ import_types36.Routes.guildMember(guild.id, id)
5660
6143
  );
6144
+ if (!data?.user?.id) {
6145
+ throw new TypeError("members.fetch() received an invalid API payload (missing user.id)");
6146
+ }
5661
6147
  return cacheMember(guild, data);
5662
6148
  } catch (err) {
5663
6149
  rethrowMapped(err, {
5664
6150
  notFound: {
5665
6151
  code: import_util3.ErrorCodes.MemberNotFound,
5666
- message: `Member ${userId} not found in guild`
6152
+ message: `Member ${id} not found in guild`
5667
6153
  },
5668
6154
  fallback: "Failed to fetch guild member"
5669
6155
  });
@@ -5671,17 +6157,20 @@ async function fetchMember(guild, userId) {
5671
6157
  }
5672
6158
  async function fetchMe(guild) {
5673
6159
  const data = await guild.client.rest.get(
5674
- import_types35.Routes.guildMemberMe(guild.id),
6160
+ import_types36.Routes.guildMemberMe(guild.id),
5675
6161
  { auth: true }
5676
6162
  );
6163
+ if (!data?.user?.id) {
6164
+ throw new TypeError("members.fetchMe() received an invalid API payload (missing user.id)");
6165
+ }
5677
6166
  return cacheMember(guild, data);
5678
6167
  }
5679
6168
 
5680
6169
  // src/Domain/Guild/Moderation.ts
5681
- var import_types37 = require("@fluxerjs/types");
6170
+ var import_types38 = require("@fluxerjs/types");
5682
6171
 
5683
6172
  // src/Domain/Guild/GuildBan.ts
5684
- var import_types36 = require("@fluxerjs/types");
6173
+ var import_types37 = require("@fluxerjs/types");
5685
6174
  function parseOptionalDate2(value) {
5686
6175
  if (value == null || value === "") return null;
5687
6176
  const date = new Date(value);
@@ -5708,7 +6197,7 @@ var GuildBan = class extends Base {
5708
6197
  * Requires Ban Members permission.
5709
6198
  */
5710
6199
  async unban(reason) {
5711
- await this.client.rest.delete(import_types36.Routes.guildBan(this.guildId, this.user.id), {
6200
+ await this.client.rest.delete(import_types37.Routes.guildBan(this.guildId, this.user.id), {
5712
6201
  auth: true,
5713
6202
  ...auditReasonHeaders(reason)
5714
6203
  });
@@ -5718,35 +6207,39 @@ var GuildBan = class extends Base {
5718
6207
  // src/Domain/Guild/Moderation.ts
5719
6208
  async function ban(guild, userId, options) {
5720
6209
  const body = options ? toGuildBanBody(options) : {};
5721
- await guild.client.rest.put(import_types37.Routes.guildBan(guild.id, userId), {
6210
+ await guild.client.rest.put(import_types38.Routes.guildBan(guild.id, userId), {
5722
6211
  body: Object.keys(body).length ? body : void 0,
5723
6212
  auth: true,
5724
6213
  ...auditReasonHeaders(options?.reason)
5725
6214
  });
5726
6215
  }
6216
+ async function fetchBan(guild, userId) {
6217
+ const data = await guild.client.rest.get(import_types38.Routes.guildBan(guild.id, userId));
6218
+ return new GuildBan(guild.client, { ...data, guild_id: guild.id }, guild.id);
6219
+ }
5727
6220
  async function fetchBans(guild) {
5728
- const data = await guild.client.rest.get(import_types37.Routes.guildBans(guild.id));
6221
+ const data = await guild.client.rest.get(import_types38.Routes.guildBans(guild.id));
5729
6222
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
5730
6223
  }
5731
6224
  async function unban(guild, userId, reason) {
5732
- await guild.client.rest.delete(import_types37.Routes.guildBan(guild.id, userId), {
6225
+ await guild.client.rest.delete(import_types38.Routes.guildBan(guild.id, userId), {
5733
6226
  auth: true,
5734
6227
  ...auditReasonHeaders(reason)
5735
6228
  });
5736
6229
  }
5737
6230
  async function kick(guild, userId, reason) {
5738
- await guild.client.rest.delete(import_types37.Routes.guildMember(guild.id, userId), {
6231
+ await guild.client.rest.delete(import_types38.Routes.guildMember(guild.id, userId), {
5739
6232
  auth: true,
5740
6233
  ...auditReasonHeaders(reason)
5741
6234
  });
5742
6235
  }
5743
6236
 
5744
6237
  // src/Domain/Guild/Roles.ts
5745
- var import_types38 = require("@fluxerjs/types");
5746
- var import_util21 = require("@fluxerjs/util");
6238
+ var import_types39 = require("@fluxerjs/types");
6239
+ var import_util22 = require("@fluxerjs/util");
5747
6240
  async function createRole(guild, options = {}) {
5748
6241
  const body = toRoleCreateBody(options);
5749
- const data = await guild.client.rest.post(import_types38.Routes.guildRoles(guild.id), {
6242
+ const data = await guild.client.rest.post(import_types39.Routes.guildRoles(guild.id), {
5750
6243
  body: Object.keys(body).length ? body : void 0,
5751
6244
  auth: true,
5752
6245
  ...auditReasonHeaders(options.reason)
@@ -5754,12 +6247,14 @@ async function createRole(guild, options = {}) {
5754
6247
  return cacheRole(guild, data);
5755
6248
  }
5756
6249
  async function fetchRoles(guild) {
5757
- const data = await guild.client.rest.get(import_types38.Routes.guildRoles(guild.id));
6250
+ const data = await guild.client.rest.get(import_types39.Routes.guildRoles(guild.id));
6251
+ if (!Array.isArray(data))
6252
+ throw new TypeError("guild.fetchRoles() received an invalid API payload (expected an array)");
5758
6253
  return data.map((r) => cacheRole(guild, r));
5759
6254
  }
5760
6255
  async function fetchRole(guild, roleId2) {
5761
6256
  try {
5762
- const data = await guild.client.rest.get(import_types38.Routes.guildRole(guild.id, roleId2));
6257
+ const data = await guild.client.rest.get(import_types39.Routes.guildRole(guild.id, roleId2));
5763
6258
  return cacheRole(guild, data);
5764
6259
  } catch (err) {
5765
6260
  rethrowMapped(err, {
@@ -5769,14 +6264,14 @@ async function fetchRole(guild, roleId2) {
5769
6264
  }
5770
6265
  }
5771
6266
  async function resolveRoleId(guild, arg) {
5772
- const parsed = (0, import_util21.parseRoleMention)(arg);
6267
+ const parsed = (0, import_util22.parseRoleMention)(arg);
5773
6268
  if (parsed) return parsed;
5774
6269
  const trimmed = arg.trim();
5775
6270
  if (/^\d{17,19}$/.test(trimmed)) return trimmed;
5776
6271
  const needle = trimmed.toLowerCase();
5777
6272
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
5778
6273
  if (cached) return cached.id;
5779
- const roles = await guild.client.rest.get(import_types38.Routes.guildRoles(guild.id));
6274
+ const roles = await guild.client.rest.get(import_types39.Routes.guildRoles(guild.id));
5780
6275
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
5781
6276
  if (!role) return null;
5782
6277
  cacheRole(guild, role);
@@ -5785,7 +6280,7 @@ async function resolveRoleId(guild, arg) {
5785
6280
  async function setRolePositions(guild, updates) {
5786
6281
  return replaceRoles(
5787
6282
  guild,
5788
- await guild.client.rest.patch(import_types38.Routes.guildRoles(guild.id), {
6283
+ await guild.client.rest.patch(import_types39.Routes.guildRoles(guild.id), {
5789
6284
  body: updates,
5790
6285
  auth: true
5791
6286
  })
@@ -5794,7 +6289,7 @@ async function setRolePositions(guild, updates) {
5794
6289
  async function setRoleHoistPositions(guild, updates) {
5795
6290
  return replaceRoles(
5796
6291
  guild,
5797
- await guild.client.rest.patch(import_types38.Routes.guildRolesHoistPositions(guild.id), {
6292
+ await guild.client.rest.patch(import_types39.Routes.guildRolesHoistPositions(guild.id), {
5798
6293
  body: updates.map((u) => ({
5799
6294
  id: u.id,
5800
6295
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -5806,17 +6301,17 @@ async function setRoleHoistPositions(guild, updates) {
5806
6301
  async function resetRoleHoistPositions(guild) {
5807
6302
  return replaceRoles(
5808
6303
  guild,
5809
- await guild.client.rest.delete(import_types38.Routes.guildRolesHoistPositions(guild.id), {
6304
+ await guild.client.rest.delete(import_types39.Routes.guildRolesHoistPositions(guild.id), {
5810
6305
  auth: true
5811
6306
  })
5812
6307
  );
5813
6308
  }
5814
6309
 
5815
6310
  // src/Domain/Guild/Stickers.ts
5816
- var import_types39 = require("@fluxerjs/types");
6311
+ var import_types40 = require("@fluxerjs/types");
5817
6312
  async function createSticker(guild, options) {
5818
6313
  const { reason, ...body } = options;
5819
- const data = await guild.client.rest.post(import_types39.Routes.guildStickers(guild.id), {
6314
+ const data = await guild.client.rest.post(import_types40.Routes.guildStickers(guild.id), {
5820
6315
  body,
5821
6316
  auth: true,
5822
6317
  ...auditReasonHeaders(reason)
@@ -5824,7 +6319,7 @@ async function createSticker(guild, options) {
5824
6319
  return cacheSticker(guild, data);
5825
6320
  }
5826
6321
  async function cloneSticker(guild, sourceStickerId) {
5827
- const data = await guild.client.rest.post(import_types39.Routes.guildStickersClone(guild.id), {
6322
+ const data = await guild.client.rest.post(import_types40.Routes.guildStickersClone(guild.id), {
5828
6323
  body: { source_sticker_id: sourceStickerId },
5829
6324
  auth: true
5830
6325
  });
@@ -5832,17 +6327,17 @@ async function cloneSticker(guild, sourceStickerId) {
5832
6327
  }
5833
6328
  async function createStickersBulk(guild, stickers) {
5834
6329
  const data = await guild.client.rest.post(
5835
- import_types39.Routes.guildStickersBulk(guild.id),
6330
+ import_types40.Routes.guildStickersBulk(guild.id),
5836
6331
  { body: { stickers }, auth: true }
5837
6332
  );
5838
6333
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
5839
6334
  }
5840
6335
  async function fetchStickers(guild) {
5841
- const data = await guild.client.rest.get(import_types39.Routes.guildStickers(guild.id));
6336
+ const data = await guild.client.rest.get(import_types40.Routes.guildStickers(guild.id));
5842
6337
  return data.map((s) => cacheSticker(guild, s));
5843
6338
  }
5844
6339
  async function fetchSticker(guild, stickerId) {
5845
- const data = await guild.client.rest.get(import_types39.Routes.guildSticker(guild.id, stickerId));
6340
+ const data = await guild.client.rest.get(import_types40.Routes.guildSticker(guild.id, stickerId));
5846
6341
  return cacheSticker(guild, data);
5847
6342
  }
5848
6343
 
@@ -5854,6 +6349,11 @@ var Guild = class extends Base {
5854
6349
  id;
5855
6350
  /** Whether the guild is currently available through the gateway. */
5856
6351
  available = true;
6352
+ /**
6353
+ * True when only guild metadata is known (e.g. created from `GET /guilds/{id}`)
6354
+ * and nested channels/roles have not been synced yet. `guilds.resolve()` hydrates partial guilds.
6355
+ */
6356
+ partial = true;
5857
6357
  /** Guild name. */
5858
6358
  name;
5859
6359
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -5926,6 +6426,10 @@ var Guild = class extends Base {
5926
6426
  emojis;
5927
6427
  /** Cached stickers in this guild. */
5928
6428
  stickers;
6429
+ /** Live stages in this guild's stage channels, keyed by stage instance ID. */
6430
+ stageInstances;
6431
+ /** Most participants a stage can have while speakers use video, or null if unknown. */
6432
+ maxStageVideoChannelUsers;
5929
6433
  /**
5930
6434
  * Construct a guild from API data.
5931
6435
  * @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE
@@ -5942,6 +6446,7 @@ var Guild = class extends Base {
5942
6446
  this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
5943
6447
  this.emojis = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.emojis });
5944
6448
  this.stickers = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.stickers });
6449
+ this.stageInstances = new import_collection12.Collection();
5945
6450
  this.name = data.name ?? "";
5946
6451
  this.icon = data.icon ?? null;
5947
6452
  this.banner = data.banner ?? null;
@@ -5959,7 +6464,7 @@ var Guild = class extends Base {
5959
6464
  this.systemChannelFlags = data.system_channel_flags ?? 0;
5960
6465
  this.splashCardAlignment = data.splash_card_alignment ?? 0;
5961
6466
  this.embedSplash = data.embed_splash ?? null;
5962
- this.nsfwLevel = data.nsfw_level ?? import_types40.GuildNSFWLevel.Safe;
6467
+ this.nsfwLevel = data.nsfw_level ?? import_types41.GuildNSFWLevel.Safe;
5963
6468
  this.nsfw = data.nsfw ?? false;
5964
6469
  this.contentWarningLevel = data.content_warning_level ?? 0;
5965
6470
  this.contentWarningText = data.content_warning_text ?? null;
@@ -5971,6 +6476,7 @@ var Guild = class extends Base {
5971
6476
  this.bannerHeight = data.banner_height ?? null;
5972
6477
  this.splashWidth = data.splash_width ?? null;
5973
6478
  this.splashHeight = data.splash_height ?? null;
6479
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
5974
6480
  this.memberCount = resolveGuildMemberCount(data) ?? null;
5975
6481
  this.onlineCount = resolveGuildOnlineCount(data) ?? null;
5976
6482
  for (const r of data.roles ?? []) {
@@ -6007,7 +6513,7 @@ var Guild = class extends Base {
6007
6513
  this.splashCardAlignment = data.splash_card_alignment ?? 0;
6008
6514
  }
6009
6515
  if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
6010
- if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types40.GuildNSFWLevel.Safe;
6516
+ if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types41.GuildNSFWLevel.Safe;
6011
6517
  if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
6012
6518
  if (data.content_warning_level !== void 0) {
6013
6519
  this.contentWarningLevel = data.content_warning_level ?? 0;
@@ -6027,6 +6533,9 @@ var Guild = class extends Base {
6027
6533
  if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
6028
6534
  if (data.splash_width !== void 0) this.splashWidth = data.splash_width ?? null;
6029
6535
  if (data.splash_height !== void 0) this.splashHeight = data.splash_height ?? null;
6536
+ if (data.max_stage_video_channel_users !== void 0) {
6537
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users ?? null;
6538
+ }
6030
6539
  const memberCount = resolveGuildMemberCount(data);
6031
6540
  if (memberCount !== void 0) this.memberCount = memberCount;
6032
6541
  const onlineCount = resolveGuildOnlineCount(data);
@@ -6042,11 +6551,11 @@ var Guild = class extends Base {
6042
6551
  }
6043
6552
  /** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
6044
6553
  get createdTimestamp() {
6045
- return import_util22.SnowflakeUtil.timestampFromSnowflake(this.id);
6554
+ return import_util23.SnowflakeUtil.timestampFromSnowflake(this.id);
6046
6555
  }
6047
6556
  /** Date when this guild was created, derived from its snowflake ID. */
6048
6557
  get createdAt() {
6049
- return import_util22.SnowflakeUtil.dateFromSnowflake(this.id);
6558
+ return import_util23.SnowflakeUtil.dateFromSnowflake(this.id);
6050
6559
  }
6051
6560
  /** The guild's name. */
6052
6561
  toString() {
@@ -6148,6 +6657,10 @@ var Guild = class extends Base {
6148
6657
  ban(userId, options) {
6149
6658
  return ban(this, userId, options);
6150
6659
  }
6660
+ /** Fetch a single ban by user ID. Requires Ban Members. */
6661
+ fetchBan(userId) {
6662
+ return fetchBan(this, userId);
6663
+ }
6151
6664
  /** Fetch all bans in this guild. Requires Ban Members. */
6152
6665
  fetchBans() {
6153
6666
  return fetchBans(this);
@@ -6243,7 +6756,7 @@ var Guild = class extends Base {
6243
6756
  };
6244
6757
 
6245
6758
  // src/Domain/Guild/Payload.ts
6246
- var import_util23 = require("@fluxerjs/util");
6759
+ var import_util24 = require("@fluxerjs/util");
6247
6760
  var TOP_LEVEL_COUNT_KEYS = [
6248
6761
  "member_count",
6249
6762
  "online_count",
@@ -6283,10 +6796,10 @@ function mergeTopLevelSnapshotFields(properties, raw) {
6283
6796
  return out;
6284
6797
  }
6285
6798
  function normalizeGuildSnapshotPayload(raw) {
6286
- if (!(0, import_util23.isRecord)(raw)) return null;
6799
+ if (!(0, import_util24.isRecord)(raw)) return null;
6287
6800
  const flatPayload = isHydratableGuildPayload(raw) && (raw.roles === void 0 || Array.isArray(raw.roles)) ? raw : null;
6288
6801
  let nestedPayload = null;
6289
- if (Object.hasOwn(raw, "properties") && (0, import_util23.isRecord)(raw.properties)) {
6802
+ if (Object.hasOwn(raw, "properties") && (0, import_util24.isRecord)(raw.properties)) {
6290
6803
  const properties = raw.properties;
6291
6804
  const rolesValid = raw.roles === void 0 || Array.isArray(raw.roles);
6292
6805
  if (rolesValid && isHydratableGuildPayload(properties) && raw.id === properties.id) {
@@ -6298,7 +6811,7 @@ function normalizeGuildSnapshotPayload(raw) {
6298
6811
  return flatPayload ?? nestedPayload;
6299
6812
  }
6300
6813
  function normalizeGuildUpdatePayload(raw) {
6301
- if (!(0, import_util23.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
6814
+ if (!(0, import_util24.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
6302
6815
  return raw;
6303
6816
  }
6304
6817
 
@@ -6328,6 +6841,9 @@ function upsertGuildFromSnapshot(client, guildData, resources = {}) {
6328
6841
  if (resources.members !== void 0) mergeMembers(guild, resources.members);
6329
6842
  if (resources.emojis !== void 0) syncEmojis(guild, resources.emojis);
6330
6843
  if (resources.stickers !== void 0) syncStickers(guild, resources.stickers);
6844
+ if (resources.stageInstances !== void 0) syncStageInstances(guild, resources.stageInstances);
6845
+ if (resources.stageCounts !== void 0) applyStageCounts(guild, resources.stageCounts);
6846
+ if (resources.channels !== void 0) guild.partial = false;
6331
6847
  return { guild, created, recovered };
6332
6848
  }
6333
6849
  function applyGuildSnapshotFromGateway(client, raw) {
@@ -6341,7 +6857,9 @@ function applyGuildSnapshotFromGateway(client, raw) {
6341
6857
  emojis: g.emojis,
6342
6858
  stickers: g.stickers,
6343
6859
  // A channel list without `threads` means this session has no viewable threads.
6344
- threads: g.channels !== void 0 ? g.threads ?? [] : g.threads
6860
+ threads: g.channels !== void 0 ? g.threads ?? [] : g.threads,
6861
+ stageInstances: g.stage_instances,
6862
+ stageCounts: g.stage_counts
6345
6863
  });
6346
6864
  if (g.voice_states?.length) {
6347
6865
  client.emit(Events.VoiceStatesSync, {
@@ -6353,23 +6871,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
6353
6871
  }
6354
6872
 
6355
6873
  // src/ClientCore/ClientUser.ts
6356
- var import_types41 = require("@fluxerjs/types");
6874
+ var import_types42 = require("@fluxerjs/types");
6357
6875
  var ClientUser = class extends User {
6358
6876
  /** Broadcast presence (gateway opcode 3) on all shards. */
6359
6877
  setPresence(presence) {
6360
6878
  this.client.options.presence = presence;
6361
6879
  const wire = toPresenceWire(presence);
6362
- this.client._sendToAllShards({ op: import_types41.GatewayOpcodes.PresenceUpdate, d: wire });
6880
+ this.client._sendToAllShards({ op: import_types42.GatewayOpcodes.PresenceUpdate, d: wire });
6363
6881
  }
6364
6882
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
6365
6883
  async fetch() {
6366
- const data = await this.client.rest.get(import_types41.Routes.currentUser(), { auth: true });
6884
+ const data = await this.client.rest.get(import_types42.Routes.currentUser(), { auth: true });
6367
6885
  this._patch(data);
6368
6886
  return this;
6369
6887
  }
6370
6888
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
6371
6889
  async fetchGuilds(options) {
6372
- const path = import_types41.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6890
+ const path = import_types42.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
6373
6891
  const data = await this.client.rest.get(path, { auth: true });
6374
6892
  return data.map((g) => ({
6375
6893
  id: g.id,
@@ -6393,7 +6911,7 @@ var ClientUser = class extends User {
6393
6911
  */
6394
6912
  async leaveGuild(guildId, options) {
6395
6913
  const body = options ? toSudoBody(options) : void 0;
6396
- await this.client.rest.delete(import_types41.Routes.leaveGuild(guildId), {
6914
+ await this.client.rest.delete(import_types42.Routes.leaveGuild(guildId), {
6397
6915
  body: body && Object.keys(body).length ? body : void 0,
6398
6916
  auth: true
6399
6917
  });
@@ -6401,7 +6919,7 @@ var ClientUser = class extends User {
6401
6919
  /** Delete every message authored by the caller across a guild (sudo). */
6402
6920
  async bulkDeleteMyMessagesInGuild(guildId, options) {
6403
6921
  const body = options ? toSudoBody(options) : void 0;
6404
- await this.client.rest.post(import_types41.Routes.guildBulkDeleteMine(guildId), {
6922
+ await this.client.rest.post(import_types42.Routes.guildBulkDeleteMine(guildId), {
6405
6923
  body: body && Object.keys(body).length ? body : void 0,
6406
6924
  auth: true
6407
6925
  });
@@ -6409,17 +6927,9 @@ var ClientUser = class extends User {
6409
6927
  };
6410
6928
 
6411
6929
  // src/ClientCore/EventHandlers/Helpers.ts
6412
- var import_util24 = require("@fluxerjs/util");
6930
+ var import_util25 = require("@fluxerjs/util");
6413
6931
  function unknownUser(id) {
6414
- return {
6415
- id,
6416
- username: "Unknown",
6417
- discriminator: "0",
6418
- global_name: null,
6419
- avatar: null,
6420
- avatar_color: null,
6421
- flags: 0
6422
- };
6932
+ return { id };
6423
6933
  }
6424
6934
  function indexMember(_client, guild, data) {
6425
6935
  if (!data.user?.id) return null;
@@ -6724,50 +7234,50 @@ var guildHandlers = {
6724
7234
  };
6725
7235
 
6726
7236
  // src/ClientCore/EventHandlers/Invites.ts
6727
- var import_types42 = require("@fluxerjs/types");
7237
+ var import_types43 = require("@fluxerjs/types");
6728
7238
  function normalizeInviteCreate(client, payload) {
6729
- const raw = (0, import_util24.asRecord)(payload);
6730
- const code = (0, import_util24.str)(raw?.code);
7239
+ const raw = (0, import_util25.asRecord)(payload);
7240
+ const code = (0, import_util25.str)(raw?.code);
6731
7241
  if (!raw || !code) return null;
6732
- const typeNum = (0, import_util24.num)(raw.type);
6733
- const type = typeNum === import_types42.InviteType.GroupDM ? import_types42.InviteType.GroupDM : import_types42.InviteType.Guild;
7242
+ const typeNum = (0, import_util25.num)(raw.type);
7243
+ const type = typeNum === import_types43.InviteType.GroupDM ? import_types43.InviteType.GroupDM : import_types43.InviteType.Guild;
6734
7244
  const shared = {
6735
7245
  code,
6736
7246
  inviter: raw.inviter ?? null,
6737
- member_count: (0, import_util24.num)(raw.member_count),
7247
+ member_count: (0, import_util25.num)(raw.member_count),
6738
7248
  expires_at: raw.expires_at ?? void 0,
6739
7249
  temporary: typeof raw.temporary === "boolean" ? raw.temporary : void 0,
6740
- created_at: (0, import_util24.str)(raw.created_at),
6741
- uses: (0, import_util24.num)(raw.uses),
6742
- max_uses: (0, import_util24.num)(raw.max_uses),
6743
- max_age: (0, import_util24.num)(raw.max_age)
7250
+ created_at: (0, import_util25.str)(raw.created_at),
7251
+ uses: (0, import_util25.num)(raw.uses),
7252
+ max_uses: (0, import_util25.num)(raw.max_uses),
7253
+ max_age: (0, import_util25.num)(raw.max_age)
6744
7254
  };
6745
- const guildObj = (0, import_util24.asRecord)(raw.guild);
6746
- const channelObj = (0, import_util24.asRecord)(raw.channel);
6747
- const guildId = (0, import_util24.str)(guildObj?.id) ?? (0, import_util24.str)(raw.guild_id) ?? "0";
6748
- const channelId = (0, import_util24.str)(channelObj?.id) ?? (0, import_util24.str)(raw.channel_id) ?? "0";
7255
+ const guildObj = (0, import_util25.asRecord)(raw.guild);
7256
+ const channelObj = (0, import_util25.asRecord)(raw.channel);
7257
+ const guildId = (0, import_util25.str)(guildObj?.id) ?? (0, import_util25.str)(raw.guild_id) ?? "0";
7258
+ const channelId = (0, import_util25.str)(channelObj?.id) ?? (0, import_util25.str)(raw.channel_id) ?? "0";
6749
7259
  const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
6750
7260
  const cachedChannel2 = channelId !== "0" ? client.channels.get(channelId) : null;
6751
7261
  const channel = {
6752
7262
  id: channelId,
6753
- type: (0, import_util24.num)(channelObj?.type) ?? cachedChannel2?.type ?? import_types42.ChannelType.GuildText,
6754
- name: (0, import_util24.str)(channelObj?.name) ?? cachedChannel2?.name ?? null,
7263
+ type: (0, import_util25.num)(channelObj?.type) ?? cachedChannel2?.type ?? import_types43.ChannelType.GuildText,
7264
+ name: (0, import_util25.str)(channelObj?.name) ?? cachedChannel2?.name ?? null,
6755
7265
  icon: channelObj?.icon ?? null
6756
7266
  };
6757
- if (type === import_types42.InviteType.GroupDM) return { ...shared, type, channel };
7267
+ if (type === import_types43.InviteType.GroupDM) return { ...shared, type, channel };
6758
7268
  return {
6759
7269
  ...shared,
6760
- type: import_types42.InviteType.Guild,
7270
+ type: import_types43.InviteType.Guild,
6761
7271
  guild: {
6762
7272
  id: guildId,
6763
- name: (0, import_util24.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
7273
+ name: (0, import_util25.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
6764
7274
  icon: guildObj?.icon ?? null,
6765
7275
  banner: guildObj?.banner ?? null,
6766
7276
  splash: guildObj?.splash ?? null,
6767
7277
  features: Array.isArray(guildObj?.features) ? guildObj.features : void 0
6768
7278
  },
6769
7279
  channel,
6770
- presence_count: (0, import_util24.num)(raw.presence_count)
7280
+ presence_count: (0, import_util25.num)(raw.presence_count)
6771
7281
  };
6772
7282
  }
6773
7283
  var inviteHandlers = {
@@ -6878,7 +7388,7 @@ var memberHandlers = {
6878
7388
  };
6879
7389
 
6880
7390
  // src/ClientCore/EventHandlers/Messages.ts
6881
- var import_util25 = require("@fluxerjs/util");
7391
+ var import_util26 = require("@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) : import_util25.SnowflakeUtil.isValid(args.id) ? import_util25.SnowflakeUtil.dateFromSnowflake(args.id) : null;
7407
+ const createdAt = cached?.timestamp ? new Date(cached.timestamp) : import_util26.SnowflakeUtil.isValid(args.id) ? import_util26.SnowflakeUtil.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
  var import_collection13 = require("@fluxerjs/collection");
7494
- var import_types43 = require("@fluxerjs/types");
8082
+ var import_types44 = require("@fluxerjs/types");
7495
8083
  var GuildManager = class extends import_collection13.LimitedCollection {
7496
8084
  constructor(client) {
7497
8085
  super({
@@ -7500,6 +8088,7 @@ var GuildManager = class extends import_collection13.LimitedCollection {
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 import_collection13.LimitedCollection {
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(import_types43.Routes.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(import_types44.Routes.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: import_util3.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: import_util3.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) {
@@ -7617,13 +8248,14 @@ var MessageCache = class {
7617
8248
 
7618
8249
  // src/ClientCore/UserManager.ts
7619
8250
  var import_collection14 = require("@fluxerjs/collection");
7620
- var import_types44 = require("@fluxerjs/types");
8251
+ var import_types45 = require("@fluxerjs/types");
7621
8252
  var soft = (p) => p.catch(() => null);
7622
8253
  var UserManager = class extends import_collection14.LimitedCollection {
7623
8254
  constructor(client) {
7624
8255
  super({ maxSize: client.cache.limits.users });
7625
8256
  this.client = client;
7626
8257
  }
8258
+ pendingFetches = /* @__PURE__ */ new Map();
7627
8259
  /** Remove matching users (skips `client.user`). Returns count removed. */
7628
8260
  sweep(filter) {
7629
8261
  let removed = 0;
@@ -7637,16 +8269,30 @@ var UserManager = class extends import_collection14.LimitedCollection {
7637
8269
  }
7638
8270
  return removed;
7639
8271
  }
7640
- /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
8272
+ /**
8273
+ * Fetch a user by ID and update cache. Returns the cached user unless `force` is set
8274
+ * or the cached entry is only a partial stub (e.g. from a reaction event).
8275
+ */
7641
8276
  async fetch(userId, options) {
7642
- const cached = this.get(userId);
7643
- if (cached && !options?.force) return cached;
7644
- const data = await this.client.rest.get(import_types44.Routes.user(userId));
7645
- return this.client.getOrCreateUser(data);
8277
+ const id = normalizeSnowflakeId(userId, "users.fetch()");
8278
+ const cached = this.get(id);
8279
+ if (cached && !cached.partial && !options?.force) return cached;
8280
+ return dedupeFetch(
8281
+ this.pendingFetches,
8282
+ id,
8283
+ async () => this.client.getOrCreateUser(
8284
+ assertApiObjectWithId(
8285
+ await this.client.rest.get(import_types45.Routes.user(id)),
8286
+ "users.fetch()"
8287
+ )
8288
+ )
8289
+ );
7646
8290
  }
7647
- /** Return a cached user, otherwise {@link fetch}. */
8291
+ /** Return a cached (non-partial) user, otherwise {@link fetch}. */
7648
8292
  async resolve(userId) {
7649
- return this.get(userId) ?? this.fetch(userId);
8293
+ const id = normalizeSnowflakeId(userId, "users.resolve()");
8294
+ const cached = this.get(id);
8295
+ return cached && !cached.partial ? cached : this.fetch(id);
7650
8296
  }
7651
8297
  /**
7652
8298
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
@@ -7659,10 +8305,10 @@ var UserManager = class extends import_collection14.LimitedCollection {
7659
8305
  async fetchWithProfile(userId, options) {
7660
8306
  const guildId = options?.guildId ?? void 0;
7661
8307
  const [userData, globalProfileRaw, serverProfileRaw, memberData] = await Promise.all([
7662
- this.client.rest.get(import_types44.Routes.user(userId)),
7663
- soft(this.client.rest.get(import_types44.Routes.userProfile(userId))),
7664
- guildId ? soft(this.client.rest.get(import_types44.Routes.userProfile(userId, guildId))) : null,
7665
- guildId ? soft(this.client.rest.get(import_types44.Routes.guildMember(guildId, userId))) : null
8308
+ this.client.rest.get(import_types45.Routes.user(userId)),
8309
+ soft(this.client.rest.get(import_types45.Routes.userProfile(userId))),
8310
+ guildId ? soft(this.client.rest.get(import_types45.Routes.userProfile(userId, guildId))) : null,
8311
+ guildId ? soft(this.client.rest.get(import_types45.Routes.guildMember(guildId, userId))) : null
7666
8312
  ]);
7667
8313
  const user = this.client.getOrCreateUser(userData);
7668
8314
  let member = null;
@@ -7749,7 +8395,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7749
8395
  cache: resolved.cache,
7750
8396
  defaultReplyPing: options.defaultReplyPing ?? true
7751
8397
  };
7752
- this.logger = options.logger ?? (0, import_util26.createLogger)({
8398
+ this.logger = options.logger ?? (0, import_util27.createLogger)({
7753
8399
  level: options.logLevel ?? "warn"
7754
8400
  });
7755
8401
  this.cache = new CacheController(this, resolved.limits);
@@ -7787,7 +8433,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7787
8433
  * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
7788
8434
  * Does not log in. Call {@link login} with a token afterward.
7789
8435
  *
7790
- * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
8436
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.com` or `https://my.instance`)
7791
8437
  * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
7792
8438
  * @param connectOptions - Optional abort signal for the discovery request
7793
8439
  */
@@ -7864,6 +8510,38 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7864
8510
  fetchStickerMetadata(stickerId) {
7865
8511
  return fetchStickerMetadata(this, stickerId);
7866
8512
  }
8513
+ /** Fetch the source guild of a custom emoji. */
8514
+ fetchEmojiSource(emojiId) {
8515
+ return fetchEmojiSource(this, emojiId);
8516
+ }
8517
+ /** Fetch the source guild of a custom sticker. */
8518
+ fetchStickerSource(stickerId) {
8519
+ return fetchStickerSource(this, stickerId);
8520
+ }
8521
+ /** List discovery categories. */
8522
+ fetchDiscoveryCategories() {
8523
+ return fetchDiscoveryCategories(this);
8524
+ }
8525
+ /** Search discoverable guilds. */
8526
+ searchDiscoveryGuilds(options) {
8527
+ return searchDiscoveryGuilds(this, options);
8528
+ }
8529
+ /** Fetch experiment assignments for this account. */
8530
+ fetchExperiments() {
8531
+ return fetchExperiments(this);
8532
+ }
8533
+ /** Refresh expiring attachment CDN URLs. */
8534
+ refreshAttachmentUrls(attachmentUrls) {
8535
+ return refreshAttachmentUrls(this, attachmentUrls);
8536
+ }
8537
+ /** List instance custom guild badges (`GET /instance/badges`). */
8538
+ fetchInstanceBadges(options) {
8539
+ return fetchInstanceBadges(this, options);
8540
+ }
8541
+ /** Fetch forum/media thread post data for a channel. */
8542
+ fetchChannelPostData(channelId, threadIds) {
8543
+ return fetchChannelPostData(this, channelId, threadIds);
8544
+ }
7867
8545
  /**
7868
8546
  * Fetch the current application (`/applications/@me`).
7869
8547
  * @returns Application metadata (owner, flags, RPC origins, etc.)
@@ -7958,6 +8636,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7958
8636
  * @internal
7959
8637
  */
7960
8638
  getOrCreateUser(data) {
8639
+ if (!data || typeof data.id !== "string" || data.id.length === 0) {
8640
+ throw new TypeError("getOrCreateUser() requires user data with a non-empty string id");
8641
+ }
7961
8642
  const existing = this.users.get(data.id);
7962
8643
  if (existing) {
7963
8644
  existing._patch(data);
@@ -8008,7 +8689,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
8008
8689
  if (options.userIds !== void 0) data.user_ids = [...new Set(options.userIds)];
8009
8690
  if (options.presences !== void 0) data.presences = options.presences;
8010
8691
  if (options.nonce !== void 0) data.nonce = options.nonce;
8011
- this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestGuildMembers, d: data });
8692
+ this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestGuildMembers, d: data });
8012
8693
  }
8013
8694
  /**
8014
8695
  * Request guild member/online counts via gateway opcode 15.
@@ -8023,7 +8704,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
8023
8704
  }
8024
8705
  const data = { guild_ids: guildIds };
8025
8706
  if (options.nonce !== void 0) data.nonce = options.nonce;
8026
- this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestGuildCounts, d: data });
8707
+ this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestGuildCounts, d: data });
8027
8708
  }
8028
8709
  /**
8029
8710
  * Request per-channel member counts via gateway opcode 16.
@@ -8039,7 +8720,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
8039
8720
  if (options.channelId !== void 0) data.channel_id = options.channelId;
8040
8721
  if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
8041
8722
  if (options.nonce !== void 0) data.nonce = options.nonce;
8042
- this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestChannelMemberCounts, d: data });
8723
+ this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestChannelMemberCounts, d: data });
8043
8724
  }
8044
8725
  /**
8045
8726
  * Request unread counts for posts in one forum or media channel (opcode 28).
@@ -8075,7 +8756,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
8075
8756
  channel_id: options.channelId,
8076
8757
  threads
8077
8758
  };
8078
- this._sendToAllShards({ op: import_types45.GatewayOpcodes.RequestForumUnreads, d: data });
8759
+ this._sendToAllShards({ op: import_types46.GatewayOpcodes.RequestForumUnreads, d: data });
8079
8760
  }
8080
8761
  /**
8081
8762
  * Subscribe to thread traffic in a guild (opcode 14).
@@ -8105,7 +8786,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
8105
8786
  subscription.thread_member_lists = threadIds;
8106
8787
  }
8107
8788
  const data = { subscriptions: { [options.guildId]: subscription } };
8108
- this._sendToAllShards({ op: import_types45.GatewayOpcodes.LazyRequest, d: data });
8789
+ this._sendToAllShards({ op: import_types46.GatewayOpcodes.LazyRequest, d: data });
8109
8790
  }
8110
8791
  /**
8111
8792
  * Broadcast a gateway payload to all shards.
@@ -8210,7 +8891,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
8210
8891
  * @see {@link Routes}
8211
8892
  */
8212
8893
  static get Routes() {
8213
- return import_types45.Routes;
8894
+ return import_types46.Routes;
8214
8895
  }
8215
8896
  };
8216
8897
  // Annotate the CommonJS export names for ESM import in node: