@fluxerjs/core 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cluster.js CHANGED
@@ -83,7 +83,13 @@ var Events = {
83
83
  WebhooksUpdate: "webhooksUpdate",
84
84
  Resumed: "resumed",
85
85
  Error: "error",
86
- Debug: "debug"
86
+ Debug: "debug",
87
+ ShardReady: "shardReady",
88
+ ShardResumed: "shardResumed",
89
+ ShardDisconnect: "shardDisconnect",
90
+ ShardReconnecting: "shardReconnecting",
91
+ ShardError: "shardError",
92
+ ShardingRequired: "shardingRequired"
87
93
  };
88
94
 
89
95
  // src/LibErrors/ErrorCodes.ts
@@ -96,90 +102,13 @@ var import_util2 = require("@fluxerjs/util");
96
102
  var import_node_events3 = require("events");
97
103
  var import_rest3 = require("@fluxerjs/rest");
98
104
  var import_types39 = require("@fluxerjs/types");
99
- var import_util20 = require("@fluxerjs/util");
100
-
101
- // src/Domain/User.ts
102
- var import_types15 = require("@fluxerjs/types");
103
- var import_util9 = require("@fluxerjs/util");
104
-
105
- // src/Helpers/Constants.ts
106
- var import_rest = require("@fluxerjs/rest");
107
- var CDN_URL = "https://fluxerusercontent.com";
108
- var STATIC_CDN_URL = "https://fluxerstatic.com";
109
-
110
- // src/Helpers/Cdn.ts
111
- function mediaBase(options) {
112
- return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
113
- }
114
- function staticBase(options) {
115
- return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
116
- }
117
- function getExtension(hash, options) {
118
- const ext = options?.extension ?? "png";
119
- if (hash?.startsWith("a_")) return "gif";
120
- return ext;
121
- }
122
- function appendSize(options) {
123
- return options?.size ? `?size=${options.size}` : "";
124
- }
125
- function cdnAvatarURL(userId, avatarHash, options) {
126
- if (!avatarHash) return null;
127
- const ext = getExtension(avatarHash, options);
128
- const size = appendSize(options);
129
- return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
130
- }
131
- function cdnBannerURL(resourceId, bannerHash, options) {
132
- if (!bannerHash) return null;
133
- const ext = getExtension(bannerHash, options);
134
- const size = appendSize(options);
135
- return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
136
- }
137
- function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
138
- if (!avatarHash) return null;
139
- const ext = getExtension(avatarHash, options);
140
- const size = appendSize(options);
141
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
142
- }
143
- function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
144
- if (!bannerHash) return null;
145
- const ext = getExtension(bannerHash, options);
146
- const size = appendSize(options);
147
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
148
- }
149
- function cdnDefaultAvatarURL(userIdOrIndex, options) {
150
- const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
151
- return `${staticBase(options)}/avatars/${index}.png`;
152
- }
153
- function cdnGuildAssetURL(kind, id, hash, options) {
154
- if (!hash) return null;
155
- const size = options?.size ? `?size=${options.size}` : "";
156
- return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
157
- }
158
- function cdnEmojiURL(emojiId, animated, options) {
159
- const ext = animated ? "gif" : "png";
160
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
161
- }
162
- function cdnStickerURL(stickerId, animated, options) {
163
- const ext = animated ? "gif" : "png";
164
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
165
- }
166
-
167
- // src/Domain/Base.ts
168
- var Base = class {
169
- };
170
-
171
- // src/Domain/Channel/Base.ts
172
- var import_types8 = require("@fluxerjs/types");
173
- var import_util5 = require("@fluxerjs/util");
174
-
175
- // src/ClientCore/MessageManager.ts
176
- var import_collection3 = require("@fluxerjs/collection");
177
- var import_types6 = require("@fluxerjs/types");
105
+ var import_util26 = require("@fluxerjs/util");
178
106
 
179
107
  // src/Domain/Message/Message.ts
180
108
  var import_builders3 = require("@fluxerjs/builders");
181
- var import_collection2 = require("@fluxerjs/collection");
109
+ var import_collection3 = require("@fluxerjs/collection");
182
110
  var import_types5 = require("@fluxerjs/types");
111
+ var import_util6 = require("@fluxerjs/util");
183
112
 
184
113
  // src/ClientCore/SdkOptions/Attachments.ts
185
114
  function toMessageAttachmentEditWire(attachments) {
@@ -246,21 +175,66 @@ function toAttachmentUploadPlanResponse(data) {
246
175
  }
247
176
 
248
177
  // src/ClientCore/SdkOptions/Channels.ts
178
+ var import_util3 = require("@fluxerjs/util");
179
+ function toOverwriteWire(overwrite) {
180
+ return {
181
+ id: overwrite.id,
182
+ type: overwrite.type,
183
+ allow: overwrite.allow !== void 0 ? (0, import_util3.resolvePermissionsToBitfield)(overwrite.allow) : "0",
184
+ deny: overwrite.deny !== void 0 ? (0, import_util3.resolvePermissionsToBitfield)(overwrite.deny) : "0"
185
+ };
186
+ }
249
187
  function toChannelEditBody(options) {
250
188
  const body = {};
251
189
  if (options.name !== void 0) body.name = options.name;
252
190
  if (options.topic !== void 0) body.topic = options.topic;
191
+ if (options.url !== void 0) body.url = options.url;
253
192
  if (options.parentId !== void 0) body.parent_id = options.parentId;
254
193
  if (options.bitrate !== void 0) body.bitrate = options.bitrate;
255
194
  if (options.userLimit !== void 0) body.user_limit = options.userLimit;
195
+ if (options.voiceConnectionLimit !== void 0) {
196
+ body.voice_connection_limit = options.voiceConnectionLimit;
197
+ }
256
198
  if (options.nsfw !== void 0) body.nsfw = options.nsfw;
199
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
200
+ if (options.contentWarningLevel !== void 0) {
201
+ body.content_warning_level = options.contentWarningLevel;
202
+ }
203
+ if (options.contentWarningText !== void 0) {
204
+ body.content_warning_text = options.contentWarningText;
205
+ }
257
206
  if (options.rateLimitPerUser !== void 0) {
258
207
  body.rate_limit_per_user = options.rateLimitPerUser;
259
208
  }
260
209
  if (options.rtcRegion !== void 0) body.rtc_region = options.rtcRegion;
210
+ if (options.icon !== void 0) body.icon = options.icon;
211
+ if (options.permissionOverwrites !== void 0) {
212
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
213
+ }
214
+ return body;
215
+ }
216
+ function toChannelCreateBody(options) {
217
+ const body = { name: options.name, type: options.type };
218
+ if (options.topic !== void 0) body.topic = options.topic;
219
+ if (options.url !== void 0) body.url = options.url;
220
+ if (options.parentId !== void 0) body.parent_id = options.parentId;
221
+ if (options.bitrate !== void 0) body.bitrate = options.bitrate;
222
+ if (options.userLimit !== void 0) body.user_limit = options.userLimit;
223
+ if (options.voiceConnectionLimit !== void 0) {
224
+ body.voice_connection_limit = options.voiceConnectionLimit;
225
+ }
261
226
  if (options.permissionOverwrites !== void 0) {
262
- body.permission_overwrites = options.permissionOverwrites;
227
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
228
+ }
229
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
230
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
231
+ if (options.contentWarningLevel !== void 0) {
232
+ body.content_warning_level = options.contentWarningLevel;
233
+ }
234
+ if (options.contentWarningText !== void 0) {
235
+ body.content_warning_text = options.contentWarningText;
263
236
  }
237
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
264
238
  return body;
265
239
  }
266
240
  function toChannelInviteBody(options) {
@@ -271,6 +245,13 @@ function toChannelInviteBody(options) {
271
245
  if (options.temporary !== void 0) body.temporary = options.temporary;
272
246
  return body;
273
247
  }
248
+ function toGroupDmEditBody(options) {
249
+ const body = { type: 3 };
250
+ if (options.name !== void 0) body.name = options.name;
251
+ if (options.icon !== void 0) body.icon = options.icon;
252
+ if (options.nicks !== void 0) body.nicks = options.nicks;
253
+ return body;
254
+ }
274
255
 
275
256
  // src/ClientCore/SdkOptions/Discovery.ts
276
257
  function toDiscoveryBody(options) {
@@ -306,32 +287,8 @@ function toDiscoveryStatusPayload(data) {
306
287
  };
307
288
  }
308
289
 
309
- // src/ClientCore/SdkOptions/Expressions.ts
310
- function toEmojiCreateBody(options) {
311
- return { name: options.name, image: options.image };
312
- }
313
- function toEmojiEditBody(options) {
314
- return { name: options.name };
315
- }
316
- function toStickerCreateBody(options) {
317
- const body = {
318
- name: options.name,
319
- image: options.file
320
- };
321
- if (options.description !== void 0) body.description = options.description;
322
- if (options.tags !== void 0) body.tags = options.tags;
323
- return body;
324
- }
325
- function toStickerEditBody(options) {
326
- const body = {};
327
- if (options.name !== void 0) body.name = options.name;
328
- if (options.description !== void 0) body.description = options.description;
329
- if (options.tags !== void 0) body.tags = options.tags;
330
- return body;
331
- }
332
-
333
290
  // src/ClientCore/SdkOptions/Guild.ts
334
- var import_util3 = require("@fluxerjs/util");
291
+ var import_util4 = require("@fluxerjs/util");
335
292
  function toGuildEditBody(options) {
336
293
  const body = {};
337
294
  if (options.name !== void 0) body.name = options.name;
@@ -359,6 +316,16 @@ function toGuildEditBody(options) {
359
316
  body.splash_card_alignment = options.splashCardAlignment;
360
317
  }
361
318
  if (options.nsfwLevel !== void 0) body.nsfw_level = options.nsfwLevel;
319
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
320
+ if (options.contentWarningLevel !== void 0) {
321
+ body.content_warning_level = options.contentWarningLevel;
322
+ }
323
+ if (options.contentWarningText !== void 0) {
324
+ body.content_warning_text = options.contentWarningText;
325
+ }
326
+ if (options.messageHistoryCutoff !== void 0) {
327
+ body.message_history_cutoff = options.messageHistoryCutoff;
328
+ }
362
329
  if (options.features !== void 0) body.features = options.features;
363
330
  return body;
364
331
  }
@@ -368,6 +335,9 @@ function toGuildBanBody(options) {
368
335
  if (options.deleteMessageDays !== void 0) {
369
336
  body.delete_message_days = options.deleteMessageDays;
370
337
  }
338
+ if (options.deleteMessageSeconds !== void 0) {
339
+ body.delete_message_seconds = options.deleteMessageSeconds;
340
+ }
371
341
  if (options.banDurationSeconds !== void 0) {
372
342
  body.ban_duration_seconds = options.banDurationSeconds;
373
343
  }
@@ -382,18 +352,26 @@ function toChannelPositionBody(updates) {
382
352
  return row;
383
353
  });
384
354
  }
385
- function toRoleRequestBody(options) {
355
+ function toRolePermissionsBody(options) {
386
356
  const body = {};
357
+ if (options.permissions !== void 0) {
358
+ body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util4.resolvePermissionsToBitfield)(options.permissions);
359
+ }
360
+ return body;
361
+ }
362
+ function toRoleCreateBody(options) {
363
+ const body = { ...toRolePermissionsBody(options) };
364
+ if (options.name !== void 0) body.name = options.name;
365
+ if (options.color !== void 0) body.color = options.color;
366
+ return body;
367
+ }
368
+ function toRoleEditBody(options) {
369
+ const body = { ...toRolePermissionsBody(options) };
387
370
  if (options.name !== void 0) body.name = options.name;
388
371
  if (options.color !== void 0) body.color = options.color;
389
372
  if (options.hoist !== void 0) body.hoist = options.hoist;
390
373
  if (options.mentionable !== void 0) body.mentionable = options.mentionable;
391
- if (options.unicodeEmoji !== void 0) body.unicode_emoji = options.unicodeEmoji;
392
- if (options.position !== void 0) body.position = options.position;
393
374
  if (options.hoistPosition !== void 0) body.hoist_position = options.hoistPosition;
394
- if (options.permissions !== void 0) {
395
- body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util3.resolvePermissionsToBitfield)(options.permissions);
396
- }
397
375
  return body;
398
376
  }
399
377
 
@@ -411,6 +389,8 @@ function toMemberSearchBody(options) {
411
389
  if (options.userCreatedAtLte !== void 0) body.user_created_at_lte = options.userCreatedAtLte;
412
390
  if (options.sortBy !== void 0) body.sort_by = options.sortBy;
413
391
  if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
392
+ if (options.joinSourceType !== void 0) body.join_source_type = options.joinSourceType;
393
+ if (options.sourceInviteCode !== void 0) body.source_invite_code = options.sourceInviteCode;
414
394
  return body;
415
395
  }
416
396
  function toMemberEditBody(options) {
@@ -423,6 +403,7 @@ function toMemberEditBody(options) {
423
403
  if (options.pronouns !== void 0) body.pronouns = options.pronouns;
424
404
  if (options.accentColor !== void 0) body.accent_color = options.accentColor;
425
405
  if (options.profileFlags !== void 0) body.profile_flags = options.profileFlags;
406
+ if (options.mentionFlags !== void 0) body.mention_flags = options.mentionFlags;
426
407
  if (options.mute !== void 0) body.mute = options.mute;
427
408
  if (options.deaf !== void 0) body.deaf = options.deaf;
428
409
  if (options.communicationDisabledUntil !== void 0) {
@@ -444,15 +425,54 @@ function toBulkFetchWire(requests) {
444
425
  ...r.around !== void 0 ? { around: r.around } : {}
445
426
  }));
446
427
  }
447
-
448
- // src/ClientCore/SdkOptions/Packs.ts
449
- function toPackInviteBody(options) {
450
- const body = {};
451
- if (options.maxUses !== void 0) body.max_uses = options.maxUses;
452
- if (options.maxAge !== void 0) body.max_age = options.maxAge;
453
- if (options.unique !== void 0) body.unique = options.unique;
428
+ function toMessageSearchBody(options = {}) {
429
+ const body = { scope: "current" };
430
+ if (options.content !== void 0) body.content = options.content;
431
+ if (options.contents !== void 0) body.contents = options.contents;
432
+ if (options.exactPhrases !== void 0) body.exact_phrases = options.exactPhrases;
433
+ if (options.channelIds !== void 0) {
434
+ body.channel_id = options.channelIds;
435
+ body.channel_ids = options.channelIds;
436
+ }
437
+ if (options.excludeChannelIds !== void 0) body.exclude_channel_id = options.excludeChannelIds;
438
+ if (options.contextGuildId !== void 0) body.context_guild_id = options.contextGuildId;
439
+ if (options.contextChannelId !== void 0) body.context_channel_id = options.contextChannelId;
440
+ if (options.hitsPerPage !== void 0) body.hits_per_page = options.hitsPerPage;
441
+ if (options.page !== void 0) body.page = options.page;
442
+ if (options.cursor !== void 0) body.cursor = options.cursor;
443
+ if (options.minId !== void 0) body.min_id = options.minId;
444
+ if (options.maxId !== void 0) body.max_id = options.maxId;
445
+ if (options.authorIds !== void 0) body.author_id = options.authorIds;
446
+ if (options.excludeAuthorIds !== void 0) body.exclude_author_id = options.excludeAuthorIds;
447
+ if (options.authorType !== void 0) body.author_type = options.authorType;
448
+ if (options.excludeAuthorType !== void 0) body.exclude_author_type = options.excludeAuthorType;
449
+ if (options.mentions !== void 0) body.mentions = options.mentions;
450
+ if (options.excludeMentions !== void 0) body.exclude_mentions = options.excludeMentions;
451
+ if (options.mentionEveryone !== void 0) body.mention_everyone = options.mentionEveryone;
452
+ if (options.pinned !== void 0) body.pinned = options.pinned;
453
+ if (options.includeNsfw !== void 0) body.include_nsfw = options.includeNsfw;
454
+ if (options.has !== void 0) body.has = options.has;
455
+ if (options.excludeHas !== void 0) body.exclude_has = options.excludeHas;
456
+ if (options.sortBy !== void 0) body.sort_by = options.sortBy;
457
+ if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
454
458
  return body;
455
459
  }
460
+ function isMessageSearchIndexing(data) {
461
+ return "indexing" in data && data.indexing === true;
462
+ }
463
+ function toMessageSearchResponse(data) {
464
+ if (isMessageSearchIndexing(data)) {
465
+ return { indexing: true };
466
+ }
467
+ return {
468
+ messages: data.messages,
469
+ channels: data.channels,
470
+ total: data.total,
471
+ hitsPerPage: data.hits_per_page,
472
+ page: data.page,
473
+ ...data.cursor !== void 0 ? { cursor: data.cursor } : {}
474
+ };
475
+ }
456
476
 
457
477
  // src/ClientCore/SdkOptions/Presence.ts
458
478
  function toPresenceWire(options) {
@@ -566,6 +586,37 @@ function applyReplyPingSuppression(body) {
566
586
  function assignIfDefined(target, key, value) {
567
587
  if (value !== void 0) target[key] = value;
568
588
  }
589
+ function normalizeSendFiles(files) {
590
+ if (!files?.length) return void 0;
591
+ const normalized = [];
592
+ const metaFromBuilders = [];
593
+ let anyBuilderMeta = false;
594
+ for (let i = 0; i < files.length; i++) {
595
+ const file = files[i];
596
+ if (!file) continue;
597
+ if (file instanceof import_builders.AttachmentBuilder) {
598
+ normalized.push(file.toFileData());
599
+ const meta = {
600
+ id: i,
601
+ filename: file.filename,
602
+ ...file.description != null ? { description: file.description } : {},
603
+ ...file.spoiler ? { flags: import_types.MessageAttachmentFlags.IS_SPOILER } : {}
604
+ };
605
+ if (file.description != null || file.spoiler) anyBuilderMeta = true;
606
+ metaFromBuilders.push(meta);
607
+ } else {
608
+ normalized.push(file);
609
+ metaFromBuilders.push({
610
+ id: i,
611
+ filename: file.filename ?? file.name
612
+ });
613
+ }
614
+ }
615
+ return {
616
+ files: normalized,
617
+ metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
618
+ };
619
+ }
569
620
  function buildSendBody(options) {
570
621
  const body = typeof options === "string" ? { content: options } : options;
571
622
  const result = {};
@@ -573,16 +624,17 @@ function buildSendBody(options) {
573
624
  if (body.embeds?.length) {
574
625
  result.embeds = body.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
575
626
  }
627
+ const normalizedFiles = normalizeSendFiles(body.files);
576
628
  if (body.uploadedAttachments?.length) {
577
629
  result.attachments = body.uploadedAttachments;
578
- } else if (body.files?.length) {
630
+ } else if (normalizedFiles?.files.length) {
579
631
  result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
580
632
  id: a.id,
581
633
  filename: a.filename,
582
634
  ...a.title != null && { title: a.title },
583
635
  ...a.description != null && { description: a.description },
584
636
  ...a.flags != null && { flags: a.flags }
585
- })) : body.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
637
+ })) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
586
638
  }
587
639
  if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
588
640
  if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
@@ -676,9 +728,10 @@ async function prepareMessagePostPayload(options, defaults) {
676
728
  } else if (allowedMentions?.repliedUser === false) {
677
729
  applyReplyPingSuppression(body);
678
730
  }
731
+ const resolvedFiles = normalizeSendFiles(files);
679
732
  return {
680
733
  body,
681
- files: !uploadedAttachments?.length && files?.length ? await resolveMessageFiles(files) : void 0
734
+ files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
682
735
  };
683
736
  }
684
737
 
@@ -690,9 +743,9 @@ var import_collection = require("@fluxerjs/collection");
690
743
  var import_types2 = require("@fluxerjs/types");
691
744
 
692
745
  // src/Helpers/HttpErrors.ts
693
- var import_rest2 = require("@fluxerjs/rest");
746
+ var import_rest = require("@fluxerjs/rest");
694
747
  function httpStatus(err) {
695
- if (err instanceof import_rest2.FluxerAPIError) return err.statusCode;
748
+ if (err instanceof import_rest.FluxerAPIError) return err.statusCode;
696
749
  if (typeof err === "object" && err !== null && "statusCode" in err) {
697
750
  const code = err.statusCode;
698
751
  return typeof code === "number" ? code : void 0;
@@ -705,7 +758,7 @@ function errorMessage(err, fallback) {
705
758
  return fallback;
706
759
  }
707
760
  function rethrowMapped(err, options) {
708
- if (err instanceof import_rest2.RateLimitError) throw err;
761
+ if (err instanceof import_rest.RateLimitError) throw err;
709
762
  if (err instanceof import_util2.FluxerError) throw err;
710
763
  if (options.notFound && httpStatus(err) === 404) {
711
764
  throw new import_util2.FluxerError(options.notFound.message, {
@@ -727,14 +780,22 @@ function qs(params) {
727
780
  return out ? `?${out}` : "";
728
781
  }
729
782
 
783
+ // src/Domain/Base.ts
784
+ var Base = class {
785
+ };
786
+
730
787
  // src/Domain/Message/MessageReaction.ts
731
- var MessageReaction = class extends Base {
788
+ var MessageReaction = class _MessageReaction extends Base {
732
789
  client;
733
790
  messageId;
734
791
  channelId;
735
792
  guildId;
736
793
  emoji;
737
- /** Raw gateway payload for low-level access. */
794
+ /** Total count when hydrated from a message payload; `1` for gateway add events. */
795
+ count;
796
+ /** Whether the current user reacted (message payload); false for gateway remove. */
797
+ me;
798
+ /** Raw gateway payload for low-level access (null when built from a message aggregate). */
738
799
  _data;
739
800
  constructor(client, data) {
740
801
  super();
@@ -748,6 +809,26 @@ var MessageReaction = class extends Base {
748
809
  ...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
749
810
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
750
811
  };
812
+ this.count = 1;
813
+ this.me = false;
814
+ }
815
+ /** Build a reaction aggregate from a message's `reactions` array entry. */
816
+ static fromMessage(message, data) {
817
+ const reaction = new _MessageReaction(message.client, {
818
+ user_id: message.client.user?.id ?? "0",
819
+ message_id: message.id,
820
+ channel_id: message.channelId,
821
+ guild_id: message.guildId ?? void 0,
822
+ emoji: {
823
+ name: data.emoji.name,
824
+ id: data.emoji.id ?? void 0,
825
+ animated: data.emoji.animated ?? void 0
826
+ }
827
+ });
828
+ Object.defineProperty(reaction, "_data", { value: null });
829
+ reaction.count = data.count;
830
+ reaction.me = data.me ?? false;
831
+ return reaction;
751
832
  }
752
833
  /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
753
834
  get emojiIdentifier() {
@@ -757,12 +838,23 @@ var MessageReaction = class extends Base {
757
838
  get guild() {
758
839
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
759
840
  }
841
+ /** Cached message this reaction belongs to, or null if the message was not cached. */
842
+ get message() {
843
+ const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
844
+ return cached ? new Message(this.client, cached) : null;
845
+ }
846
+ /** Cached text-capable channel, or null if uncached / not text-based. */
847
+ get channel() {
848
+ const channel = this.client.channels.get(this.channelId);
849
+ return channel?.isTextBased() ? channel : null;
850
+ }
760
851
  /**
761
- * Fetch the message this reaction belongs to.
762
- * Use when you need to edit, delete, or otherwise interact with the message.
852
+ * Fetch the message this reaction belongs to (cache first, then REST).
763
853
  * @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
764
854
  */
765
855
  async fetchMessage() {
856
+ const cached = this.message;
857
+ if (cached) return cached;
766
858
  try {
767
859
  const data = await this.client.rest.get(
768
860
  import_types2.Routes.channelMessage(this.channelId, this.messageId)
@@ -781,7 +873,7 @@ var MessageReaction = class extends Base {
781
873
  };
782
874
 
783
875
  // src/Helpers/ReactionCollector.ts
784
- var ReactionCollector = class extends import_node_events.EventEmitter {
876
+ var ReactionCollector = class _ReactionCollector extends import_node_events.EventEmitter {
785
877
  client;
786
878
  messageId;
787
879
  channelId;
@@ -824,15 +916,17 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
824
916
  ...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
825
917
  }
826
918
  });
827
- const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
919
+ const cached = this.client.users.get(entry.userId);
920
+ const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
921
+ {
828
922
  id: entry.userId,
829
923
  username: "Unknown",
830
924
  discriminator: "0",
831
- global_name: null,
925
+ globalName: null,
832
926
  avatar: null,
833
- avatar_color: null,
834
- flags: 0
835
- });
927
+ bot: false,
928
+ system: false
929
+ };
836
930
  this._collect(reaction, user, entry.userId);
837
931
  }
838
932
  };
@@ -864,6 +958,21 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
864
958
  }
865
959
  this.emit("end", this.collected, reason);
866
960
  }
961
+ /**
962
+ * One-shot helper used by {@link Message.awaitReactions}.
963
+ * Resolves with the collected reactions when the collector ends.
964
+ * Rejects if `options.errors` includes the end reason.
965
+ */
966
+ static awaitReactions(client, messageId, channelId, options) {
967
+ const errors = options?.errors ?? [];
968
+ return new Promise((resolve, reject) => {
969
+ const collector = new _ReactionCollector(client, messageId, channelId, options);
970
+ collector.on("end", (collected, reason) => {
971
+ if (errors.includes(reason)) reject(collected);
972
+ else resolve(collected);
973
+ });
974
+ });
975
+ }
867
976
  on(event, listener) {
868
977
  return super.on(event, listener);
869
978
  }
@@ -872,127 +981,281 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
872
981
  }
873
982
  };
874
983
 
875
- // src/Domain/Message/Reactions.ts
876
- var import_types3 = require("@fluxerjs/types");
877
- var import_util4 = require("@fluxerjs/util");
878
- async function emojiPath(message, emoji) {
879
- return message.client.resolveEmoji(emoji, message.guildId);
880
- }
881
- function toReactionEmoji(emoji) {
882
- if (typeof emoji !== "string") {
883
- return {
884
- name: emoji.name,
885
- ...emoji.id !== void 0 ? { id: emoji.id } : {},
886
- ...emoji.animated !== void 0 ? { animated: emoji.animated } : {}
887
- };
888
- }
889
- const animatedWire = /^a:(\w+):(\d+)$/.exec(emoji);
890
- if (animatedWire) {
891
- return { name: animatedWire[1], id: animatedWire[2], animated: true };
892
- }
893
- const parsed = (0, import_util4.parseEmoji)(emoji);
894
- if (parsed?.id) {
895
- return {
896
- name: parsed.name,
897
- id: parsed.id,
898
- ...parsed.animated ? { animated: true } : {}
899
- };
900
- }
901
- let name = emoji;
902
- try {
903
- name = decodeURIComponent(emoji);
904
- } catch {
905
- }
906
- return { name: parsed?.name ?? name };
907
- }
908
- function emitOwnReactionAdd(message, wireOrInput) {
909
- const user = message.client.user;
910
- if (!user) return;
911
- const emojiPayload = toReactionEmoji(wireOrInput);
912
- const reaction = new MessageReaction(message.client, {
913
- user_id: user.id,
914
- channel_id: message.channelId,
915
- message_id: message.id,
916
- guild_id: message.guildId ?? void 0,
917
- emoji: {
918
- name: emojiPayload.name,
919
- ...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
920
- ...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
921
- }
922
- });
923
- const payload = {
924
- reaction,
925
- user,
926
- messageId: message.id,
927
- channelId: message.channelId,
928
- emoji: emojiPayload,
929
- userId: user.id
984
+ // src/Domain/Message/Attachment.ts
985
+ function toMessageAttachment(data) {
986
+ return {
987
+ id: data.id,
988
+ filename: data.filename,
989
+ title: data.title ?? null,
990
+ description: data.description ?? null,
991
+ contentType: data.content_type ?? null,
992
+ contentHash: data.content_hash ?? null,
993
+ size: data.size,
994
+ url: data.url ?? null,
995
+ proxyUrl: data.proxy_url ?? null,
996
+ width: data.width ?? null,
997
+ height: data.height ?? null,
998
+ placeholder: data.placeholder ?? null,
999
+ flags: data.flags ?? 0,
1000
+ nsfw: data.nsfw ?? false,
1001
+ duration: data.duration ?? null,
1002
+ waveform: data.waveform ?? null,
1003
+ expiresAt: data.expires_at ? new Date(data.expires_at) : null,
1004
+ expired: data.expired ?? false
930
1005
  };
931
- message.client.emit(Events.MessageReactionAdd, payload);
932
- }
933
- async function reactToMessage(message, emoji) {
934
- const wire = await emojiPath(message, emoji);
935
- await message.client.rest.put(
936
- import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
937
- );
938
- emitOwnReactionAdd(message, wire);
939
- }
940
- async function removeMessageReaction(message, emoji, userId) {
941
- const e = await emojiPath(message, emoji);
942
- const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
943
- await message.client.rest.delete(route);
944
- }
945
- async function removeAllMessageReactions(message) {
946
- await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
947
1006
  }
948
- async function removeMessageReactionEmoji(message, emoji) {
949
- const e = await emojiPath(message, emoji);
950
- await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
951
- }
952
- async function fetchMessageReactionUsers(message, emoji, options) {
953
- return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
1007
+
1008
+ // src/Domain/Message/Embed.ts
1009
+ function toMessageEmbedAuthor(data) {
1010
+ return {
1011
+ name: data.name ?? null,
1012
+ url: data.url ?? null,
1013
+ iconUrl: data.icon_url ?? null,
1014
+ proxyIconUrl: data.proxy_icon_url ?? null
1015
+ };
954
1016
  }
955
- async function fetchMessageReactionUsersPage(message, emoji, options) {
956
- const e = await emojiPath(message, emoji);
957
- const params = new URLSearchParams();
958
- if (options?.limit != null) params.set("limit", String(options.limit));
959
- if (options?.after) params.set("after", options.after);
960
- const qs2 = params.toString();
961
- const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
962
- const data = await message.client.rest.get(route);
963
- if (Array.isArray(data)) {
964
- return {
965
- users: data.map((u) => message.client.getOrCreateUser(u)),
966
- hasMore: false,
967
- nextAfter: null
968
- };
969
- }
970
- const list = data.items ?? data.users ?? [];
1017
+ function toMessageEmbedFooter(data) {
971
1018
  return {
972
- users: list.map((u) => message.client.getOrCreateUser(u)),
973
- hasMore: data.has_more ?? false,
974
- nextAfter: data.next_after ?? null
1019
+ text: data.text,
1020
+ iconUrl: data.icon_url ?? null,
1021
+ proxyIconUrl: data.proxy_icon_url ?? null
975
1022
  };
976
1023
  }
977
-
978
- // src/Domain/Message/Send.ts
979
- var import_builders2 = require("@fluxerjs/builders");
980
- var import_types4 = require("@fluxerjs/types");
981
- function toReplyTarget(ref) {
1024
+ function toMessageEmbedMedia(data) {
982
1025
  return {
983
- channelId: ref.channel_id,
984
- messageId: ref.message_id,
985
- ...ref.guild_id != null ? { guildId: ref.guild_id } : {}
1026
+ url: data.url,
1027
+ proxyUrl: data.proxy_url ?? null,
1028
+ contentType: data.content_type ?? null,
1029
+ contentHash: data.content_hash ?? null,
1030
+ width: data.width ?? null,
1031
+ height: data.height ?? null,
1032
+ description: data.description ?? null,
1033
+ placeholder: data.placeholder ?? null,
1034
+ duration: data.duration ?? null,
1035
+ flags: data.flags ?? null
986
1036
  };
987
1037
  }
988
- function toSendOptions(content) {
989
- if (typeof content === "string") return { content };
990
- if (content instanceof import_builders2.MessagePayload) return messagePayloadToSendOptions(content);
991
- return { ...content };
1038
+ function toMessageEmbed(data) {
1039
+ const full = data;
1040
+ return {
1041
+ type: data.type ?? "rich",
1042
+ url: data.url ?? null,
1043
+ title: data.title ?? null,
1044
+ color: data.color ?? null,
1045
+ timestamp: data.timestamp ? new Date(data.timestamp) : null,
1046
+ description: data.description ?? null,
1047
+ author: data.author ? toMessageEmbedAuthor(data.author) : null,
1048
+ image: data.image ? toMessageEmbedMedia(data.image) : null,
1049
+ thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
1050
+ footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
1051
+ fields: (data.fields ?? []).map((f) => ({
1052
+ name: f.name,
1053
+ value: f.value,
1054
+ inline: f.inline ?? false
1055
+ })),
1056
+ provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
1057
+ video: data.video ? toMessageEmbedMedia(data.video) : null,
1058
+ audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
1059
+ nsfw: data.nsfw ?? false,
1060
+ children: (full.children ?? []).map(toMessageEmbed),
1061
+ html: full.html ?? null,
1062
+ htmlWidth: full.html_width ?? null,
1063
+ htmlHeight: full.html_height ?? null
1064
+ };
992
1065
  }
993
- async function createMessageBody(content, referenced_message, ping) {
994
- if (typeof content === "string" && content.length === 0) {
995
- throw new import_util2.FluxerError("Cannot send an empty message", { code: import_util.ErrorCodes.EmptyMessage });
1066
+
1067
+ // src/Domain/Message/MessageReactionManager.ts
1068
+ var import_collection2 = require("@fluxerjs/collection");
1069
+ var MessageReactionManager = class {
1070
+ constructor(message) {
1071
+ this.message = message;
1072
+ }
1073
+ _cache = new import_collection2.Collection();
1074
+ /** Reactions keyed by unicode name or `name:id`. */
1075
+ get cache() {
1076
+ return this._cache;
1077
+ }
1078
+ get size() {
1079
+ return this._cache.size;
1080
+ }
1081
+ [Symbol.iterator]() {
1082
+ return this._cache.values();
1083
+ }
1084
+ /** @internal Sync from an API message payload. */
1085
+ _patch(reactions) {
1086
+ this._cache.clear();
1087
+ for (const data of reactions ?? []) {
1088
+ const reaction = MessageReaction.fromMessage(this.message, data);
1089
+ this._cache.set(reaction.emojiIdentifier, reaction);
1090
+ }
1091
+ }
1092
+ };
1093
+
1094
+ // src/Domain/Message/MessageSticker.ts
1095
+ var import_util5 = require("@fluxerjs/util");
1096
+
1097
+ // src/Helpers/Constants.ts
1098
+ var import_rest2 = require("@fluxerjs/rest");
1099
+ var CDN_URL = "https://fluxerusercontent.com";
1100
+ var STATIC_CDN_URL = "https://fluxerstatic.com";
1101
+
1102
+ // src/Helpers/Cdn.ts
1103
+ function mediaBase(options) {
1104
+ return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1105
+ }
1106
+ function staticBase(options) {
1107
+ return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
1108
+ }
1109
+ function getExtension(hash, options) {
1110
+ const ext = options?.extension ?? "png";
1111
+ if (hash?.startsWith("a_")) return "gif";
1112
+ return ext;
1113
+ }
1114
+ function appendSize(options) {
1115
+ return options?.size ? `?size=${options.size}` : "";
1116
+ }
1117
+ function cdnAvatarURL(userId, avatarHash, options) {
1118
+ if (!avatarHash) return null;
1119
+ const ext = getExtension(avatarHash, options);
1120
+ const size = appendSize(options);
1121
+ return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1122
+ }
1123
+ function cdnBannerURL(resourceId, bannerHash, options) {
1124
+ if (!bannerHash) return null;
1125
+ const ext = getExtension(bannerHash, options);
1126
+ const size = appendSize(options);
1127
+ return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1128
+ }
1129
+ function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1130
+ if (!avatarHash) return null;
1131
+ const ext = getExtension(avatarHash, options);
1132
+ const size = appendSize(options);
1133
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1134
+ }
1135
+ function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1136
+ if (!bannerHash) return null;
1137
+ const ext = getExtension(bannerHash, options);
1138
+ const size = appendSize(options);
1139
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1140
+ }
1141
+ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1142
+ const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
1143
+ return `${staticBase(options)}/avatars/${index}.png`;
1144
+ }
1145
+ function cdnGuildAssetURL(kind, id, hash, options) {
1146
+ if (!hash) return null;
1147
+ const size = options?.size ? `?size=${options.size}` : "";
1148
+ return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1149
+ }
1150
+ function cdnEmojiURL(emojiId, animated, options) {
1151
+ const ext = animated ? "gif" : "png";
1152
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1153
+ }
1154
+ function cdnStickerURL(stickerId, animated, options) {
1155
+ const ext = animated ? "gif" : "png";
1156
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1157
+ }
1158
+
1159
+ // src/Domain/Message/MessageSticker.ts
1160
+ var MessageSticker = class extends Base {
1161
+ client;
1162
+ id;
1163
+ name;
1164
+ description;
1165
+ tags;
1166
+ animated;
1167
+ constructor(client, data) {
1168
+ super();
1169
+ this.client = client;
1170
+ this.id = data.id;
1171
+ this.name = data.name;
1172
+ this.description = data.description ?? "";
1173
+ this.tags = data.tags ?? [];
1174
+ this.animated = data.animated ?? false;
1175
+ }
1176
+ /** CDN URL for this sticker image. */
1177
+ get url() {
1178
+ return cdnStickerURL(this.id, this.animated, {
1179
+ mediaBase: this.client.instance.endpoints.media
1180
+ });
1181
+ }
1182
+ /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
1183
+ get createdTimestamp() {
1184
+ return import_util5.SnowflakeUtil.timestampFromSnowflake(this.id);
1185
+ }
1186
+ /** Date when this sticker was created, derived from its snowflake ID. */
1187
+ get createdAt() {
1188
+ return import_util5.SnowflakeUtil.dateFromSnowflake(this.id);
1189
+ }
1190
+ };
1191
+
1192
+ // src/Domain/Message/Reactions.ts
1193
+ var import_types3 = require("@fluxerjs/types");
1194
+ async function emojiPath(message, emoji) {
1195
+ return message.client.resolveEmoji(emoji, message.guildId);
1196
+ }
1197
+ async function reactToMessage(message, emoji) {
1198
+ const wire = await emojiPath(message, emoji);
1199
+ await message.client.rest.put(
1200
+ import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
1201
+ );
1202
+ }
1203
+ async function removeMessageReaction(message, emoji, userId) {
1204
+ const e = await emojiPath(message, emoji);
1205
+ const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
1206
+ await message.client.rest.delete(route);
1207
+ }
1208
+ async function removeAllMessageReactions(message) {
1209
+ await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
1210
+ }
1211
+ async function removeMessageReactionEmoji(message, emoji) {
1212
+ const e = await emojiPath(message, emoji);
1213
+ await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
1214
+ }
1215
+ async function fetchMessageReactionUsers(message, emoji, options) {
1216
+ return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
1217
+ }
1218
+ async function fetchMessageReactionUsersPage(message, emoji, options) {
1219
+ const e = await emojiPath(message, emoji);
1220
+ const params = new URLSearchParams();
1221
+ if (options?.limit != null) params.set("limit", String(options.limit));
1222
+ if (options?.after) params.set("after", options.after);
1223
+ const qs2 = params.toString();
1224
+ const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
1225
+ const data = await message.client.rest.get(route);
1226
+ if (Array.isArray(data)) {
1227
+ return {
1228
+ users: data.map((u) => message.client.getOrCreateUser(u)),
1229
+ hasMore: false,
1230
+ nextAfter: null
1231
+ };
1232
+ }
1233
+ const list = data.items ?? data.users ?? [];
1234
+ return {
1235
+ users: list.map((u) => message.client.getOrCreateUser(u)),
1236
+ hasMore: data.has_more ?? false,
1237
+ nextAfter: data.next_after ?? null
1238
+ };
1239
+ }
1240
+
1241
+ // src/Domain/Message/Send.ts
1242
+ var import_builders2 = require("@fluxerjs/builders");
1243
+ var import_types4 = require("@fluxerjs/types");
1244
+ function toReplyTarget(ref) {
1245
+ return {
1246
+ channelId: ref.channel_id,
1247
+ messageId: ref.message_id,
1248
+ ...ref.guild_id != null ? { guildId: ref.guild_id } : {}
1249
+ };
1250
+ }
1251
+ function toSendOptions(content) {
1252
+ if (typeof content === "string") return { content };
1253
+ if (content instanceof import_builders2.MessagePayload) return messagePayloadToSendOptions(content);
1254
+ return { ...content };
1255
+ }
1256
+ async function createMessageBody(content, referenced_message, ping) {
1257
+ if (typeof content === "string" && content.length === 0) {
1258
+ throw new import_util2.FluxerError("Cannot send an empty message", { code: import_util.ErrorCodes.EmptyMessage });
996
1259
  }
997
1260
  const opts = toSendOptions(content);
998
1261
  if (referenced_message) {
@@ -1041,7 +1304,33 @@ async function replyToMessage(message, options, replyOptions) {
1041
1304
  }
1042
1305
 
1043
1306
  // src/Domain/Message/Message.ts
1307
+ function toMessageCall(data) {
1308
+ return {
1309
+ participants: data.participants,
1310
+ endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
1311
+ };
1312
+ }
1313
+ function toMessageSnapshot(client, data) {
1314
+ return {
1315
+ content: data.content ?? null,
1316
+ createdAt: new Date(data.timestamp),
1317
+ editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
1318
+ mentionUserIds: data.mentions ?? [],
1319
+ mentionRoles: data.mention_roles ?? [],
1320
+ embeds: (data.embeds ?? []).map(toMessageEmbed),
1321
+ attachments: (data.attachments ?? []).map(toMessageAttachment),
1322
+ stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
1323
+ ...data.type !== void 0 ? { type: data.type } : {}
1324
+ };
1325
+ }
1326
+ function resolveMessageFlags(flags) {
1327
+ if (flags === void 0) return void 0;
1328
+ if (typeof flags === "number") return flags;
1329
+ return Number(import_util6.MessageFlagsBitField.resolve(flags));
1330
+ }
1044
1331
  var Message = class _Message extends Base {
1332
+ /** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
1333
+ partial = false;
1045
1334
  /** The {@link Client} that instantiated this message. */
1046
1335
  client;
1047
1336
  /** Snowflake ID of this message. */
@@ -1070,7 +1359,7 @@ var Message = class _Message extends Base {
1070
1359
  mentionEveryone;
1071
1360
  /** Whether this is a text-to-speech message. */
1072
1361
  tts;
1073
- /** Embedded content (rich previews, etc.). */
1362
+ /** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
1074
1363
  embeds;
1075
1364
  /** Stickers sent with the message. */
1076
1365
  stickers;
@@ -1092,26 +1381,41 @@ var Message = class _Message extends Base {
1092
1381
  mentionRoles;
1093
1382
  /** Client-side nonce for deduplication. */
1094
1383
  nonce;
1095
- /** Cached text/DM/guild channel, or null if uncached. */
1384
+ /**
1385
+ * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1386
+ * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
1387
+ */
1096
1388
  get channel() {
1097
- return this.client.channels.get(this.channelId) ?? null;
1389
+ const channel = this.client.channels.get(this.channelId) ?? null;
1390
+ return channel?.isTextBased() ? channel : null;
1098
1391
  }
1099
1392
  /** Cached guild, or null for DMs / uncached. */
1100
1393
  get guild() {
1101
1394
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
1102
1395
  }
1103
- /** Fetch and resolve the channel this message is in. */
1396
+ /** Cached guild member for the author, or null in DMs / if uncached. */
1397
+ get member() {
1398
+ return this.guild?.members.get(this.author.id) ?? null;
1399
+ }
1400
+ /**
1401
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1402
+ * has {@link Channel.delete} and {@link Channel.send}.
1403
+ * @example
1404
+ * const channel = await message.resolveChannel();
1405
+ * await channel.delete();
1406
+ */
1104
1407
  async resolveChannel() {
1105
1408
  return this.client.channels.resolve(this.channelId);
1106
1409
  }
1107
- /** Fetch and resolve the guild, or null if a DM. */
1410
+ /**
1411
+ * Fetch and resolve the guild, or null if a DM.
1412
+ * Propagates network/auth errors; only returns null when there is no guildId.
1413
+ * @example
1414
+ * const guild = await message.resolveGuild();
1415
+ */
1108
1416
  async resolveGuild() {
1109
1417
  if (!this.guildId) return null;
1110
- try {
1111
- return await this.client.guilds.resolve(this.guildId);
1112
- } catch {
1113
- return null;
1114
- }
1418
+ return this.client.guilds.resolve(this.guildId);
1115
1419
  }
1116
1420
  /**
1117
1421
  * Construct a message from API data.
@@ -1128,29 +1432,73 @@ var Message = class _Message extends Base {
1128
1432
  this.createdAt = new Date(data.timestamp);
1129
1433
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1130
1434
  this.pinned = data.pinned;
1131
- this.attachments = new import_collection2.Collection();
1132
- for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
1435
+ this.attachments = new import_collection3.Collection();
1436
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1133
1437
  this.type = data.type ?? import_types5.MessageType.Default;
1134
- this.flags = data.flags ?? 0;
1438
+ this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
1135
1439
  this.mentionEveryone = data.mention_everyone ?? false;
1136
1440
  this.tts = data.tts ?? false;
1137
- this.embeds = data.embeds ?? [];
1138
- this.stickers = data.stickers ?? [];
1139
- this.reactions = data.reactions ?? [];
1140
- this.messageReference = data.message_reference ?? null;
1141
- this.messageSnapshots = data.message_snapshots ?? [];
1142
- this.call = data.call ?? null;
1441
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1442
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
1443
+ this.reactions = new MessageReactionManager(this);
1444
+ this.reactions._patch(data.reactions);
1445
+ this.messageReference = data.message_reference ? {
1446
+ channelId: data.message_reference.channel_id,
1447
+ messageId: data.message_reference.message_id,
1448
+ guildId: data.message_reference.guild_id ?? null,
1449
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1450
+ } : null;
1451
+ this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
1452
+ this.call = data.call ? toMessageCall(data.call) : null;
1143
1453
  this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
1144
1454
  this.webhookId = data.webhook_id ?? null;
1145
1455
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1146
1456
  this.mentionRoles = data.mention_roles ?? [];
1147
1457
  this.nonce = data.nonce ?? null;
1148
1458
  }
1149
- /** Send a message in this channel without replying. */
1459
+ /**
1460
+ * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
1461
+ * @internal
1462
+ */
1463
+ _patch(data) {
1464
+ this.content = data.content;
1465
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1466
+ this.pinned = data.pinned;
1467
+ this.attachments.clear();
1468
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1469
+ this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
1470
+ this.mentionEveryone = data.mention_everyone ?? false;
1471
+ this.tts = data.tts ?? false;
1472
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1473
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1474
+ this.reactions._patch(data.reactions);
1475
+ this.messageReference = data.message_reference ? {
1476
+ channelId: data.message_reference.channel_id,
1477
+ messageId: data.message_reference.message_id,
1478
+ guildId: data.message_reference.guild_id ?? null,
1479
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1480
+ } : null;
1481
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
1482
+ (s) => toMessageSnapshot(this.client, s)
1483
+ );
1484
+ this.call = data.call ? toMessageCall(data.call) : null;
1485
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
1486
+ this.webhookId = data.webhook_id ?? null;
1487
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1488
+ this.mentionRoles = data.mention_roles ?? [];
1489
+ this.nonce = data.nonce ?? null;
1490
+ }
1491
+ /**
1492
+ * Send a standalone message in this channel (not a reply).
1493
+ * Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
1494
+ */
1150
1495
  async send(options) {
1151
1496
  return sendMessage(this, options);
1152
1497
  }
1153
- /** Send a message to another channel by ID. */
1498
+ /**
1499
+ * Send a message to another channel by ID.
1500
+ * Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
1501
+ */
1154
1502
  async sendTo(channelId, options) {
1155
1503
  return sendMessageTo(this, channelId, options);
1156
1504
  }
@@ -1164,6 +1512,16 @@ var Message = class _Message extends Base {
1164
1512
  async reply(options, replyOptions) {
1165
1513
  return replyToMessage(this, options, replyOptions);
1166
1514
  }
1515
+ /**
1516
+ * Hydrate a partial message, or return the message as-is.
1517
+ * @example
1518
+ * client.on(Events.MessageUpdate, async (_old, msg) => {
1519
+ * const message = await Message.resolve(msg);
1520
+ * });
1521
+ */
1522
+ static async resolve(message) {
1523
+ return message.partial ? message.fetch() : message;
1524
+ }
1167
1525
  /** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
1168
1526
  static async _createMessageBody(content, referenced_message, ping) {
1169
1527
  return createMessageBody(content, referenced_message, ping);
@@ -1176,7 +1534,7 @@ var Message = class _Message extends Base {
1176
1534
  async edit(options) {
1177
1535
  const body = {};
1178
1536
  if (options.content !== void 0) body.content = options.content;
1179
- if (options.embeds?.length) {
1537
+ if (options.embeds !== void 0) {
1180
1538
  body.embeds = options.embeds.map(
1181
1539
  (e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e
1182
1540
  );
@@ -1184,7 +1542,8 @@ var Message = class _Message extends Base {
1184
1542
  if (options.allowedMentions) {
1185
1543
  body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
1186
1544
  }
1187
- if (options.flags !== void 0) body.flags = options.flags;
1545
+ const flags = resolveMessageFlags(options.flags);
1546
+ if (flags !== void 0) body.flags = flags;
1188
1547
  if (options.attachments !== void 0) {
1189
1548
  body.attachments = toMessageAttachmentEditWire(options.attachments);
1190
1549
  }
@@ -1199,6 +1558,13 @@ var Message = class _Message extends Base {
1199
1558
  createReactionCollector(options) {
1200
1559
  return new ReactionCollector(this.client, this.id, this.channelId, options);
1201
1560
  }
1561
+ /**
1562
+ * Wait for reactions matching the filter, then resolve the collected set.
1563
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
1564
+ */
1565
+ awaitReactions(options) {
1566
+ return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
1567
+ }
1202
1568
  /** Fetch the latest version of this message from the API. */
1203
1569
  async fetch() {
1204
1570
  return this.client.channels.fetchMessage(this.channelId, this.id);
@@ -1252,7 +1618,68 @@ var Message = class _Message extends Base {
1252
1618
  }
1253
1619
  };
1254
1620
 
1621
+ // src/Domain/Message/PartialMessage.ts
1622
+ var import_util7 = require("@fluxerjs/util");
1623
+ var PartialMessage = class {
1624
+ partial = true;
1625
+ client;
1626
+ id;
1627
+ channelId;
1628
+ guildId;
1629
+ content;
1630
+ authorId;
1631
+ author;
1632
+ createdAt;
1633
+ constructor(client, data) {
1634
+ this.client = client;
1635
+ this.id = data.id;
1636
+ this.channelId = data.channelId;
1637
+ this.guildId = data.guildId ?? null;
1638
+ this.content = data.content ?? null;
1639
+ this.authorId = data.authorId ?? null;
1640
+ this.author = data.author ?? null;
1641
+ this.createdAt = data.createdAt ?? (import_util7.SnowflakeUtil.isValid(data.id) ? import_util7.SnowflakeUtil.dateFromSnowflake(data.id) : null);
1642
+ }
1643
+ /**
1644
+ * Live text-capable channel from cache, or null if uncached / not text-based.
1645
+ * Same contract as {@link Message.channel}.
1646
+ */
1647
+ get channel() {
1648
+ const channel = this.client.channels.get(this.channelId) ?? null;
1649
+ return channel?.isTextBased() ? channel : null;
1650
+ }
1651
+ /**
1652
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1653
+ * has {@link Channel.delete} and {@link Channel.send}.
1654
+ * @example
1655
+ * const channel = await message.resolveChannel();
1656
+ * await channel.delete();
1657
+ */
1658
+ async resolveChannel() {
1659
+ return this.client.channels.resolve(this.channelId);
1660
+ }
1661
+ /**
1662
+ * Fetch the full message from the API.
1663
+ * @example
1664
+ * const message = await partial.fetch();
1665
+ * await message.reply('Pong!');
1666
+ */
1667
+ async fetch() {
1668
+ return this.client.channels.fetchMessage(this.channelId, this.id);
1669
+ }
1670
+ };
1671
+
1672
+ // src/Domain/User.ts
1673
+ var import_types16 = require("@fluxerjs/types");
1674
+ var import_util14 = require("@fluxerjs/util");
1675
+
1676
+ // src/Domain/Channel/Base.ts
1677
+ var import_types8 = require("@fluxerjs/types");
1678
+ var import_util8 = require("@fluxerjs/util");
1679
+
1255
1680
  // src/ClientCore/MessageManager.ts
1681
+ var import_collection4 = require("@fluxerjs/collection");
1682
+ var import_types6 = require("@fluxerjs/types");
1256
1683
  var BULK = {
1257
1684
  requests: { min: 1, max: 25 },
1258
1685
  limit: { min: 1, max: 25 },
@@ -1286,19 +1713,40 @@ var MessageManager = class {
1286
1713
  this.client = client;
1287
1714
  this.channelId = channelId;
1288
1715
  }
1716
+ /** Structure cache keyed by message id (identity for {@link get}). */
1717
+ _structures = new import_collection4.Collection();
1289
1718
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
1290
1719
  get(messageId) {
1291
1720
  const data = this.client._getMessageCache(this.channelId)?.get(messageId);
1292
- return data ? new Message(this.client, data) : void 0;
1721
+ if (!data) {
1722
+ this._structures.delete(messageId);
1723
+ return void 0;
1724
+ }
1725
+ const existing = this._structures.get(messageId);
1726
+ if (existing) return existing;
1727
+ const message = new Message(this.client, data);
1728
+ this._structures.set(messageId, message);
1729
+ return message;
1730
+ }
1731
+ /** Retrieve from cache, otherwise {@link fetch}. */
1732
+ async resolve(messageId) {
1733
+ return this.get(messageId) ?? this.fetch(messageId);
1293
1734
  }
1294
1735
  async fetch(idOrOptions) {
1295
1736
  return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
1296
1737
  }
1297
- /** Cache API data and return a {@link Message} built from the cached entry when present. */
1738
+ /** Cache API data and return a {@link Message} (reusing identity when present). */
1298
1739
  wrap(data) {
1299
1740
  this.client._addMessageToCache(this.channelId, data);
1300
1741
  const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
1301
- return new Message(this.client, cached);
1742
+ const existing = this._structures.get(data.id);
1743
+ if (existing) {
1744
+ existing._patch(cached);
1745
+ return existing;
1746
+ }
1747
+ const message = new Message(this.client, cached);
1748
+ this._structures.set(data.id, message);
1749
+ return message;
1302
1750
  }
1303
1751
  /** Fetch a single message from the API. */
1304
1752
  async fetchOne(messageId) {
@@ -1331,12 +1779,110 @@ var MessageManager = class {
1331
1779
  }
1332
1780
  const base = import_types6.Routes.channelMessages(this.channelId);
1333
1781
  const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
1334
- const collection = new import_collection3.Collection();
1782
+ const collection = new import_collection4.Collection();
1335
1783
  for (const msg of data) collection.set(msg.id, this.wrap(msg));
1336
1784
  return collection;
1337
1785
  }
1338
1786
  };
1339
1787
 
1788
+ // src/Helpers/MessageCollector.ts
1789
+ var import_node_events2 = require("events");
1790
+ var import_collection5 = require("@fluxerjs/collection");
1791
+ function requireCollectorBounds(options) {
1792
+ const time = options.time ?? 0;
1793
+ const max = options.max ?? 0;
1794
+ if (time <= 0 && max <= 0) {
1795
+ throw new import_util2.FluxerError("MessageCollector requires `time` and/or `max`", {
1796
+ code: import_util.ErrorCodes.CollectorOptionsRequired
1797
+ });
1798
+ }
1799
+ }
1800
+ var MessageCollector = class _MessageCollector extends import_node_events2.EventEmitter {
1801
+ client;
1802
+ channelId;
1803
+ options;
1804
+ collected = new import_collection5.Collection();
1805
+ _timeout = null;
1806
+ _ended = false;
1807
+ _listener;
1808
+ constructor(client, channelId, options = {}) {
1809
+ super();
1810
+ requireCollectorBounds(options);
1811
+ this.client = client;
1812
+ this.channelId = channelId;
1813
+ this.options = {
1814
+ filter: options.filter ?? (() => true),
1815
+ time: options.time ?? 0,
1816
+ max: options.max ?? 0
1817
+ };
1818
+ this._listener = (message) => {
1819
+ if (this._ended || message.channelId !== this.channelId) return;
1820
+ if (!this.options.filter(message)) return;
1821
+ this.collected.set(message.id, message);
1822
+ this.emit("collect", message);
1823
+ if (this.options.max > 0 && this.collected.size >= this.options.max) {
1824
+ this.stop("limit");
1825
+ }
1826
+ };
1827
+ this.client.on(Events.MessageCreate, this._listener);
1828
+ if (this.options.time > 0) {
1829
+ this._timeout = setTimeout(() => this.stop("time"), this.options.time);
1830
+ }
1831
+ }
1832
+ stop(reason = "user") {
1833
+ if (this._ended) return;
1834
+ this._ended = true;
1835
+ this.client.off(Events.MessageCreate, this._listener);
1836
+ if (this._timeout) {
1837
+ clearTimeout(this._timeout);
1838
+ this._timeout = null;
1839
+ }
1840
+ this.emit("end", this.collected, reason);
1841
+ }
1842
+ /**
1843
+ * One-shot helper used by {@link Channel.awaitMessages}.
1844
+ * Resolves with the collected messages when the collector ends for `user` (or when
1845
+ * the end reason is not listed in `errors`).
1846
+ * By default, `time` and `limit` reject with {@link FluxerError}
1847
+ * (`CollectorIdle` / `CollectorMax`).
1848
+ */
1849
+ static awaitMessages(client, channelId, options) {
1850
+ const errors = options?.errors ?? ["time", "limit"];
1851
+ return new Promise((resolve, reject) => {
1852
+ const collector = new _MessageCollector(client, channelId, options);
1853
+ collector.on("end", (collected, reason) => {
1854
+ if (!errors.includes(reason)) {
1855
+ resolve(collected);
1856
+ return;
1857
+ }
1858
+ if (reason === "time") {
1859
+ reject(
1860
+ new import_util2.FluxerError("Message collector timed out", {
1861
+ code: import_util.ErrorCodes.CollectorIdle
1862
+ })
1863
+ );
1864
+ return;
1865
+ }
1866
+ if (reason === "limit") {
1867
+ reject(
1868
+ new import_util2.FluxerError("Message collector reached max", {
1869
+ code: import_util.ErrorCodes.CollectorMax
1870
+ })
1871
+ );
1872
+ return;
1873
+ }
1874
+ reject(collected);
1875
+ });
1876
+ });
1877
+ }
1878
+ on(event, listener) {
1879
+ return super.on(event, listener);
1880
+ }
1881
+ emit(event, ...args) {
1882
+ return super.emit(event, ...args);
1883
+ }
1884
+ };
1885
+
1340
1886
  // src/Domain/Channel/Attachments.ts
1341
1887
  var import_types7 = require("@fluxerjs/types");
1342
1888
  function asBytes(data) {
@@ -1415,6 +1961,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1415
1961
 
1416
1962
  // src/Domain/Channel/Base.ts
1417
1963
  var Channel = class extends Base {
1964
+ #messages;
1418
1965
  /** The {@link Client} that instantiated this channel. */
1419
1966
  client;
1420
1967
  /** Snowflake ID of this channel. */
@@ -1438,11 +1985,11 @@ var Channel = class extends Base {
1438
1985
  }
1439
1986
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
1440
1987
  get createdTimestamp() {
1441
- return import_util5.SnowflakeUtil.timestampFromSnowflake(this.id);
1988
+ return import_util8.SnowflakeUtil.timestampFromSnowflake(this.id);
1442
1989
  }
1443
1990
  /** Date when this channel was created, derived from its snowflake ID. */
1444
1991
  get createdAt() {
1445
- return import_util5.SnowflakeUtil.dateFromSnowflake(this.id);
1992
+ return import_util8.SnowflakeUtil.dateFromSnowflake(this.id);
1446
1993
  }
1447
1994
  /**
1448
1995
  * Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
@@ -1456,19 +2003,36 @@ var Channel = class extends Base {
1456
2003
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1457
2004
  }
1458
2005
  }
1459
- /** Wired in `structures/channel/index.ts` after subclasses load. */
2006
+ /** @internal Factory wired after subclasses load. */
1460
2007
  static from(_c, _d) {
1461
2008
  throw new Error("Channel.from not initialized");
1462
2009
  }
2010
+ /** @internal Factory wired after subclasses load. */
1463
2011
  static fromOrCreate(_c, _d) {
1464
2012
  throw new Error("Channel.fromOrCreate not initialized");
1465
2013
  }
2014
+ /** @internal Factory wired after subclasses load. */
1466
2015
  static createDM(_c, _d) {
1467
2016
  throw new Error("Channel.createDM not initialized");
1468
2017
  }
1469
- /** Check if this channel supports sending messages (text/DM). */
2018
+ /**
2019
+ * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
2020
+ * Checks {@link ChannelType}, not whether `send` exists on the instance.
2021
+ */
1470
2022
  isTextBased() {
1471
- return "send" in this;
2023
+ return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
2024
+ }
2025
+ /** Check if this is a guild channel (text, voice, category, or link). */
2026
+ isGuild() {
2027
+ return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.GuildCategory || this.type === import_types8.ChannelType.GuildLink;
2028
+ }
2029
+ /** Check if this is a guild text channel. */
2030
+ isText() {
2031
+ return this.type === import_types8.ChannelType.GuildText;
2032
+ }
2033
+ /** Check if this is a category channel. */
2034
+ isCategory() {
2035
+ return this.type === import_types8.ChannelType.GuildCategory;
1472
2036
  }
1473
2037
  /** Check if this is a DM, group DM, or personal notes channel. */
1474
2038
  isDM() {
@@ -1480,11 +2044,11 @@ var Channel = class extends Base {
1480
2044
  }
1481
2045
  /** Check if this is a voice channel. */
1482
2046
  isVoice() {
1483
- return "bitrate" in this;
2047
+ return this.type === import_types8.ChannelType.GuildVoice;
1484
2048
  }
1485
2049
  /** Check if this is a link channel. */
1486
2050
  isLink() {
1487
- return "url" in this;
2051
+ return this.type === import_types8.ChannelType.GuildLink;
1488
2052
  }
1489
2053
  /**
1490
2054
  * Delete recent messages or an explicit ID list.
@@ -1523,7 +2087,7 @@ var Channel = class extends Base {
1523
2087
  for (const id of ids) this.client._removeMessageFromCache(this.id, id);
1524
2088
  return ids;
1525
2089
  }
1526
- /** Delete all messages sent by the bot in this channel (user account feature). */
2090
+ /** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
1527
2091
  async bulkDeleteMyMessages(options) {
1528
2092
  const body = options ? toSudoBody(options) : void 0;
1529
2093
  await this.client.rest.post(import_types8.Routes.channelBulkDeleteMine(this.id), {
@@ -1531,11 +2095,17 @@ var Channel = class extends Base {
1531
2095
  auth: true
1532
2096
  });
1533
2097
  }
1534
- /** Mark all pinned messages as read in this channel. */
2098
+ /**
2099
+ * Mark all pinned messages as read in this channel.
2100
+ * Session-token helper; bots usually skip this.
2101
+ */
1535
2102
  async acknowledgePins() {
1536
2103
  await this.client.rest.post(import_types8.Routes.channelPinsAck(this.id), { auth: true });
1537
2104
  }
1538
- /** Clear the read state for this channel. */
2105
+ /**
2106
+ * Clear the read state for this channel.
2107
+ * Session-token helper; bots usually skip this.
2108
+ */
1539
2109
  async clearReadState() {
1540
2110
  await this.client.rest.delete(import_types8.Routes.channelMessagesAck(this.id), { auth: true });
1541
2111
  }
@@ -1571,7 +2141,11 @@ var Channel = class extends Base {
1571
2141
  async sendTyping() {
1572
2142
  await this.client.rest.post(import_types8.Routes.channelTyping(this.id), { auth: true });
1573
2143
  }
1574
- /** Fetch available RTC regions for voice channels. */
2144
+ /**
2145
+ * Fetch available RTC regions for voice channels.
2146
+ * User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
2147
+ * Bots should skip this and join voice with `@fluxerjs/voice` instead.
2148
+ */
1575
2149
  async fetchRtcRegions() {
1576
2150
  const data = await this.client.rest.get(import_types8.Routes.channelRtcRegions(this.id), {
1577
2151
  auth: true
@@ -1586,75 +2160,69 @@ var Channel = class extends Base {
1586
2160
  );
1587
2161
  return {
1588
2162
  rateLimitPerUser: data.rate_limit_per_user,
1589
- retryAfterMs: data.retry_after_ms,
1590
- nextSendAllowedAt: data.next_send_allowed_at
1591
- };
1592
- }
1593
- /** Check if the bot can send messages in this channel. */
1594
- canSendMessage() {
1595
- return this.isDM();
1596
- }
1597
- };
1598
-
1599
- // src/Domain/Channel/Dm.ts
1600
- var import_types10 = require("@fluxerjs/types");
1601
-
1602
- // src/Domain/Channel/TextCapable.ts
1603
- var import_types9 = require("@fluxerjs/types");
1604
-
1605
- // src/Helpers/MessageCollector.ts
1606
- var import_node_events2 = require("events");
1607
- var import_collection4 = require("@fluxerjs/collection");
1608
- var MessageCollector = class extends import_node_events2.EventEmitter {
1609
- client;
1610
- channelId;
1611
- options;
1612
- collected = new import_collection4.Collection();
1613
- _timeout = null;
1614
- _ended = false;
1615
- _listener;
1616
- constructor(client, channelId, options = {}) {
1617
- super();
1618
- this.client = client;
1619
- this.channelId = channelId;
1620
- this.options = {
1621
- filter: options.filter ?? (() => true),
1622
- time: options.time ?? 0,
1623
- max: options.max ?? 0
1624
- };
1625
- this._listener = (message) => {
1626
- if (this._ended || message.channelId !== this.channelId) return;
1627
- if (!this.options.filter(message)) return;
1628
- this.collected.set(message.id, message);
1629
- this.emit("collect", message);
1630
- if (this.options.max > 0 && this.collected.size >= this.options.max) {
1631
- this.stop("limit");
1632
- }
2163
+ retryAfterMs: data.retry_after_ms,
2164
+ nextSendAllowedAt: data.next_send_allowed_at
1633
2165
  };
1634
- this.client.on(Events.MessageCreate, this._listener);
1635
- if (this.options.time > 0) {
1636
- this._timeout = setTimeout(() => this.stop("time"), this.options.time);
1637
- }
1638
2166
  }
1639
- stop(reason = "user") {
1640
- if (this._ended) return;
1641
- this._ended = true;
1642
- this.client.off(Events.MessageCreate, this._listener);
1643
- if (this._timeout) {
1644
- clearTimeout(this._timeout);
1645
- this._timeout = null;
2167
+ /** Whether this channel type can carry messages (does not check permissions). */
2168
+ canSendMessage() {
2169
+ return this.isTextBased();
2170
+ }
2171
+ /** Per-channel message cache + fetch. */
2172
+ get messages() {
2173
+ if (!this.#messages) {
2174
+ this.#messages = new MessageManager(this.client, this.id);
1646
2175
  }
1647
- this.emit("end", this.collected, reason);
2176
+ return this.#messages;
1648
2177
  }
1649
- on(event, listener) {
1650
- return super.on(event, listener);
2178
+ /** Collect messages in this channel until time/max/stop. */
2179
+ createMessageCollector(options) {
2180
+ return new MessageCollector(this.client, this.id, options);
1651
2181
  }
1652
- emit(event, ...args) {
1653
- return super.emit(event, ...args);
2182
+ /**
2183
+ * Wait for messages matching the filter, then resolve the collected set.
2184
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
2185
+ * @example
2186
+ * const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
2187
+ */
2188
+ awaitMessages(options) {
2189
+ return MessageCollector.awaitMessages(this.client, this.id, options);
2190
+ }
2191
+ /**
2192
+ * Delete this channel (or close it if it is a DM).
2193
+ * Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
2194
+ * @example
2195
+ * const channel = await client.channels.fetch(channelId);
2196
+ * await channel.delete();
2197
+ */
2198
+ async delete(options) {
2199
+ const params = new URLSearchParams();
2200
+ if (options?.silent) params.set("silent", "true");
2201
+ if (options?.deleteMessages) params.set("delete_messages", "true");
2202
+ const qs2 = params.toString();
2203
+ const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2204
+ const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2205
+ await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2206
+ body,
2207
+ auth: true
2208
+ });
2209
+ this.client.channels.delete(this.id);
2210
+ this.client._clearMessageCache(this.id);
2211
+ if (this.isGuild() && this.guildId) {
2212
+ this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2213
+ }
2214
+ }
2215
+ /** Channel mention (`<#id>`). */
2216
+ toString() {
2217
+ return `<#${this.id}>`;
1654
2218
  }
1655
2219
  };
1656
2220
 
2221
+ // src/Domain/Channel/Dm.ts
2222
+ var import_types10 = require("@fluxerjs/types");
2223
+
1657
2224
  // src/Domain/Channel/TextCapable.ts
2225
+ var import_types9 = require("@fluxerjs/types");
1658
2226
  async function fetchPinnedMessagesPageFor(client, channelId, options) {
1659
2227
  const params = new URLSearchParams();
1660
2228
  if (options?.limit != null) params.set("limit", String(options.limit));
@@ -1672,27 +2240,19 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
1672
2240
  }
1673
2241
  function TextCapable(Base2) {
1674
2242
  class TextCapableChannel extends Base2 {
1675
- #messages;
2243
+ /**
2244
+ * Send a message in this channel.
2245
+ * @example
2246
+ * await channel.send('hi');
2247
+ */
1676
2248
  async send(options) {
1677
- const payload = await prepareMessagePostPayload(options, {
1678
- defaultAllowedMentions: this.client.options.defaultAllowedMentions
1679
- });
1680
- const data = await this.client.rest.post(import_types9.Routes.channelMessages(this.id), payload);
1681
- this.client._addMessageToCache(this.id, data);
1682
- return new Message(this.client, data);
1683
- }
1684
- get messages() {
1685
- if (!this.#messages) {
1686
- this.#messages = new MessageManager(this.client, this.id);
1687
- }
1688
- return this.#messages;
1689
- }
1690
- createMessageCollector(options) {
1691
- return new MessageCollector(this.client, this.id, options);
2249
+ return this.client.channels.send(this.id, options);
1692
2250
  }
2251
+ /** Fetch pinned messages in this channel. */
1693
2252
  async fetchPinnedMessages(options) {
1694
2253
  return (await this.fetchPinnedMessagesPage(options)).messages;
1695
2254
  }
2255
+ /** Fetch a page of pinned messages plus pagination metadata. */
1696
2256
  async fetchPinnedMessagesPage(options) {
1697
2257
  return fetchPinnedMessagesPageFor(this.client, this.id, options);
1698
2258
  }
@@ -1718,7 +2278,38 @@ var DMChannel = class extends TextCapable(Channel) {
1718
2278
  this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
1719
2279
  this.nicks = full.nicks ?? {};
1720
2280
  }
1721
- /** Purge all messages from personal notes. Only works on personal notes channels. */
2281
+ /**
2282
+ * Apply DM/group-DM fields in place.
2283
+ * @internal
2284
+ */
2285
+ _patch(data) {
2286
+ super._patch(data);
2287
+ const full = data;
2288
+ if ("last_message_id" in full && full.last_message_id !== void 0) {
2289
+ this.lastMessageId = full.last_message_id ?? null;
2290
+ }
2291
+ if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2292
+ if ("recipients" in full && full.recipients !== void 0) {
2293
+ this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2294
+ }
2295
+ if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2296
+ }
2297
+ /**
2298
+ * Edit this group DM (name, icon, nicks).
2299
+ * Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
2300
+ */
2301
+ async edit(options) {
2302
+ const data = await this.client.rest.patch(import_types10.Routes.channel(this.id), {
2303
+ body: toGroupDmEditBody(options),
2304
+ auth: true
2305
+ });
2306
+ this._patch(data);
2307
+ return this;
2308
+ }
2309
+ /**
2310
+ * Purge all messages from personal notes. Only works on personal notes channels.
2311
+ * Notes-only; bots usually skip this.
2312
+ */
1722
2313
  async purgeMessages() {
1723
2314
  if (this.type !== import_types10.ChannelType.DMPersonalNotes) {
1724
2315
  throw new import_util2.FluxerError("purgeMessages is only available on personal notes channels", {
@@ -1731,15 +2322,24 @@ var DMChannel = class extends TextCapable(Channel) {
1731
2322
  );
1732
2323
  return data.deleted_count;
1733
2324
  }
1734
- /** Pin this DM channel to the top of the DM list. */
2325
+ /**
2326
+ * Pin this DM channel to the top of the DM list.
2327
+ * Session-token helper; bots usually skip this.
2328
+ */
1735
2329
  async pinInList() {
1736
2330
  await this.client.rest.put(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
1737
2331
  }
1738
- /** Unpin this DM channel from the DM list. */
2332
+ /**
2333
+ * Unpin this DM channel from the DM list.
2334
+ * Session-token helper; bots usually skip this.
2335
+ */
1739
2336
  async unpinFromList() {
1740
2337
  await this.client.rest.delete(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
1741
2338
  }
1742
- /** Add a user to this group DM. */
2339
+ /**
2340
+ * Add a user to this group DM.
2341
+ * Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
2342
+ */
1743
2343
  async addRecipient(userId) {
1744
2344
  await this.client.rest.put(import_types10.Routes.channelRecipient(this.id, userId), { auth: true });
1745
2345
  const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
@@ -1755,14 +2355,14 @@ var DMChannel = class extends TextCapable(Channel) {
1755
2355
  };
1756
2356
 
1757
2357
  // src/Domain/Channel/Guild.ts
1758
- var import_types13 = require("@fluxerjs/types");
1759
- var import_util8 = require("@fluxerjs/util");
2358
+ var import_types14 = require("@fluxerjs/types");
2359
+ var import_util13 = require("@fluxerjs/util");
1760
2360
 
1761
2361
  // src/Domain/Invite.ts
1762
2362
  var import_types11 = require("@fluxerjs/types");
1763
2363
 
1764
2364
  // src/Helpers/Instance.ts
1765
- var import_util6 = require("@fluxerjs/util");
2365
+ var import_util9 = require("@fluxerjs/util");
1766
2366
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
1767
2367
  api: "https://api.fluxer.app",
1768
2368
  api_client: "https://web.fluxer.app/api",
@@ -1806,7 +2406,7 @@ function normalizeInviteBase(invite) {
1806
2406
  return invite.trim().replace(/\/+$/, "");
1807
2407
  }
1808
2408
  function parseInstanceDiscovery(raw) {
1809
- if (!(0, import_util6.isRecord)(raw)) {
2409
+ if (!(0, import_util9.isRecord)(raw)) {
1810
2410
  throw new import_util2.FluxerError("Invalid instance discovery: expected an object", {
1811
2411
  code: import_util.ErrorCodes.InvalidInstanceDiscovery
1812
2412
  });
@@ -1816,7 +2416,7 @@ function parseInstanceDiscovery(raw) {
1816
2416
  code: import_util.ErrorCodes.InvalidInstanceDiscovery
1817
2417
  });
1818
2418
  }
1819
- if (!(0, import_util6.isRecord)(raw.endpoints)) {
2419
+ if (!(0, import_util9.isRecord)(raw.endpoints)) {
1820
2420
  throw new import_util2.FluxerError("Invalid instance discovery: endpoints must be an object", {
1821
2421
  code: import_util.ErrorCodes.InvalidInstanceDiscovery
1822
2422
  });
@@ -1886,7 +2486,7 @@ function resolveInstanceEndpoints(input) {
1886
2486
  discovery: null
1887
2487
  });
1888
2488
  }
1889
- const isFull = "endpoints" in input && (0, import_util6.isRecord)(input.endpoints) && typeof input.api_code_version === "number";
2489
+ const isFull = "endpoints" in input && (0, import_util9.isRecord)(input.endpoints) && typeof input.api_code_version === "number";
1890
2490
  if (isFull) {
1891
2491
  const discovery = parseInstanceDiscovery(input);
1892
2492
  return Object.freeze({
@@ -1953,13 +2553,36 @@ function parseInviteCode(codeOrUrl) {
1953
2553
  }
1954
2554
  return code;
1955
2555
  }
2556
+ function parseOptionalDate(value) {
2557
+ if (value == null || value === "") return null;
2558
+ const date = new Date(value);
2559
+ return Number.isNaN(date.getTime()) ? null : date;
2560
+ }
2561
+ function toInviteGuild(data) {
2562
+ return {
2563
+ id: data.id,
2564
+ name: data.name,
2565
+ icon: data.icon ?? null,
2566
+ banner: data.banner ?? null,
2567
+ splash: data.splash ?? null,
2568
+ features: data.features ?? []
2569
+ };
2570
+ }
2571
+ function toInviteChannel(data) {
2572
+ return {
2573
+ id: data.id,
2574
+ name: data.name ?? null,
2575
+ type: data.type,
2576
+ icon: data.icon ?? null,
2577
+ parentId: data.parent_id ?? null
2578
+ };
2579
+ }
1956
2580
  var Invite = class _Invite extends Base {
1957
2581
  client;
1958
2582
  code;
1959
2583
  type;
1960
- guild;
1961
- channel;
1962
- pack;
2584
+ guildSnapshot;
2585
+ channelSnapshot;
1963
2586
  inviter;
1964
2587
  memberCount;
1965
2588
  presenceCount;
@@ -1974,15 +2597,14 @@ var Invite = class _Invite extends Base {
1974
2597
  this.client = client;
1975
2598
  this.code = data.code;
1976
2599
  this.type = data.type;
1977
- this.guild = (0, import_types11.isGuildInvite)(data) ? data.guild : null;
1978
- this.channel = (0, import_types11.isGuildInvite)(data) || (0, import_types11.isGroupDmInvite)(data) ? data.channel : null;
1979
- this.pack = (0, import_types11.isPackInvite)(data) ? data.pack : null;
2600
+ this.guildSnapshot = (0, import_types11.isGuildInvite)(data) ? toInviteGuild(data.guild) : null;
2601
+ this.channelSnapshot = (0, import_types11.isGuildInvite)(data) || (0, import_types11.isGroupDmInvite)(data) ? toInviteChannel(data.channel) : null;
1980
2602
  this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
1981
- this.memberCount = (0, import_types11.isPackInvite)(data) ? null : data.member_count ?? null;
2603
+ this.memberCount = data.member_count ?? null;
1982
2604
  this.presenceCount = (0, import_types11.isGuildInvite)(data) ? data.presence_count ?? null : null;
1983
- this.expiresAt = data.expires_at ?? null;
2605
+ this.expiresAt = parseOptionalDate(data.expires_at);
1984
2606
  this.temporary = data.temporary ?? null;
1985
- this.createdAt = data.created_at ?? null;
2607
+ this.createdAt = parseOptionalDate(data.created_at);
1986
2608
  this.uses = data.uses ?? null;
1987
2609
  this.maxUses = data.max_uses ?? null;
1988
2610
  this.maxAge = data.max_age ?? null;
@@ -1993,16 +2615,25 @@ var Invite = class _Invite extends Base {
1993
2615
  isGroupDM() {
1994
2616
  return this.type === import_types11.InviteType.GroupDM;
1995
2617
  }
1996
- isPack() {
1997
- return this.type === import_types11.InviteType.EmojiPack || this.type === import_types11.InviteType.StickerPack;
1998
- }
1999
2618
  /** Full invite URL (uses this client's instance invite base). */
2000
2619
  get url() {
2001
2620
  return inviteUrl(this.client.instance.endpoints.invite, this.code);
2002
2621
  }
2003
- /** Cached guild for guild invites, else null. */
2004
- getGuild() {
2005
- return this.guild?.id ? this.client.guilds.get(this.guild.id) ?? null : null;
2622
+ /**
2623
+ * Resolve the cached/fetched {@link Guild} for this invite, or null.
2624
+ * `guildSnapshot` is metadata only.
2625
+ */
2626
+ async resolveGuild() {
2627
+ if (!this.guildSnapshot?.id) return null;
2628
+ return this.client.guilds.resolve(this.guildSnapshot.id);
2629
+ }
2630
+ /**
2631
+ * Resolve the cached/fetched {@link Channel} for this invite, or null.
2632
+ * `channelSnapshot` is metadata only.
2633
+ */
2634
+ async resolveChannel() {
2635
+ if (!this.channelSnapshot?.id) return null;
2636
+ return this.client.channels.resolve(this.channelSnapshot.id);
2006
2637
  }
2007
2638
  /** Fetch invite metadata by code or URL (does not join). */
2008
2639
  static async fetch(client, codeOrUrl) {
@@ -2018,7 +2649,7 @@ var Invite = class _Invite extends Base {
2018
2649
  // src/Domain/Webhook.ts
2019
2650
  var import_builders4 = require("@fluxerjs/builders");
2020
2651
  var import_types12 = require("@fluxerjs/types");
2021
- var import_util7 = require("@fluxerjs/util");
2652
+ var import_util10 = require("@fluxerjs/util");
2022
2653
  var Webhook = class _Webhook extends Base {
2023
2654
  /** Parent client instance. */
2024
2655
  client;
@@ -2055,11 +2686,11 @@ var Webhook = class _Webhook extends Base {
2055
2686
  }
2056
2687
  /** Unix timestamp (ms) when this webhook was created, derived from its snowflake ID. */
2057
2688
  get createdTimestamp() {
2058
- return import_util7.SnowflakeUtil.timestampFromSnowflake(this.id);
2689
+ return import_util10.SnowflakeUtil.timestampFromSnowflake(this.id);
2059
2690
  }
2060
2691
  /** Date when this webhook was created, derived from its snowflake ID. */
2061
2692
  get createdAt() {
2062
- return import_util7.SnowflakeUtil.dateFromSnowflake(this.id);
2693
+ return import_util10.SnowflakeUtil.dateFromSnowflake(this.id);
2063
2694
  }
2064
2695
  /** Delete this webhook (token auth when available, otherwise bot auth). */
2065
2696
  async delete() {
@@ -2181,9 +2812,103 @@ var Webhook = class _Webhook extends Base {
2181
2812
  }
2182
2813
  };
2183
2814
 
2815
+ // src/Domain/Channel/PermissionOverwriteManager.ts
2816
+ var import_collection6 = require("@fluxerjs/collection");
2817
+ var import_types13 = require("@fluxerjs/types");
2818
+ var import_util12 = require("@fluxerjs/util");
2819
+
2820
+ // src/Domain/Channel/PermissionOverwrite.ts
2821
+ var import_util11 = require("@fluxerjs/util");
2822
+ var PermissionOverwrite = class {
2823
+ id;
2824
+ type;
2825
+ /** @internal Raw allow bitfield string. */
2826
+ _allow;
2827
+ /** @internal Raw deny bitfield string. */
2828
+ _deny;
2829
+ constructor(data) {
2830
+ this.id = data.id;
2831
+ this.type = data.type;
2832
+ this._allow = data.allow ?? "0";
2833
+ this._deny = data.deny ?? "0";
2834
+ }
2835
+ /** Allowed permissions for this overwrite. */
2836
+ get allow() {
2837
+ return new import_util11.PermissionsBitField(BigInt(this._allow || "0"));
2838
+ }
2839
+ /** Denied permissions for this overwrite. */
2840
+ get deny() {
2841
+ return new import_util11.PermissionsBitField(BigInt(this._deny || "0"));
2842
+ }
2843
+ /** Wire shape for permission computation / REST. */
2844
+ toJSON() {
2845
+ return {
2846
+ id: this.id,
2847
+ type: this.type,
2848
+ allow: this._allow,
2849
+ deny: this._deny
2850
+ };
2851
+ }
2852
+ };
2853
+
2854
+ // src/Domain/Channel/PermissionOverwriteManager.ts
2855
+ var PermissionOverwriteManager = class {
2856
+ constructor(channel, initial = []) {
2857
+ this.channel = channel;
2858
+ this._patch(initial);
2859
+ }
2860
+ _cache = new import_collection6.Collection();
2861
+ /** Cached overwrites keyed by role/member ID. */
2862
+ get cache() {
2863
+ return this._cache;
2864
+ }
2865
+ get size() {
2866
+ return this._cache.size;
2867
+ }
2868
+ [Symbol.iterator]() {
2869
+ return this._cache.values();
2870
+ }
2871
+ /** Wire-shaped overwrites for permission computation. */
2872
+ toJSON() {
2873
+ return [...this._cache.values()].map((o) => o.toJSON());
2874
+ }
2875
+ /** Edit or create a permission overwrite. */
2876
+ async edit(overwriteId, options) {
2877
+ const allow = options.allow !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.allow) : "0";
2878
+ const deny = options.deny !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.deny) : "0";
2879
+ await this.channel.client.rest.put(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
2880
+ body: { type: options.type, allow, deny },
2881
+ auth: true
2882
+ });
2883
+ this._cache.set(
2884
+ overwriteId,
2885
+ new PermissionOverwrite({
2886
+ id: overwriteId,
2887
+ type: options.type,
2888
+ allow,
2889
+ deny
2890
+ })
2891
+ );
2892
+ }
2893
+ /** Delete a permission overwrite. */
2894
+ async delete(overwriteId) {
2895
+ await this.channel.client.rest.delete(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
2896
+ auth: true
2897
+ });
2898
+ this._cache.delete(overwriteId);
2899
+ }
2900
+ /** @internal Sync from an API channel payload. */
2901
+ _patch(overwrites) {
2902
+ this._cache.clear();
2903
+ for (const entry of overwrites ?? []) {
2904
+ this._cache.set(entry.id, new PermissionOverwrite(entry));
2905
+ }
2906
+ }
2907
+ };
2908
+
2184
2909
  // src/Domain/Channel/Guild.ts
2185
2910
  var GuildChannel = class extends Channel {
2186
- /** Guild ID this channel belongs to. */
2911
+ /** Guild ID this channel belongs to, or null if missing from the payload. */
2187
2912
  guildId;
2188
2913
  /** Position in the channel list. */
2189
2914
  position;
@@ -2193,11 +2918,14 @@ var GuildChannel = class extends Channel {
2193
2918
  permissionOverwrites;
2194
2919
  constructor(client, data) {
2195
2920
  super(client, data);
2196
- this.guildId = data.guild_id ?? "";
2921
+ this.guildId = data.guild_id ?? null;
2197
2922
  this.name = data.name ?? null;
2198
2923
  this.position = data.position;
2199
2924
  this.parentId = data.parent_id ?? null;
2200
- this.permissionOverwrites = data.permission_overwrites ?? [];
2925
+ this.permissionOverwrites = new PermissionOverwriteManager(
2926
+ this,
2927
+ data.permission_overwrites ?? []
2928
+ );
2201
2929
  }
2202
2930
  /**
2203
2931
  * Apply guild-channel fields in place.
@@ -2209,13 +2937,13 @@ var GuildChannel = class extends Channel {
2209
2937
  if (data.position !== void 0) this.position = data.position;
2210
2938
  if (data.parent_id !== void 0) this.parentId = data.parent_id ?? null;
2211
2939
  if (data.permission_overwrites !== void 0) {
2212
- this.permissionOverwrites = data.permission_overwrites ?? [];
2940
+ this.permissionOverwrites._patch(data.permission_overwrites ?? []);
2213
2941
  }
2214
2942
  this.applyEditPatch(data);
2215
2943
  }
2216
2944
  /** Create a webhook for this channel. Requires Manage Webhooks. */
2217
2945
  async createWebhook(options) {
2218
- const data = await this.client.rest.post(import_types13.Routes.channelWebhooks(this.id), {
2946
+ const data = await this.client.rest.post(import_types14.Routes.channelWebhooks(this.id), {
2219
2947
  body: options,
2220
2948
  auth: true
2221
2949
  });
@@ -2223,13 +2951,13 @@ var GuildChannel = class extends Channel {
2223
2951
  }
2224
2952
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
2225
2953
  async fetchWebhooks() {
2226
- const data = await this.client.rest.get(import_types13.Routes.channelWebhooks(this.id));
2954
+ const data = await this.client.rest.get(import_types14.Routes.channelWebhooks(this.id));
2227
2955
  return data.map((w) => new Webhook(this.client, w));
2228
2956
  }
2229
2957
  /** Create an invite for this channel. Requires Create Instant Invite. */
2230
2958
  async createInvite(options) {
2231
2959
  const body = options ? toChannelInviteBody(options) : {};
2232
- const data = await this.client.rest.post(import_types13.Routes.channelInvites(this.id), {
2960
+ const data = await this.client.rest.post(import_types14.Routes.channelInvites(this.id), {
2233
2961
  body: Object.keys(body).length ? body : void 0,
2234
2962
  auth: true
2235
2963
  });
@@ -2237,109 +2965,160 @@ var GuildChannel = class extends Channel {
2237
2965
  }
2238
2966
  /** Fetch all invites for this channel. Requires Manage Channels. */
2239
2967
  async fetchInvites() {
2240
- const data = await this.client.rest.get(import_types13.Routes.channelInvites(this.id));
2968
+ const data = await this.client.rest.get(import_types14.Routes.channelInvites(this.id));
2241
2969
  return data.map((i) => new Invite(this.client, i));
2242
2970
  }
2243
- /** Edit or create a permission overwrite. Requires Manage Roles. */
2244
- async editPermission(overwriteId, options) {
2245
- await this.client.rest.put(import_types13.Routes.channelPermission(this.id, overwriteId), {
2246
- body: options,
2247
- auth: true
2248
- });
2249
- const entry = {
2250
- id: overwriteId,
2251
- type: options.type,
2252
- allow: options.allow ?? "0",
2253
- deny: options.deny ?? "0"
2254
- };
2255
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2256
- if (idx >= 0) this.permissionOverwrites[idx] = entry;
2257
- else this.permissionOverwrites.push(entry);
2258
- }
2259
- /** Delete a permission overwrite. Requires Manage Roles. */
2260
- async deletePermission(overwriteId) {
2261
- await this.client.rest.delete(import_types13.Routes.channelPermission(this.id, overwriteId), { auth: true });
2262
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2263
- if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
2264
- }
2265
- /** Check if the bot can send messages in this channel (with permissions). */
2971
+ /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
2266
2972
  canSendMessage() {
2973
+ if (!this.guildId) return false;
2267
2974
  const me = this.client.guilds.get(this.guildId)?.members.me;
2268
2975
  if (!me) return false;
2269
2976
  const perms = me.permissionsIn(this);
2270
- return perms.has(import_util8.PermissionFlags.ViewChannel) && perms.has(import_util8.PermissionFlags.SendMessages);
2977
+ return perms.has(import_util13.PermissionFlags.ViewChannel) && perms.has(import_util13.PermissionFlags.SendMessages);
2978
+ }
2979
+ /**
2980
+ * Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
2981
+ * Returns false when the channel has no guildId.
2982
+ */
2983
+ async canSend() {
2984
+ if (!this.guildId) return false;
2985
+ const guild = this.client.guilds.get(this.guildId);
2986
+ if (!guild) return false;
2987
+ if (!guild.members.me) {
2988
+ try {
2989
+ await guild.members.fetchMe();
2990
+ } catch {
2991
+ return false;
2992
+ }
2993
+ }
2994
+ return this.canSendMessage();
2271
2995
  }
2272
2996
  /** Edit this channel's settings. Requires Manage Channels. */
2273
2997
  async edit(options) {
2274
- const data = await this.client.rest.patch(import_types13.Routes.channel(this.id), {
2998
+ const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
2275
2999
  body: toChannelEditBody(options),
2276
3000
  auth: true
2277
3001
  });
2278
3002
  this.name = data.name ?? this.name;
2279
3003
  this.parentId = data.parent_id ?? this.parentId;
2280
- this.permissionOverwrites = data.permission_overwrites ?? this.permissionOverwrites;
3004
+ if (data.permission_overwrites !== void 0) {
3005
+ this.permissionOverwrites._patch(data.permission_overwrites);
3006
+ }
2281
3007
  this.applyEditPatch(data);
2282
3008
  return this;
2283
3009
  }
2284
3010
  applyEditPatch(_data) {
2285
3011
  }
2286
- /** Delete this channel. Requires Manage Channels or channel ownership. */
2287
- async delete(options) {
2288
- const params = new URLSearchParams();
2289
- if (options?.silent) params.set("silent", "true");
2290
- if (options?.deleteMessages) params.set("delete_messages", "true");
2291
- const qs2 = params.toString();
2292
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2293
- const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2294
- await this.client.rest.delete(import_types13.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2295
- body,
2296
- auth: true
2297
- });
2298
- this.client.channels.delete(this.id);
2299
- this.client._clearMessageCache(this.id);
2300
- this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2301
- }
2302
3012
  };
2303
3013
  var TextChannel = class extends TextCapable(GuildChannel) {
2304
3014
  /** Channel topic. */
2305
3015
  topic;
2306
3016
  /** Whether this channel is marked as NSFW. */
2307
3017
  nsfw;
3018
+ /** Per-channel NSFW override (`null` inherits). */
3019
+ nsfwOverride;
2308
3020
  /** Slowmode rate limit in seconds. */
2309
3021
  rateLimitPerUser;
2310
3022
  /** ID of the last message sent in this channel. */
2311
3023
  lastMessageId;
3024
+ /** Content warning level. */
3025
+ contentWarningLevel;
3026
+ /** Custom content warning text. */
3027
+ contentWarningText;
2312
3028
  constructor(client, data) {
2313
3029
  super(client, data);
2314
3030
  this.topic = data.topic ?? null;
2315
3031
  this.nsfw = data.nsfw ?? false;
3032
+ this.nsfwOverride = data.nsfw_override ?? null;
2316
3033
  this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
2317
3034
  this.lastMessageId = data.last_message_id ?? null;
3035
+ this.contentWarningLevel = data.content_warning_level ?? null;
3036
+ this.contentWarningText = data.content_warning_text ?? null;
3037
+ }
3038
+ /**
3039
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3040
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3041
+ */
3042
+ async setSlowmode(seconds) {
3043
+ return this.edit({ rateLimitPerUser: seconds });
2318
3044
  }
2319
3045
  applyEditPatch(data) {
2320
3046
  if ("topic" in data) this.topic = data.topic ?? null;
2321
3047
  if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3048
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
2322
3049
  if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3050
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3051
+ if ("content_warning_level" in data) {
3052
+ this.contentWarningLevel = data.content_warning_level ?? null;
3053
+ }
3054
+ if ("content_warning_text" in data) {
3055
+ this.contentWarningText = data.content_warning_text ?? null;
3056
+ }
2323
3057
  }
2324
3058
  };
2325
3059
  var CategoryChannel = class extends GuildChannel {
2326
3060
  };
2327
- var VoiceChannel = class extends GuildChannel {
3061
+ var VoiceChannel = class extends TextCapable(GuildChannel) {
3062
+ /** Channel topic. */
3063
+ topic;
3064
+ /** Whether this channel is marked as NSFW. */
3065
+ nsfw;
3066
+ /** Per-channel NSFW override (`null` inherits). */
3067
+ nsfwOverride;
3068
+ /** Slowmode rate limit in seconds. */
3069
+ rateLimitPerUser;
3070
+ /** ID of the last message sent in this channel. */
3071
+ lastMessageId;
3072
+ /** Content warning level. */
3073
+ contentWarningLevel;
3074
+ /** Custom content warning text. */
3075
+ contentWarningText;
2328
3076
  /** Voice bitrate. */
2329
3077
  bitrate;
2330
3078
  /** Maximum number of users allowed. */
2331
3079
  userLimit;
3080
+ /** Max active voice connections per user. */
3081
+ voiceConnectionLimit;
2332
3082
  /** RTC region override for this channel. */
2333
3083
  rtcRegion;
2334
3084
  constructor(client, data) {
2335
3085
  super(client, data);
3086
+ this.topic = data.topic ?? null;
3087
+ this.nsfw = data.nsfw ?? false;
3088
+ this.nsfwOverride = data.nsfw_override ?? null;
3089
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3090
+ this.lastMessageId = data.last_message_id ?? null;
3091
+ this.contentWarningLevel = data.content_warning_level ?? null;
3092
+ this.contentWarningText = data.content_warning_text ?? null;
2336
3093
  this.bitrate = data.bitrate ?? null;
2337
3094
  this.userLimit = data.user_limit ?? null;
3095
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
2338
3096
  this.rtcRegion = data.rtc_region ?? null;
2339
3097
  }
3098
+ /**
3099
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3100
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3101
+ */
3102
+ async setSlowmode(seconds) {
3103
+ return this.edit({ rateLimitPerUser: seconds });
3104
+ }
2340
3105
  applyEditPatch(data) {
3106
+ if ("topic" in data) this.topic = data.topic ?? null;
3107
+ if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3108
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
3109
+ if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3110
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3111
+ if ("content_warning_level" in data) {
3112
+ this.contentWarningLevel = data.content_warning_level ?? null;
3113
+ }
3114
+ if ("content_warning_text" in data) {
3115
+ this.contentWarningText = data.content_warning_text ?? null;
3116
+ }
2341
3117
  if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
2342
3118
  if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
3119
+ if ("voice_connection_limit" in data) {
3120
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3121
+ }
2343
3122
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
2344
3123
  }
2345
3124
  };
@@ -2350,20 +3129,23 @@ var LinkChannel = class extends GuildChannel {
2350
3129
  super(client, data);
2351
3130
  this.url = data.url ?? null;
2352
3131
  }
3132
+ applyEditPatch(data) {
3133
+ if ("url" in data) this.url = data.url ?? null;
3134
+ }
2353
3135
  };
2354
3136
 
2355
3137
  // src/Domain/Channel/Factory.ts
2356
- var import_types14 = require("@fluxerjs/types");
3138
+ var import_types15 = require("@fluxerjs/types");
2357
3139
  var GUILD_FACTORIES = {
2358
- [import_types14.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
2359
- [import_types14.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
2360
- [import_types14.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
2361
- [import_types14.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
3140
+ [import_types15.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
3141
+ [import_types15.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3142
+ [import_types15.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
3143
+ [import_types15.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
2362
3144
  };
2363
3145
  var DM_TYPES = /* @__PURE__ */ new Set([
2364
- import_types14.ChannelType.DM,
2365
- import_types14.ChannelType.GroupDM,
2366
- import_types14.ChannelType.DMPersonalNotes
3146
+ import_types15.ChannelType.DM,
3147
+ import_types15.ChannelType.GroupDM,
3148
+ import_types15.ChannelType.DMPersonalNotes
2367
3149
  ]);
2368
3150
  function createDM(client, data) {
2369
3151
  return new DMChannel(client, data);
@@ -2465,11 +3247,11 @@ var User = class extends Base {
2465
3247
  */
2466
3248
  /** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
2467
3249
  get createdTimestamp() {
2468
- return import_util9.SnowflakeUtil.timestampFromSnowflake(this.id);
3250
+ return import_util14.SnowflakeUtil.timestampFromSnowflake(this.id);
2469
3251
  }
2470
3252
  /** Date when this account was created, derived from its snowflake ID. */
2471
3253
  get createdAt() {
2472
- return import_util9.SnowflakeUtil.dateFromSnowflake(this.id);
3254
+ return import_util14.SnowflakeUtil.dateFromSnowflake(this.id);
2473
3255
  }
2474
3256
  toString() {
2475
3257
  return `<@${this.id}>`;
@@ -2479,7 +3261,7 @@ var User = class extends Base {
2479
3261
  * @returns DM channel instance (cached if already open)
2480
3262
  */
2481
3263
  async createDM() {
2482
- const data = await this.client.rest.post(import_types15.Routes.userMeChannels(), {
3264
+ const data = await this.client.rest.post(import_types16.Routes.userMeChannels(), {
2483
3265
  body: { recipient_id: this.id },
2484
3266
  auth: true
2485
3267
  });
@@ -2594,6 +3376,9 @@ var CacheController = class {
2594
3376
  stickers
2595
3377
  };
2596
3378
  }
3379
+ /**
3380
+ * Sweep cached messages. Filter receives a hydrated {@link Message} (`createdAt`).
3381
+ */
2597
3382
  sweepMessages(filter, channelId) {
2598
3383
  return this.client.sweepMessages(filter, channelId);
2599
3384
  }
@@ -2662,7 +3447,7 @@ var CacheController = class {
2662
3447
  * @internal
2663
3448
  */
2664
3449
  cascadeChannel(channel, from = "both") {
2665
- const guildId = "guildId" in channel && typeof channel.guildId === "string" ? channel.guildId : void 0;
3450
+ const guildId = typeof channel.isGuild === "function" && channel.isGuild() ? channel.guildId : void 0;
2666
3451
  const dropFromGuild = () => {
2667
3452
  if (!guildId) return;
2668
3453
  const guildChannels = this.client.guilds.get(guildId)?.channels;
@@ -2692,12 +3477,12 @@ var CacheController = class {
2692
3477
  };
2693
3478
 
2694
3479
  // src/ClientCore/ChannelManager.ts
2695
- var import_collection6 = require("@fluxerjs/collection");
2696
- var import_types22 = require("@fluxerjs/types");
3480
+ var import_collection8 = require("@fluxerjs/collection");
3481
+ var import_types23 = require("@fluxerjs/types");
2697
3482
 
2698
3483
  // src/Domain/Guild/GuildEmoji.ts
2699
- var import_types16 = require("@fluxerjs/types");
2700
- var import_util10 = require("@fluxerjs/util");
3484
+ var import_types17 = require("@fluxerjs/types");
3485
+ var import_util15 = require("@fluxerjs/util");
2701
3486
  var GuildEmoji = class extends Base {
2702
3487
  client;
2703
3488
  id;
@@ -2733,11 +3518,11 @@ var GuildEmoji = class extends Base {
2733
3518
  }
2734
3519
  /** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
2735
3520
  get createdTimestamp() {
2736
- return import_util10.SnowflakeUtil.timestampFromSnowflake(this.id);
3521
+ return import_util15.SnowflakeUtil.timestampFromSnowflake(this.id);
2737
3522
  }
2738
3523
  /** Date when this emoji was created, derived from its snowflake ID. */
2739
3524
  get createdAt() {
2740
- return import_util10.SnowflakeUtil.dateFromSnowflake(this.id);
3525
+ return import_util15.SnowflakeUtil.dateFromSnowflake(this.id);
2741
3526
  }
2742
3527
  /** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
2743
3528
  toString() {
@@ -2745,7 +3530,7 @@ var GuildEmoji = class extends Base {
2745
3530
  }
2746
3531
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
2747
3532
  async delete() {
2748
- await this.client.rest.delete(import_types16.Routes.guildEmoji(this.guildId, this.id), {
3533
+ await this.client.rest.delete(import_types17.Routes.guildEmoji(this.guildId, this.id), {
2749
3534
  auth: true
2750
3535
  });
2751
3536
  const guild = this.client.guilds.get(this.guildId);
@@ -2756,7 +3541,7 @@ var GuildEmoji = class extends Base {
2756
3541
  * Requires Manage Emojis and Stickers permission.
2757
3542
  */
2758
3543
  async edit(options) {
2759
- const data = await this.client.rest.patch(import_types16.Routes.guildEmoji(this.guildId, this.id), {
3544
+ const data = await this.client.rest.patch(import_types17.Routes.guildEmoji(this.guildId, this.id), {
2760
3545
  body: options,
2761
3546
  auth: true
2762
3547
  });
@@ -2766,28 +3551,28 @@ var GuildEmoji = class extends Base {
2766
3551
  };
2767
3552
 
2768
3553
  // src/Domain/Guild/GuildMember.ts
2769
- var import_types19 = require("@fluxerjs/types");
2770
- var import_util12 = require("@fluxerjs/util");
3554
+ var import_types20 = require("@fluxerjs/types");
3555
+ var import_util17 = require("@fluxerjs/util");
2771
3556
 
2772
3557
  // src/Helpers/Permissions.ts
2773
- var import_types17 = require("@fluxerjs/types");
2774
- var import_util11 = require("@fluxerjs/util");
3558
+ var import_types18 = require("@fluxerjs/types");
3559
+ var import_util16 = require("@fluxerjs/util");
2775
3560
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
2776
- if (isOwner) return import_util11.ALL_PERMISSIONS_BIGINT;
3561
+ if (isOwner) return import_util16.ALL_PERMISSIONS_BIGINT;
2777
3562
  let perms = basePermissions;
2778
3563
  for (const overwrite of overwrites ?? []) {
2779
- const applies = overwrite.type === import_types17.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types17.OverwriteType.Member && overwrite.id === memberId;
3564
+ const applies = overwrite.type === import_types18.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types18.OverwriteType.Member && overwrite.id === memberId;
2780
3565
  if (!applies) continue;
2781
3566
  const allow = BigInt(overwrite.allow || "0");
2782
3567
  const deny = BigInt(overwrite.deny || "0");
2783
3568
  perms = perms & ~deny | allow;
2784
3569
  }
2785
- return (perms & import_util11.PermissionFlags.Administrator) !== 0n ? import_util11.ALL_PERMISSIONS_BIGINT : perms;
3570
+ return (perms & import_util16.PermissionFlags.Administrator) !== 0n ? import_util16.ALL_PERMISSIONS_BIGINT : perms;
2786
3571
  }
2787
3572
 
2788
3573
  // src/Domain/Guild/GuildMemberRoleManager.ts
2789
- var import_collection5 = require("@fluxerjs/collection");
2790
- var import_types18 = require("@fluxerjs/types");
3574
+ var import_collection7 = require("@fluxerjs/collection");
3575
+ var import_types19 = require("@fluxerjs/types");
2791
3576
  function roleId(roleOrId) {
2792
3577
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
2793
3578
  }
@@ -2805,7 +3590,7 @@ var GuildMemberRoleManager = class {
2805
3590
  }
2806
3591
  /** Live Role objects from `guild.roles` for this member's role IDs. */
2807
3592
  get cache() {
2808
- const out = new import_collection5.Collection();
3593
+ const out = new import_collection7.Collection();
2809
3594
  for (const id of this.ids) {
2810
3595
  const role = this.member.guild.roles.get(id);
2811
3596
  if (role) out.set(id, role);
@@ -2816,7 +3601,7 @@ var GuildMemberRoleManager = class {
2816
3601
  const id = roleId(roleOrId);
2817
3602
  if (this.ids.includes(id)) return;
2818
3603
  await this.member.client.rest.put(
2819
- import_types18.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
3604
+ import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
2820
3605
  );
2821
3606
  this.ids.push(id);
2822
3607
  }
@@ -2825,13 +3610,13 @@ var GuildMemberRoleManager = class {
2825
3610
  const idx = this.ids.indexOf(id);
2826
3611
  if (idx === -1) return;
2827
3612
  await this.member.client.rest.delete(
2828
- import_types18.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
3613
+ import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
2829
3614
  );
2830
3615
  this.ids.splice(idx, 1);
2831
3616
  }
2832
3617
  async set(roleIds) {
2833
3618
  const data = await this.member.client.rest.patch(
2834
- import_types18.Routes.guildMember(this.member.guild.id, this.member.id),
3619
+ import_types19.Routes.guildMember(this.member.guild.id, this.member.id),
2835
3620
  { body: { roles: roleIds }, auth: true }
2836
3621
  );
2837
3622
  this.ids = data.roles ? [...data.roles] : [];
@@ -2844,6 +3629,8 @@ var GuildMemberRoleManager = class {
2844
3629
 
2845
3630
  // src/Domain/Guild/GuildMember.ts
2846
3631
  var GuildMember = class _GuildMember extends Base {
3632
+ /** Discriminant vs {@link PartialGuildMember}: always `false` on a hydrated member. */
3633
+ partial = false;
2847
3634
  /** Parent client instance. */
2848
3635
  client;
2849
3636
  /** User ID (same as `user.id`). */
@@ -2872,6 +3659,12 @@ var GuildMember = class _GuildMember extends Base {
2872
3659
  accentColor;
2873
3660
  /** Guild-specific profile flags. */
2874
3661
  profileFlags;
3662
+ /** Per-guild reply mention preference override. */
3663
+ mentionFlags;
3664
+ /** Guild-specific bio (set from member edit; not always on GET member). */
3665
+ bio;
3666
+ /** Guild-specific pronouns (set from member edit; not always on GET member). */
3667
+ pronouns;
2875
3668
  constructor(client, data, guild) {
2876
3669
  super();
2877
3670
  this.client = client;
@@ -2888,6 +3681,9 @@ var GuildMember = class _GuildMember extends Base {
2888
3681
  this.banner = data.banner ?? null;
2889
3682
  this.accentColor = data.accent_color ?? null;
2890
3683
  this.profileFlags = data.profile_flags ?? null;
3684
+ this.mentionFlags = data.mention_flags ?? null;
3685
+ this.bio = data.bio ?? null;
3686
+ this.pronouns = data.pronouns ?? null;
2891
3687
  }
2892
3688
  /**
2893
3689
  * Apply an API member payload in place (gateway GUILD_MEMBER_UPDATE / REST edit).
@@ -2906,6 +3702,9 @@ var GuildMember = class _GuildMember extends Base {
2906
3702
  if (data.banner !== void 0) this.banner = data.banner ?? null;
2907
3703
  if (data.accent_color !== void 0) this.accentColor = data.accent_color ?? null;
2908
3704
  if (data.profile_flags !== void 0) this.profileFlags = data.profile_flags ?? null;
3705
+ if (data.mention_flags !== void 0) this.mentionFlags = data.mention_flags ?? null;
3706
+ if (data.bio !== void 0) this.bio = data.bio ?? null;
3707
+ if (data.pronouns !== void 0) this.pronouns = data.pronouns ?? null;
2909
3708
  }
2910
3709
  /**
2911
3710
  * Snapshot for `guildMemberUpdate` old-member arg (before in-place patch).
@@ -2934,7 +3733,10 @@ var GuildMember = class _GuildMember extends Base {
2934
3733
  avatar: this.avatar,
2935
3734
  banner: this.banner,
2936
3735
  accent_color: this.accentColor,
2937
- profile_flags: this.profileFlags ?? void 0
3736
+ profile_flags: this.profileFlags ?? void 0,
3737
+ mention_flags: this.mentionFlags,
3738
+ bio: this.bio,
3739
+ pronouns: this.pronouns
2938
3740
  },
2939
3741
  this.guild
2940
3742
  );
@@ -2961,41 +3763,105 @@ var GuildMember = class _GuildMember extends Base {
2961
3763
  mediaBase: this.client.instance.endpoints.media
2962
3764
  });
2963
3765
  }
2964
- /** PATCH member (`/members/@me` when editing the bot). */
3766
+ /**
3767
+ * PATCH member (`/members/@me` when editing the bot).
3768
+ * @example
3769
+ * await member.edit({ nick: 'Ada' });
3770
+ */
2965
3771
  async edit(options) {
2966
3772
  const isMe = this.client.user?.id === this.id;
2967
- const route = isMe ? import_types19.Routes.guildMemberMe(this.guild.id) : import_types19.Routes.guildMember(this.guild.id, this.id);
3773
+ const route = isMe ? import_types20.Routes.guildMemberMe(this.guild.id) : import_types20.Routes.guildMember(this.guild.id, this.id);
2968
3774
  const data = await this.client.rest.patch(route, {
2969
3775
  body: toMemberEditBody(options),
2970
3776
  auth: true
2971
3777
  });
2972
3778
  this._patch(data);
3779
+ if (options.bio !== void 0) this.bio = options.bio;
3780
+ if (options.pronouns !== void 0) this.pronouns = options.pronouns;
3781
+ if (options.mentionFlags !== void 0) this.mentionFlags = options.mentionFlags;
2973
3782
  return this;
2974
3783
  }
2975
3784
  /**
2976
3785
  * Guild-level permissions (roles only, no channel overwrites).
2977
3786
  * @see {@link permissionsIn} for channel-specific permissions
2978
3787
  */
2979
- get permissions() {
2980
- return new import_util12.PermissionsBitField(this._effectivePermissions([], []));
3788
+ get permissions() {
3789
+ return new import_util17.PermissionsBitField(this._effectivePermissions([], []));
3790
+ }
3791
+ /**
3792
+ * Effective permissions in a channel (roles + overwrites).
3793
+ * @param channel - The guild channel
3794
+ * @returns Computed permissions bitfield
3795
+ */
3796
+ permissionsIn(channel) {
3797
+ return new import_util17.PermissionsBitField(
3798
+ this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
3799
+ );
3800
+ }
3801
+ /**
3802
+ * Move to a voice channel, or `null` to disconnect. Requires Move Members.
3803
+ * @param channelId - Voice channel ID or null to disconnect
3804
+ * @param connectionId - Optional connection ID for multi-session scenarios
3805
+ */
3806
+ async move(channelId, connectionId) {
3807
+ await this.edit({ channelId, connectionId });
3808
+ }
3809
+ /** Kick this member. Requires Kick Members. */
3810
+ async kick() {
3811
+ await this.guild.kick(this.id);
3812
+ }
3813
+ /** Ban this member. Requires Ban Members. */
3814
+ async ban(options) {
3815
+ await this.guild.ban(this.id, options);
3816
+ }
3817
+ /**
3818
+ * Whether the bot can kick this member (cache-only; needs `members.me`).
3819
+ * False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
3820
+ */
3821
+ get kickable() {
3822
+ return this._moderatableWith(import_util17.PermissionFlags.KickMembers);
3823
+ }
3824
+ /**
3825
+ * Whether the bot can ban this member (cache-only; needs `members.me`).
3826
+ */
3827
+ get bannable() {
3828
+ return this._moderatableWith(import_util17.PermissionFlags.BanMembers);
2981
3829
  }
2982
3830
  /**
2983
- * Effective permissions in a channel (roles + overwrites).
2984
- * @param channel - The guild channel
2985
- * @returns Computed permissions bitfield
3831
+ * Whether the bot can timeout this member (cache-only; needs `members.me`).
2986
3832
  */
2987
- permissionsIn(channel) {
2988
- return new import_util12.PermissionsBitField(
2989
- this._effectivePermissions(channel.permissionOverwrites, [...this.roles.roleIds])
2990
- );
3833
+ get moderatable() {
3834
+ return this._moderatableWith(import_util17.PermissionFlags.ModerateMembers);
3835
+ }
3836
+ _moderatableWith(flag) {
3837
+ const me = this.guild.members.me;
3838
+ if (!me) return false;
3839
+ if (this.id === me.id) return false;
3840
+ if (this.guild.ownerId != null && String(this.guild.ownerId) === String(this.id)) return false;
3841
+ if (!me.permissions.has(flag)) return false;
3842
+ return this._compareRolePosition(me) < 0;
3843
+ }
3844
+ /** Negative when this member's highest role is below `other`'s. */
3845
+ _compareRolePosition(other) {
3846
+ const highest = (m) => {
3847
+ let pos = -1;
3848
+ for (const role of m.roles.cache.values()) {
3849
+ if (role.position > pos) pos = role.position;
3850
+ }
3851
+ return pos;
3852
+ };
3853
+ return highest(this) - highest(other);
2991
3854
  }
2992
3855
  /**
2993
- * Move to a voice channel, or `null` to disconnect. Requires Move Members.
2994
- * @param channelId - Voice channel ID or null to disconnect
2995
- * @param connectionId - Optional connection ID for multi-session scenarios
3856
+ * Timeout this member for `durationMs` milliseconds, or pass `null` to clear.
3857
+ * Requires Moderate Members.
2996
3858
  */
2997
- async move(channelId, connectionId) {
2998
- await this.edit({ channelId, connectionId });
3859
+ async timeout(durationMs, reason) {
3860
+ const communicationDisabledUntil = durationMs == null || durationMs <= 0 ? null : new Date(Date.now() + durationMs).toISOString();
3861
+ return this.edit({
3862
+ communicationDisabledUntil,
3863
+ ...reason !== void 0 ? { timeoutReason: reason } : {}
3864
+ });
2999
3865
  }
3000
3866
  _effectivePermissions(overwrites, roleIds) {
3001
3867
  const ownerId = this.guild.ownerId;
@@ -3016,8 +3882,8 @@ var GuildMember = class _GuildMember extends Base {
3016
3882
  };
3017
3883
 
3018
3884
  // src/Domain/Guild/GuildSticker.ts
3019
- var import_types20 = require("@fluxerjs/types");
3020
- var import_util13 = require("@fluxerjs/util");
3885
+ var import_types21 = require("@fluxerjs/types");
3886
+ var import_util18 = require("@fluxerjs/util");
3021
3887
  var GuildSticker = class extends Base {
3022
3888
  client;
3023
3889
  id;
@@ -3059,15 +3925,15 @@ var GuildSticker = class extends Base {
3059
3925
  }
3060
3926
  /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
3061
3927
  get createdTimestamp() {
3062
- return import_util13.SnowflakeUtil.timestampFromSnowflake(this.id);
3928
+ return import_util18.SnowflakeUtil.timestampFromSnowflake(this.id);
3063
3929
  }
3064
3930
  /** Date when this sticker was created, derived from its snowflake ID. */
3065
3931
  get createdAt() {
3066
- return import_util13.SnowflakeUtil.dateFromSnowflake(this.id);
3932
+ return import_util18.SnowflakeUtil.dateFromSnowflake(this.id);
3067
3933
  }
3068
3934
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3069
3935
  async delete() {
3070
- await this.client.rest.delete(import_types20.Routes.guildSticker(this.guildId, this.id), {
3936
+ await this.client.rest.delete(import_types21.Routes.guildSticker(this.guildId, this.id), {
3071
3937
  auth: true
3072
3938
  });
3073
3939
  const guild = this.client.guilds.get(this.guildId);
@@ -3078,7 +3944,7 @@ var GuildSticker = class extends Base {
3078
3944
  * Requires Manage Emojis and Stickers permission.
3079
3945
  */
3080
3946
  async edit(options) {
3081
- const data = await this.client.rest.patch(import_types20.Routes.guildSticker(this.guildId, this.id), {
3947
+ const data = await this.client.rest.patch(import_types21.Routes.guildSticker(this.guildId, this.id), {
3082
3948
  body: options,
3083
3949
  auth: true
3084
3950
  });
@@ -3090,8 +3956,8 @@ var GuildSticker = class extends Base {
3090
3956
  };
3091
3957
 
3092
3958
  // src/Domain/Guild/Role.ts
3093
- var import_types21 = require("@fluxerjs/types");
3094
- var import_util14 = require("@fluxerjs/util");
3959
+ var import_types22 = require("@fluxerjs/types");
3960
+ var import_util19 = require("@fluxerjs/util");
3095
3961
  var Role = class _Role extends Base {
3096
3962
  /** Parent client instance. */
3097
3963
  client;
@@ -3134,21 +4000,29 @@ var Role = class _Role extends Base {
3134
4000
  */
3135
4001
  get permissions() {
3136
4002
  const bits = BigInt(this._permissions);
3137
- return new import_util14.PermissionsBitField(
3138
- (bits & import_util14.PermissionFlags.Administrator) !== 0n ? import_util14.ALL_PERMISSIONS_BIGINT : bits
4003
+ return new import_util19.PermissionsBitField(
4004
+ (bits & import_util19.PermissionFlags.Administrator) !== 0n ? import_util19.ALL_PERMISSIONS_BIGINT : bits
3139
4005
  );
3140
4006
  }
4007
+ /**
4008
+ * Alias of {@link permissions}.has for discord.js-style checks.
4009
+ * @example
4010
+ * if (role.has(PermissionFlags.BanMembers)) { ... }
4011
+ */
4012
+ has(permission) {
4013
+ return this.permissions.has(permission);
4014
+ }
3141
4015
  /**
3142
4016
  * Format as a mention string (`<@&id>`).
3143
4017
  * @returns Mention syntax
3144
4018
  */
3145
4019
  /** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
3146
4020
  get createdTimestamp() {
3147
- return import_util14.SnowflakeUtil.timestampFromSnowflake(this.id);
4021
+ return import_util19.SnowflakeUtil.timestampFromSnowflake(this.id);
3148
4022
  }
3149
4023
  /** Date when this role was created, derived from its snowflake ID. */
3150
4024
  get createdAt() {
3151
- return import_util14.SnowflakeUtil.dateFromSnowflake(this.id);
4025
+ return import_util19.SnowflakeUtil.dateFromSnowflake(this.id);
3152
4026
  }
3153
4027
  toString() {
3154
4028
  return `<@&${this.id}>`;
@@ -3191,8 +4065,8 @@ var Role = class _Role extends Base {
3191
4065
  * @returns This role instance (updated in-place)
3192
4066
  */
3193
4067
  async edit(options) {
3194
- const body = toRoleRequestBody(options);
3195
- const data = await this.client.rest.patch(import_types21.Routes.guildRole(this.guildId, this.id), {
4068
+ const body = toRoleEditBody(options);
4069
+ const data = await this.client.rest.patch(import_types22.Routes.guildRole(this.guildId, this.id), {
3196
4070
  body: Object.keys(body).length ? body : void 0,
3197
4071
  auth: true
3198
4072
  });
@@ -3203,7 +4077,7 @@ var Role = class _Role extends Base {
3203
4077
  * DELETE role. Requires Manage Roles.
3204
4078
  */
3205
4079
  async delete() {
3206
- await this.client.rest.delete(import_types21.Routes.guildRole(this.guildId, this.id), { auth: true });
4080
+ await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), { auth: true });
3207
4081
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
3208
4082
  }
3209
4083
  };
@@ -3211,17 +4085,15 @@ var Role = class _Role extends Base {
3211
4085
  // src/Domain/Guild/Cache.ts
3212
4086
  function putChannel(client, channel, guild) {
3213
4087
  client.channels.set(channel.id, channel);
3214
- const resolvedGuild = guild ?? (() => {
3215
- const guildId = "guildId" in channel ? channel.guildId : void 0;
3216
- return guildId ? client.guilds.get(guildId) : void 0;
3217
- })();
4088
+ if (!channel.isGuild()) return;
4089
+ const resolvedGuild = guild ?? (channel.guildId ? client.guilds.get(channel.guildId) : void 0);
3218
4090
  if (resolvedGuild) {
3219
4091
  resolvedGuild.channels.set(channel.id, channel);
3220
4092
  }
3221
4093
  }
3222
4094
  function cacheChannel(guild, data) {
3223
4095
  const existing = guild.channels.get(data.id) ?? guild.client.channels.get(data.id);
3224
- if (existing && "guildId" in existing && existing.type === data.type) {
4096
+ if (existing?.isGuild() && existing.type === data.type) {
3225
4097
  existing._patch(data);
3226
4098
  putChannel(guild.client, existing, guild);
3227
4099
  return existing;
@@ -3327,7 +4199,7 @@ function syncStickers(guild, stickers) {
3327
4199
  }
3328
4200
 
3329
4201
  // src/ClientCore/ChannelManager.ts
3330
- var ChannelManager = class extends import_collection6.LimitedCollection {
4202
+ var ChannelManager = class extends import_collection8.LimitedCollection {
3331
4203
  constructor(client) {
3332
4204
  super({
3333
4205
  maxSize: client.cache.limits.channels,
@@ -3335,6 +4207,10 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3335
4207
  });
3336
4208
  this.client = client;
3337
4209
  }
4210
+ /**
4211
+ * Remove a channel from cache. Does not delete it on the API.
4212
+ * Use {@link Channel.delete} after {@link fetch} to delete the channel.
4213
+ */
3338
4214
  delete(key) {
3339
4215
  const channel = this.get(key);
3340
4216
  const deleted = super.delete(key);
@@ -3348,15 +4224,20 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3348
4224
  return this.get(channelId) ?? this.fetch(channelId);
3349
4225
  }
3350
4226
  /**
3351
- * Fetch a channel by ID.
3352
- * Returns the cached channel unless `force` is set, in which case REST metadata is applied.
4227
+ * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
4228
+ * and {@link Channel.send} (send throws if the type is not text-based).
4229
+ * Returns the cached channel unless `force` is set.
4230
+ * @example
4231
+ * const channel = await client.channels.fetch(channelId);
4232
+ * await channel.delete();
4233
+ * await channel.send('hi');
3353
4234
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
3354
4235
  */
3355
4236
  async fetch(channelId, options) {
3356
4237
  const cached = this.get(channelId);
3357
4238
  if (cached && !options?.force) return cached;
3358
4239
  try {
3359
- const data = await this.client.rest.get(import_types22.Routes.channel(channelId));
4240
+ const data = await this.client.rest.get(import_types23.Routes.channel(channelId));
3360
4241
  const guildId = "guild_id" in data ? data.guild_id : void 0;
3361
4242
  if (guildId) {
3362
4243
  const guild = this.client.guilds.get(guildId);
@@ -3392,6 +4273,7 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3392
4273
  }
3393
4274
  /**
3394
4275
  * Send to a channel by ID without resolving it first.
4276
+ * Prefer {@link Channel.send} after {@link fetch} when you want the channel object.
3395
4277
  * @example
3396
4278
  * await client.channels.send(logChannelId, 'User joined!');
3397
4279
  */
@@ -3400,7 +4282,7 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3400
4282
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
3401
4283
  });
3402
4284
  const data = await this.client.rest.post(
3403
- import_types22.Routes.channelMessages(channelId),
4285
+ import_types23.Routes.channelMessages(channelId),
3404
4286
  postPayload
3405
4287
  );
3406
4288
  this.client._addMessageToCache(channelId, data);
@@ -3409,29 +4291,29 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3409
4291
  };
3410
4292
 
3411
4293
  // src/ClientCore/ClientEmoji.ts
3412
- var import_collection7 = require("@fluxerjs/collection");
3413
- var import_types23 = require("@fluxerjs/types");
3414
- var import_util15 = require("@fluxerjs/util");
4294
+ var import_collection9 = require("@fluxerjs/collection");
4295
+ var import_types24 = require("@fluxerjs/types");
4296
+ var import_util20 = require("@fluxerjs/util");
3415
4297
  async function resolveClientEmoji(client, emoji, guildId) {
3416
4298
  if (typeof emoji === "object" && emoji.id) {
3417
- return (0, import_util15.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
4299
+ return (0, import_util20.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
3418
4300
  }
3419
- const parsed = (0, import_util15.parseEmoji)(
4301
+ const parsed = (0, import_util20.parseEmoji)(
3420
4302
  typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
3421
4303
  );
3422
4304
  if (!parsed) {
3423
4305
  throw new import_util2.FluxerError("Invalid emoji", { code: import_util.ErrorCodes.InvalidEmoji });
3424
4306
  }
3425
4307
  if (parsed.id) {
3426
- return (0, import_util15.formatEmoji)(parsed);
4308
+ return (0, import_util20.formatEmoji)(parsed);
3427
4309
  }
3428
4310
  if (!/^\w+$/.test(parsed.name)) return parsed.name;
3429
- const unicodeFromShortcode = (0, import_util15.getUnicodeFromShortcode)(parsed.name);
4311
+ const unicodeFromShortcode = (0, import_util20.getUnicodeFromShortcode)(parsed.name);
3430
4312
  if (unicodeFromShortcode) return unicodeFromShortcode;
3431
4313
  if (guildId) {
3432
- const emojis = await client.rest.get(import_types23.Routes.guildEmojis(guildId));
4314
+ const emojis = await client.rest.get(import_types24.Routes.guildEmojis(guildId));
3433
4315
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
3434
- if (found) return (0, import_util15.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
4316
+ if (found) return (0, import_util20.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
3435
4317
  throw new import_util2.FluxerError(
3436
4318
  `Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format.`,
3437
4319
  { code: import_util.ErrorCodes.EmojiNotFound }
@@ -3446,28 +4328,31 @@ async function resolveClientEmoji(client, emoji, guildId) {
3446
4328
  return parsed.name;
3447
4329
  }
3448
4330
  async function fetchInstance(client) {
3449
- const raw = await client.rest.get(import_types23.Routes.instanceDiscovery(), { auth: false });
4331
+ const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), { auth: false });
3450
4332
  return parseInstanceDiscovery(raw);
3451
4333
  }
3452
4334
  function fetchGatewayInfo(client) {
3453
- return client.rest.get(import_types23.Routes.gatewayBot());
4335
+ return client.rest.get(import_types24.Routes.gatewayBot());
3454
4336
  }
3455
4337
  function fetchEmojiMetadata(client, emojiId) {
3456
- return client.rest.get(import_types23.Routes.emojiMetadata(emojiId), { auth: true });
4338
+ return client.rest.get(import_types24.Routes.emojiMetadata(emojiId), { auth: true });
3457
4339
  }
3458
4340
  function fetchStickerMetadata(client, stickerId) {
3459
- return client.rest.get(import_types23.Routes.stickerMetadata(stickerId), { auth: true });
4341
+ return client.rest.get(import_types24.Routes.stickerMetadata(stickerId), { auth: true });
3460
4342
  }
3461
4343
  function fetchApplication(client) {
3462
- return client.rest.get(import_types23.Routes.applicationsMe(), { auth: true });
4344
+ return client.rest.get(import_types24.Routes.applicationsMe(), { auth: true });
3463
4345
  }
3464
4346
  async function fetchOAuthApplications(client) {
3465
- const data = await client.rest.get(import_types23.Routes.oauth2ApplicationsMe(), { auth: true });
3466
- return Array.isArray(data) ? data : data.applications ?? [];
3467
- }
3468
- function checkUsernameTag(client, username, discriminator) {
3469
- const params = new URLSearchParams({ username, discriminator });
3470
- return client.rest.get(`${import_types23.Routes.checkUsernameTag()}?${params}`, { auth: true });
4347
+ const data = await client.rest.get(import_types24.Routes.oauth2ApplicationsMe(), { auth: true });
4348
+ if (Array.isArray(data)) return data;
4349
+ if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
4350
+ return data.applications;
4351
+ }
4352
+ if (data && typeof data === "object" && "id" in data && typeof data.id === "string") {
4353
+ return [data];
4354
+ }
4355
+ return [];
3471
4356
  }
3472
4357
  function assertChannelIdBatch(name, channelIds) {
3473
4358
  if (channelIds.length < 1 || channelIds.length > 100) {
@@ -3478,14 +4363,14 @@ function assertChannelIdBatch(name, channelIds) {
3478
4363
  }
3479
4364
  function preloadMessages(client, channelIds) {
3480
4365
  assertChannelIdBatch("preloadMessages", channelIds);
3481
- return client.rest.post(import_types23.Routes.preloadMessages(), {
4366
+ return client.rest.post(import_types24.Routes.preloadMessages(), {
3482
4367
  body: { channels: channelIds },
3483
4368
  auth: true
3484
4369
  });
3485
4370
  }
3486
4371
  function preloadMessagesAlt(client, channelIds) {
3487
4372
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
3488
- return client.rest.post(import_types23.Routes.preloadMessagesAlt(), {
4373
+ return client.rest.post(import_types24.Routes.preloadMessagesAlt(), {
3489
4374
  body: { channels: channelIds },
3490
4375
  auth: true
3491
4376
  });
@@ -3493,14 +4378,14 @@ function preloadMessagesAlt(client, channelIds) {
3493
4378
  async function bulkFetchMessages(client, requests, options = {}) {
3494
4379
  validateBulkMessageFetchRequests(requests);
3495
4380
  const wire = toBulkFetchWire(requests);
3496
- const data = await client.rest.post(import_types23.Routes.channelsMessagesBulk(), {
4381
+ const data = await client.rest.post(import_types24.Routes.channelsMessagesBulk(), {
3497
4382
  body: { requests: wire },
3498
4383
  auth: true
3499
4384
  });
3500
4385
  if (options.hydrate === false) return data;
3501
4386
  return {
3502
4387
  channels: data.channels.map((entry) => {
3503
- const collection = new import_collection7.Collection();
4388
+ const collection = new import_collection9.Collection();
3504
4389
  for (const msg of entry.messages) {
3505
4390
  client._addMessageToCache(entry.channel_id, msg);
3506
4391
  collection.set(msg.id, new Message(client, msg));
@@ -3509,6 +4394,13 @@ async function bulkFetchMessages(client, requests, options = {}) {
3509
4394
  })
3510
4395
  };
3511
4396
  }
4397
+ async function searchMessages(client, options = {}) {
4398
+ const data = await client.rest.post(import_types24.Routes.searchMessages(), {
4399
+ body: toMessageSearchBody(options),
4400
+ auth: true
4401
+ });
4402
+ return toMessageSearchResponse(data);
4403
+ }
3512
4404
 
3513
4405
  // src/ClientCore/ClientEvents.ts
3514
4406
  function createEventMethods(client) {
@@ -3527,14 +4419,14 @@ function createEventMethods(client) {
3527
4419
  var import_ws = require("@fluxerjs/ws");
3528
4420
 
3529
4421
  // src/Domain/Guild/Guild.ts
3530
- var import_collection9 = require("@fluxerjs/collection");
3531
- var import_types33 = require("@fluxerjs/types");
3532
- var import_util17 = require("@fluxerjs/util");
4422
+ var import_collection12 = require("@fluxerjs/collection");
4423
+ var import_types34 = require("@fluxerjs/types");
4424
+ var import_util22 = require("@fluxerjs/util");
3533
4425
 
3534
4426
  // src/ClientCore/GuildMemberManager.ts
3535
- var import_collection8 = require("@fluxerjs/collection");
3536
- var import_types24 = require("@fluxerjs/types");
3537
- var GuildMemberManager = class extends import_collection8.LimitedCollection {
4427
+ var import_collection10 = require("@fluxerjs/collection");
4428
+ var import_types25 = require("@fluxerjs/types");
4429
+ var GuildMemberManager = class extends import_collection10.LimitedCollection {
3538
4430
  constructor(guild) {
3539
4431
  super({ maxSize: guild.client.cache.limits.members });
3540
4432
  this.guild = guild;
@@ -3550,7 +4442,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3550
4442
  * console.log(member.displayName);
3551
4443
  */
3552
4444
  async resolve(userId) {
3553
- return this.get(userId) ?? this.guild.fetchMember(userId);
4445
+ return this.get(userId) ?? this.fetch(userId);
3554
4446
  }
3555
4447
  /**
3556
4448
  * The current bot user as a GuildMember in this guild.
@@ -3577,17 +4469,20 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3577
4469
  async fetchMe() {
3578
4470
  return this.guild.fetchMe();
3579
4471
  }
3580
- /**
3581
- * Fetch guild members with pagination. GET /guilds/{id}/members.
3582
- * @param options - limit (1-1000), after (user ID for pagination)
3583
- * @returns Array of GuildMember objects (cached in guild.members)
3584
- */
3585
- async fetch(options) {
4472
+ async fetch(userIdOrOptions, options) {
4473
+ if (typeof userIdOrOptions === "string") {
4474
+ const cached = this.get(userIdOrOptions);
4475
+ if (cached && !options?.force) return cached;
4476
+ return this.guild.fetchMember(userIdOrOptions);
4477
+ }
4478
+ return this.fetchMany(userIdOrOptions);
4479
+ }
4480
+ async fetchMany(options) {
3586
4481
  const params = new URLSearchParams();
3587
4482
  if (options?.limit != null) params.set("limit", String(options.limit));
3588
4483
  if (options?.after) params.set("after", options.after);
3589
4484
  const qs2 = params.toString();
3590
- const url = import_types24.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
4485
+ const url = import_types25.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
3591
4486
  const data = await this.guild.client.rest.get(url, { auth: true });
3592
4487
  const members = [];
3593
4488
  for (const m of data) {
@@ -3610,7 +4505,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3610
4505
  */
3611
4506
  async search(options = {}) {
3612
4507
  const data = await this.guild.client.rest.post(
3613
- import_types24.Routes.guildMembersSearch(this.guild.id),
4508
+ import_types25.Routes.guildMembersSearch(this.guild.id),
3614
4509
  { body: toMemberSearchBody(options), auth: true }
3615
4510
  );
3616
4511
  const offset = options.offset ?? 0;
@@ -3636,7 +4531,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3636
4531
  };
3637
4532
 
3638
4533
  // src/Domain/Guild/Admin.ts
3639
- var import_types25 = require("@fluxerjs/types");
4534
+ var import_types26 = require("@fluxerjs/types");
3640
4535
  function toAuditLogEntryPayload(entry, guildId) {
3641
4536
  return {
3642
4537
  id: entry.id,
@@ -3657,7 +4552,7 @@ function toVanityPayload(data) {
3657
4552
  return { code: data.code ?? null, uses: data.uses };
3658
4553
  }
3659
4554
  async function fetchAuditLogs(guild, options) {
3660
- const url = import_types25.Routes.guildAuditLogs(guild.id) + qs({
4555
+ const url = import_types26.Routes.guildAuditLogs(guild.id) + qs({
3661
4556
  limit: options?.limit,
3662
4557
  before: options?.before,
3663
4558
  after: options?.after,
@@ -3681,7 +4576,7 @@ async function fetchAuditLogs(guild, options) {
3681
4576
  };
3682
4577
  }
3683
4578
  async function editGuild(guild, options) {
3684
- const data = await guild.client.rest.patch(import_types25.Routes.guild(guild.id), {
4579
+ const data = await guild.client.rest.patch(import_types26.Routes.guild(guild.id), {
3685
4580
  body: toGuildEditBody(options),
3686
4581
  auth: true
3687
4582
  });
@@ -3689,13 +4584,13 @@ async function editGuild(guild, options) {
3689
4584
  return guild;
3690
4585
  }
3691
4586
  async function fetchVanityURL(guild) {
3692
- const data = await guild.client.rest.get(import_types25.Routes.guildVanityUrl(guild.id), {
4587
+ const data = await guild.client.rest.get(import_types26.Routes.guildVanityUrl(guild.id), {
3693
4588
  auth: true
3694
4589
  });
3695
4590
  return toVanityPayload(data);
3696
4591
  }
3697
4592
  async function editVanityURL(guild, code) {
3698
- const data = await guild.client.rest.patch(import_types25.Routes.guildVanityUrl(guild.id), {
4593
+ const data = await guild.client.rest.patch(import_types26.Routes.guildVanityUrl(guild.id), {
3699
4594
  body: { code },
3700
4595
  auth: true
3701
4596
  });
@@ -3703,14 +4598,14 @@ async function editVanityURL(guild, code) {
3703
4598
  return toVanityPayload(data);
3704
4599
  }
3705
4600
  async function fetchDiscoveryStatus(guild) {
3706
- const data = await guild.client.rest.get(import_types25.Routes.guildDiscovery(guild.id), {
4601
+ const data = await guild.client.rest.get(import_types26.Routes.guildDiscovery(guild.id), {
3707
4602
  auth: true
3708
4603
  });
3709
4604
  return toDiscoveryStatusPayload(data);
3710
4605
  }
3711
4606
  async function applyForDiscovery(guild, options) {
3712
4607
  const data = await guild.client.rest.post(
3713
- import_types25.Routes.guildDiscovery(guild.id),
4608
+ import_types26.Routes.guildDiscovery(guild.id),
3714
4609
  {
3715
4610
  body: toDiscoveryBody(options),
3716
4611
  auth: true
@@ -3720,7 +4615,7 @@ async function applyForDiscovery(guild, options) {
3720
4615
  }
3721
4616
  async function editDiscoveryApplication(guild, options) {
3722
4617
  const data = await guild.client.rest.patch(
3723
- import_types25.Routes.guildDiscovery(guild.id),
4618
+ import_types26.Routes.guildDiscovery(guild.id),
3724
4619
  {
3725
4620
  body: toDiscoveryBody(options),
3726
4621
  auth: true
@@ -3729,34 +4624,34 @@ async function editDiscoveryApplication(guild, options) {
3729
4624
  return toDiscoveryApplicationPayload(data);
3730
4625
  }
3731
4626
  async function withdrawDiscoveryApplication(guild) {
3732
- await guild.client.rest.delete(import_types25.Routes.guildDiscovery(guild.id), { auth: true });
4627
+ await guild.client.rest.delete(import_types26.Routes.guildDiscovery(guild.id), { auth: true });
3733
4628
  }
3734
4629
  async function deleteGuild(guild, options) {
3735
4630
  const body = options ? toSudoBody(options) : {};
3736
- await guild.client.rest.post(import_types25.Routes.guildDelete(guild.id), {
4631
+ await guild.client.rest.post(import_types26.Routes.guildDelete(guild.id), {
3737
4632
  body,
3738
4633
  auth: true
3739
4634
  });
3740
4635
  guild.client.guilds.delete(guild.id);
3741
4636
  }
3742
4637
  async function transferOwnership(guild, newOwnerId, password) {
3743
- await guild.client.rest.post(import_types25.Routes.guildTransferOwnership(guild.id), {
4638
+ await guild.client.rest.post(import_types26.Routes.guildTransferOwnership(guild.id), {
3744
4639
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
3745
4640
  auth: true
3746
4641
  });
3747
4642
  }
3748
4643
 
3749
4644
  // src/Domain/Guild/Channels.ts
3750
- var import_types26 = require("@fluxerjs/types");
3751
- async function createChannel(guild, data) {
3752
- const created = await guild.client.rest.post(import_types26.Routes.guildChannels(guild.id), {
3753
- body: data,
4645
+ var import_types27 = require("@fluxerjs/types");
4646
+ async function createChannel(guild, options) {
4647
+ const created = await guild.client.rest.post(import_types27.Routes.guildChannels(guild.id), {
4648
+ body: toChannelCreateBody(options),
3754
4649
  auth: true
3755
4650
  });
3756
4651
  return cacheChannel(guild, created);
3757
4652
  }
3758
4653
  async function fetchChannels(guild) {
3759
- const data = await guild.client.rest.get(import_types26.Routes.guildChannels(guild.id));
4654
+ const data = await guild.client.rest.get(import_types27.Routes.guildChannels(guild.id));
3760
4655
  const channels = [];
3761
4656
  for (const ch of data) {
3762
4657
  const channel = cacheChannel(guild, ch);
@@ -3765,17 +4660,17 @@ async function fetchChannels(guild) {
3765
4660
  return channels;
3766
4661
  }
3767
4662
  async function setChannelPositions(guild, updates) {
3768
- await guild.client.rest.patch(import_types26.Routes.guildChannels(guild.id), {
4663
+ await guild.client.rest.patch(import_types27.Routes.guildChannels(guild.id), {
3769
4664
  body: toChannelPositionBody(updates),
3770
4665
  auth: true
3771
4666
  });
3772
4667
  }
3773
4668
  async function fetchWebhooks(guild) {
3774
- const data = await guild.client.rest.get(import_types26.Routes.guildWebhooks(guild.id));
4669
+ const data = await guild.client.rest.get(import_types27.Routes.guildWebhooks(guild.id));
3775
4670
  return data.map((w) => new Webhook(guild.client, w));
3776
4671
  }
3777
4672
  async function fetchInvites(guild) {
3778
- const data = await guild.client.rest.get(import_types26.Routes.guildInvites(guild.id));
4673
+ const data = await guild.client.rest.get(import_types27.Routes.guildInvites(guild.id));
3779
4674
  return data.map((invite) => new Invite(guild.client, invite));
3780
4675
  }
3781
4676
  async function fetchInvite(guild, codeOrUrl) {
@@ -3795,14 +4690,14 @@ function resolveGuildOnlineCount(data) {
3795
4690
  }
3796
4691
 
3797
4692
  // src/Domain/Guild/Emojis.ts
3798
- var import_types27 = require("@fluxerjs/types");
4693
+ var import_types28 = require("@fluxerjs/types");
3799
4694
  async function fetchEmojis(guild) {
3800
- const data = await guild.client.rest.get(import_types27.Routes.guildEmojis(guild.id));
4695
+ const data = await guild.client.rest.get(import_types28.Routes.guildEmojis(guild.id));
3801
4696
  return data.map((e) => cacheEmoji(guild, e));
3802
4697
  }
3803
4698
  async function fetchEmoji(guild, emojiId) {
3804
4699
  try {
3805
- const data = await guild.client.rest.get(import_types27.Routes.guildEmoji(guild.id, emojiId));
4700
+ const data = await guild.client.rest.get(import_types28.Routes.guildEmoji(guild.id, emojiId));
3806
4701
  return cacheEmoji(guild, data);
3807
4702
  } catch (err) {
3808
4703
  rethrowMapped(err, {
@@ -3812,14 +4707,14 @@ async function fetchEmoji(guild, emojiId) {
3812
4707
  }
3813
4708
  }
3814
4709
  async function createEmoji(guild, options) {
3815
- const data = await guild.client.rest.post(import_types27.Routes.guildEmojis(guild.id), {
4710
+ const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
3816
4711
  body: options,
3817
4712
  auth: true
3818
4713
  });
3819
4714
  return cacheEmoji(guild, data);
3820
4715
  }
3821
4716
  async function cloneEmoji(guild, sourceEmojiId) {
3822
- const data = await guild.client.rest.post(import_types27.Routes.guildEmojisClone(guild.id), {
4717
+ const data = await guild.client.rest.post(import_types28.Routes.guildEmojisClone(guild.id), {
3823
4718
  body: { source_emoji_id: sourceEmojiId },
3824
4719
  auth: true
3825
4720
  });
@@ -3827,18 +4722,18 @@ async function cloneEmoji(guild, sourceEmojiId) {
3827
4722
  }
3828
4723
  async function createEmojisBulk(guild, emojis) {
3829
4724
  const data = await guild.client.rest.post(
3830
- import_types27.Routes.guildEmojisBulk(guild.id),
4725
+ import_types28.Routes.guildEmojisBulk(guild.id),
3831
4726
  { body: { emojis }, auth: true }
3832
4727
  );
3833
4728
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
3834
4729
  }
3835
4730
 
3836
4731
  // src/Domain/Guild/MemberHttp.ts
3837
- var import_types28 = require("@fluxerjs/types");
4732
+ var import_types29 = require("@fluxerjs/types");
3838
4733
  async function fetchMember(guild, userId) {
3839
4734
  try {
3840
4735
  const data = await guild.client.rest.get(
3841
- import_types28.Routes.guildMember(guild.id, userId)
4736
+ import_types29.Routes.guildMember(guild.id, userId)
3842
4737
  );
3843
4738
  return cacheMember(guild, data);
3844
4739
  } catch (err) {
@@ -3853,23 +4748,28 @@ async function fetchMember(guild, userId) {
3853
4748
  }
3854
4749
  async function fetchMe(guild) {
3855
4750
  const data = await guild.client.rest.get(
3856
- import_types28.Routes.guildMemberMe(guild.id),
4751
+ import_types29.Routes.guildMemberMe(guild.id),
3857
4752
  { auth: true }
3858
4753
  );
3859
4754
  return cacheMember(guild, data);
3860
4755
  }
3861
4756
 
3862
4757
  // src/Domain/Guild/Moderation.ts
3863
- var import_types30 = require("@fluxerjs/types");
4758
+ var import_types31 = require("@fluxerjs/types");
3864
4759
 
3865
4760
  // src/Domain/Guild/GuildBan.ts
3866
- var import_types29 = require("@fluxerjs/types");
4761
+ var import_types30 = require("@fluxerjs/types");
4762
+ function parseOptionalDate2(value) {
4763
+ if (value == null || value === "") return null;
4764
+ const date = new Date(value);
4765
+ return Number.isNaN(date.getTime()) ? null : date;
4766
+ }
3867
4767
  var GuildBan = class extends Base {
3868
4768
  client;
3869
4769
  guildId;
3870
4770
  user;
3871
4771
  reason;
3872
- /** ISO timestamp when a temporary ban expires. Null for permanent bans. */
4772
+ /** When a temporary ban expires. Null for permanent bans. */
3873
4773
  expiresAt;
3874
4774
  /** @param data - API ban from GET /guilds/{id}/bans or gateway GUILD_BAN_ADD */
3875
4775
  constructor(client, data, guildId) {
@@ -3878,14 +4778,14 @@ var GuildBan = class extends Base {
3878
4778
  this.guildId = data.guild_id ?? guildId;
3879
4779
  this.user = client.getOrCreateUser(data.user);
3880
4780
  this.reason = data.reason ?? null;
3881
- this.expiresAt = data.expires_at ?? null;
4781
+ this.expiresAt = parseOptionalDate2(data.expires_at);
3882
4782
  }
3883
4783
  /**
3884
4784
  * Remove this ban (unban the user).
3885
4785
  * Requires Ban Members permission.
3886
4786
  */
3887
4787
  async unban() {
3888
- await this.client.rest.delete(import_types29.Routes.guildBan(this.guildId, this.user.id), {
4788
+ await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
3889
4789
  auth: true
3890
4790
  });
3891
4791
  }
@@ -3894,40 +4794,53 @@ var GuildBan = class extends Base {
3894
4794
  // src/Domain/Guild/Moderation.ts
3895
4795
  async function ban(guild, userId, options) {
3896
4796
  const body = options ? toGuildBanBody(options) : {};
3897
- await guild.client.rest.put(import_types30.Routes.guildBan(guild.id, userId), {
4797
+ await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
3898
4798
  body: Object.keys(body).length ? body : void 0,
3899
4799
  auth: true
3900
4800
  });
3901
4801
  }
3902
4802
  async function fetchBans(guild) {
3903
- const data = await guild.client.rest.get(import_types30.Routes.guildBans(guild.id));
4803
+ const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
3904
4804
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
3905
4805
  }
3906
4806
  async function unban(guild, userId) {
3907
- await guild.client.rest.delete(import_types30.Routes.guildBan(guild.id, userId), { auth: true });
4807
+ await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), { auth: true });
3908
4808
  }
3909
4809
  async function kick(guild, userId) {
3910
- await guild.client.rest.delete(import_types30.Routes.guildMember(guild.id, userId), { auth: true });
4810
+ await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), { auth: true });
3911
4811
  }
3912
4812
 
4813
+ // src/Domain/Guild/GuildRoleManager.ts
4814
+ var import_collection11 = require("@fluxerjs/collection");
4815
+ var GuildRoleManager = class extends import_collection11.LimitedCollection {
4816
+ constructor(guildId, options) {
4817
+ super(options);
4818
+ this.guildId = guildId;
4819
+ }
4820
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4821
+ get everyone() {
4822
+ return this.get(this.guildId);
4823
+ }
4824
+ };
4825
+
3913
4826
  // src/Domain/Guild/Roles.ts
3914
- var import_types31 = require("@fluxerjs/types");
3915
- var import_util16 = require("@fluxerjs/util");
4827
+ var import_types32 = require("@fluxerjs/types");
4828
+ var import_util21 = require("@fluxerjs/util");
3916
4829
  async function createRole(guild, options = {}) {
3917
- const body = toRoleRequestBody(options);
3918
- const data = await guild.client.rest.post(import_types31.Routes.guildRoles(guild.id), {
4830
+ const body = toRoleCreateBody(options);
4831
+ const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
3919
4832
  body: Object.keys(body).length ? body : void 0,
3920
4833
  auth: true
3921
4834
  });
3922
4835
  return cacheRole(guild, data);
3923
4836
  }
3924
4837
  async function fetchRoles(guild) {
3925
- const data = await guild.client.rest.get(import_types31.Routes.guildRoles(guild.id));
4838
+ const data = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
3926
4839
  return data.map((r) => cacheRole(guild, r));
3927
4840
  }
3928
4841
  async function fetchRole(guild, roleId2) {
3929
4842
  try {
3930
- const data = await guild.client.rest.get(import_types31.Routes.guildRole(guild.id, roleId2));
4843
+ const data = await guild.client.rest.get(import_types32.Routes.guildRole(guild.id, roleId2));
3931
4844
  return cacheRole(guild, data);
3932
4845
  } catch (err) {
3933
4846
  rethrowMapped(err, {
@@ -3937,14 +4850,14 @@ async function fetchRole(guild, roleId2) {
3937
4850
  }
3938
4851
  }
3939
4852
  async function resolveRoleId(guild, arg) {
3940
- const parsed = (0, import_util16.parseRoleMention)(arg);
4853
+ const parsed = (0, import_util21.parseRoleMention)(arg);
3941
4854
  if (parsed) return parsed;
3942
4855
  const trimmed = arg.trim();
3943
4856
  if (/^\d{17,19}$/.test(trimmed)) return trimmed;
3944
4857
  const needle = trimmed.toLowerCase();
3945
4858
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
3946
4859
  if (cached) return cached.id;
3947
- const roles = await guild.client.rest.get(import_types31.Routes.guildRoles(guild.id));
4860
+ const roles = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
3948
4861
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
3949
4862
  if (!role) return null;
3950
4863
  cacheRole(guild, role);
@@ -3953,7 +4866,7 @@ async function resolveRoleId(guild, arg) {
3953
4866
  async function setRolePositions(guild, updates) {
3954
4867
  return replaceRoles(
3955
4868
  guild,
3956
- await guild.client.rest.patch(import_types31.Routes.guildRoles(guild.id), {
4869
+ await guild.client.rest.patch(import_types32.Routes.guildRoles(guild.id), {
3957
4870
  body: updates,
3958
4871
  auth: true
3959
4872
  })
@@ -3962,7 +4875,7 @@ async function setRolePositions(guild, updates) {
3962
4875
  async function setRoleHoistPositions(guild, updates) {
3963
4876
  return replaceRoles(
3964
4877
  guild,
3965
- await guild.client.rest.patch(import_types31.Routes.guildRolesHoistPositions(guild.id), {
4878
+ await guild.client.rest.patch(import_types32.Routes.guildRolesHoistPositions(guild.id), {
3966
4879
  body: updates.map((u) => ({
3967
4880
  id: u.id,
3968
4881
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -3974,23 +4887,23 @@ async function setRoleHoistPositions(guild, updates) {
3974
4887
  async function resetRoleHoistPositions(guild) {
3975
4888
  return replaceRoles(
3976
4889
  guild,
3977
- await guild.client.rest.delete(import_types31.Routes.guildRolesHoistPositions(guild.id), {
4890
+ await guild.client.rest.delete(import_types32.Routes.guildRolesHoistPositions(guild.id), {
3978
4891
  auth: true
3979
4892
  })
3980
4893
  );
3981
4894
  }
3982
4895
 
3983
4896
  // src/Domain/Guild/Stickers.ts
3984
- var import_types32 = require("@fluxerjs/types");
4897
+ var import_types33 = require("@fluxerjs/types");
3985
4898
  async function createSticker(guild, options) {
3986
- const data = await guild.client.rest.post(import_types32.Routes.guildStickers(guild.id), {
4899
+ const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
3987
4900
  body: options,
3988
4901
  auth: true
3989
4902
  });
3990
4903
  return cacheSticker(guild, data);
3991
4904
  }
3992
4905
  async function cloneSticker(guild, sourceStickerId) {
3993
- const data = await guild.client.rest.post(import_types32.Routes.guildStickersClone(guild.id), {
4906
+ const data = await guild.client.rest.post(import_types33.Routes.guildStickersClone(guild.id), {
3994
4907
  body: { source_sticker_id: sourceStickerId },
3995
4908
  auth: true
3996
4909
  });
@@ -3998,17 +4911,17 @@ async function cloneSticker(guild, sourceStickerId) {
3998
4911
  }
3999
4912
  async function createStickersBulk(guild, stickers) {
4000
4913
  const data = await guild.client.rest.post(
4001
- import_types32.Routes.guildStickersBulk(guild.id),
4914
+ import_types33.Routes.guildStickersBulk(guild.id),
4002
4915
  { body: { stickers }, auth: true }
4003
4916
  );
4004
4917
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
4005
4918
  }
4006
4919
  async function fetchStickers(guild) {
4007
- const data = await guild.client.rest.get(import_types32.Routes.guildStickers(guild.id));
4920
+ const data = await guild.client.rest.get(import_types33.Routes.guildStickers(guild.id));
4008
4921
  return data.map((s) => cacheSticker(guild, s));
4009
4922
  }
4010
4923
  async function fetchSticker(guild, stickerId) {
4011
- const data = await guild.client.rest.get(import_types32.Routes.guildSticker(guild.id, stickerId));
4924
+ const data = await guild.client.rest.get(import_types33.Routes.guildSticker(guild.id, stickerId));
4012
4925
  return cacheSticker(guild, data);
4013
4926
  }
4014
4927
 
@@ -4048,8 +4961,26 @@ var Guild = class extends Base {
4048
4961
  systemChannelId;
4049
4962
  /** Rules channel ID (for Community guilds), or null if none. */
4050
4963
  rulesChannelId;
4964
+ /** {@link SystemChannelFlags} bitfield. */
4965
+ systemChannelFlags;
4966
+ /** Splash card alignment. */
4967
+ splashCardAlignment;
4968
+ /** Embed splash hash. */
4969
+ embedSplash;
4051
4970
  /** NSFW level for this guild. */
4052
4971
  nsfwLevel;
4972
+ /** Whether the guild is marked as adult (18+) content. */
4973
+ nsfw;
4974
+ /** Content warning level. */
4975
+ contentWarningLevel;
4976
+ /** Custom guild-wide content warning text. */
4977
+ contentWarningText;
4978
+ /** {@link GuildOperations} bitfield of disabled operations. */
4979
+ disabledOperations;
4980
+ /** ISO-8601 timestamp before which message history is not available. */
4981
+ messageHistoryCutoff;
4982
+ /** Permissions for the current member in this guild (bitfield string). */
4983
+ permissions;
4053
4984
  /** MFA level required for moderation actions. */
4054
4985
  mfaLevel;
4055
4986
  /** Banner width in pixels. */
@@ -4083,13 +5014,13 @@ var Guild = class extends Base {
4083
5014
  this.client = client;
4084
5015
  this.id = data.id;
4085
5016
  this.members = new GuildMemberManager(this);
4086
- this.channels = new import_collection9.LimitedCollection({
5017
+ this.channels = new import_collection12.LimitedCollection({
4087
5018
  maxSize: Number.POSITIVE_INFINITY,
4088
5019
  onEvict: (_id, channel) => client.cache.cascadeChannel(channel, "guild")
4089
5020
  });
4090
- this.roles = new import_collection9.LimitedCollection({ maxSize: client.cache.limits.roles });
4091
- this.emojis = new import_collection9.LimitedCollection({ maxSize: client.cache.limits.emojis });
4092
- this.stickers = new import_collection9.LimitedCollection({ maxSize: client.cache.limits.stickers });
5021
+ this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
5022
+ this.emojis = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.emojis });
5023
+ this.stickers = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.stickers });
4093
5024
  this.name = data.name ?? "";
4094
5025
  this.icon = data.icon ?? null;
4095
5026
  this.banner = data.banner ?? null;
@@ -4104,7 +5035,16 @@ var Guild = class extends Base {
4104
5035
  this.afkTimeout = data.afk_timeout ?? 0;
4105
5036
  this.systemChannelId = data.system_channel_id ?? null;
4106
5037
  this.rulesChannelId = data.rules_channel_id ?? null;
4107
- this.nsfwLevel = data.nsfw_level ?? import_types33.GuildNSFWLevel.Safe;
5038
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5039
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5040
+ this.embedSplash = data.embed_splash ?? null;
5041
+ this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
5042
+ this.nsfw = data.nsfw ?? false;
5043
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5044
+ this.contentWarningText = data.content_warning_text ?? null;
5045
+ this.disabledOperations = data.disabled_operations ?? 0;
5046
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5047
+ this.permissions = data.permissions ?? null;
4108
5048
  this.mfaLevel = data.mfa_level ?? 0;
4109
5049
  this.bannerWidth = data.banner_width ?? null;
4110
5050
  this.bannerHeight = data.banner_height ?? null;
@@ -4139,7 +5079,28 @@ var Guild = class extends Base {
4139
5079
  if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
4140
5080
  if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
4141
5081
  if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
4142
- if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types33.GuildNSFWLevel.Safe;
5082
+ if (data.system_channel_flags !== void 0) {
5083
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5084
+ }
5085
+ if (data.splash_card_alignment !== void 0) {
5086
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5087
+ }
5088
+ if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
5089
+ if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
5090
+ if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
5091
+ if (data.content_warning_level !== void 0) {
5092
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5093
+ }
5094
+ if (data.content_warning_text !== void 0) {
5095
+ this.contentWarningText = data.content_warning_text ?? null;
5096
+ }
5097
+ if (data.disabled_operations !== void 0) {
5098
+ this.disabledOperations = data.disabled_operations ?? 0;
5099
+ }
5100
+ if (data.message_history_cutoff !== void 0) {
5101
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5102
+ }
5103
+ if (data.permissions !== void 0) this.permissions = data.permissions ?? null;
4143
5104
  if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
4144
5105
  if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
4145
5106
  if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
@@ -4160,11 +5121,11 @@ var Guild = class extends Base {
4160
5121
  }
4161
5122
  /** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
4162
5123
  get createdTimestamp() {
4163
- return import_util17.SnowflakeUtil.timestampFromSnowflake(this.id);
5124
+ return import_util22.SnowflakeUtil.timestampFromSnowflake(this.id);
4164
5125
  }
4165
5126
  /** Date when this guild was created, derived from its snowflake ID. */
4166
5127
  get createdAt() {
4167
- return import_util17.SnowflakeUtil.dateFromSnowflake(this.id);
5128
+ return import_util22.SnowflakeUtil.dateFromSnowflake(this.id);
4168
5129
  }
4169
5130
  /** The guild's name. */
4170
5131
  toString() {
@@ -4192,11 +5153,11 @@ var Guild = class extends Base {
4192
5153
  });
4193
5154
  }
4194
5155
  /**
4195
- * Create a channel. `data.type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
5156
+ * Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
4196
5157
  * Requires Manage Channels.
4197
5158
  */
4198
- createChannel(data) {
4199
- return createChannel(this, data);
5159
+ createChannel(options) {
5160
+ return createChannel(this, options);
4200
5161
  }
4201
5162
  /** Fetch all channels in this guild from the API. */
4202
5163
  fetchChannels() {
@@ -4258,7 +5219,7 @@ var Guild = class extends Base {
4258
5219
  resetRoleHoistPositions() {
4259
5220
  return resetRoleHoistPositions(this);
4260
5221
  }
4261
- /** Ban a user from the guild. Requires Ban Members. `ban_duration_seconds`: 0 = permanent. */
5222
+ /** Ban a user from the guild. Requires Ban Members. `banDurationSeconds`: 0 = permanent. */
4262
5223
  ban(userId, options) {
4263
5224
  return ban(this, userId, options);
4264
5225
  }
@@ -4357,7 +5318,7 @@ var Guild = class extends Base {
4357
5318
  };
4358
5319
 
4359
5320
  // src/Domain/Guild/Payload.ts
4360
- var import_util18 = require("@fluxerjs/util");
5321
+ var import_util23 = require("@fluxerjs/util");
4361
5322
  var TOP_LEVEL_COUNT_KEYS = [
4362
5323
  "member_count",
4363
5324
  "online_count",
@@ -4397,10 +5358,10 @@ function mergeTopLevelSnapshotFields(properties, raw) {
4397
5358
  return out;
4398
5359
  }
4399
5360
  function normalizeGuildSnapshotPayload(raw) {
4400
- if (!(0, import_util18.isRecord)(raw)) return null;
5361
+ if (!(0, import_util23.isRecord)(raw)) return null;
4401
5362
  const flatPayload = isHydratableGuildPayload(raw) && (raw.roles === void 0 || Array.isArray(raw.roles)) ? raw : null;
4402
5363
  let nestedPayload = null;
4403
- if (Object.hasOwn(raw, "properties") && (0, import_util18.isRecord)(raw.properties)) {
5364
+ if (Object.hasOwn(raw, "properties") && (0, import_util23.isRecord)(raw.properties)) {
4404
5365
  const properties = raw.properties;
4405
5366
  const rolesValid = raw.roles === void 0 || Array.isArray(raw.roles);
4406
5367
  if (rolesValid && isHydratableGuildPayload(properties) && raw.id === properties.id) {
@@ -4412,7 +5373,7 @@ function normalizeGuildSnapshotPayload(raw) {
4412
5373
  return flatPayload ?? nestedPayload;
4413
5374
  }
4414
5375
  function normalizeGuildUpdatePayload(raw) {
4415
- if (!(0, import_util18.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
5376
+ if (!(0, import_util23.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
4416
5377
  return raw;
4417
5378
  }
4418
5379
 
@@ -4458,23 +5419,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
4458
5419
  }
4459
5420
 
4460
5421
  // src/ClientCore/ClientUser.ts
4461
- var import_types34 = require("@fluxerjs/types");
5422
+ var import_types35 = require("@fluxerjs/types");
4462
5423
  var ClientUser = class extends User {
4463
5424
  /** Broadcast presence (gateway opcode 3) on all shards. */
4464
5425
  setPresence(presence) {
5426
+ this.client.options.presence = presence;
4465
5427
  const wire = toPresenceWire(presence);
4466
- this.client.options.presence = wire;
4467
- this.client._sendToAllShards({ op: import_types34.GatewayOpcodes.PresenceUpdate, d: wire });
5428
+ this.client._sendToAllShards({ op: import_types35.GatewayOpcodes.PresenceUpdate, d: wire });
4468
5429
  }
4469
5430
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
4470
5431
  async fetch() {
4471
- const data = await this.client.rest.get(import_types34.Routes.currentUser(), { auth: true });
5432
+ const data = await this.client.rest.get(import_types35.Routes.currentUser(), { auth: true });
4472
5433
  this._patch(data);
4473
5434
  return this;
4474
5435
  }
4475
5436
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
4476
5437
  async fetchGuilds(options) {
4477
- const path = import_types34.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
5438
+ const path = import_types35.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
4478
5439
  const data = await this.client.rest.get(path, { auth: true });
4479
5440
  return data.map((g) => ({
4480
5441
  id: g.id,
@@ -4487,10 +5448,18 @@ var ClientUser = class extends User {
4487
5448
  ...g.approximate_presence_count !== void 0 ? { approximatePresenceCount: g.approximate_presence_count } : {}
4488
5449
  }));
4489
5450
  }
4490
- /** DELETE /users/@me/guilds/{guild_id} */
5451
+ /**
5452
+ * Leave a guild (`client.user.leaveGuild`).
5453
+ * DELETE /users/@me/guilds/{guild_id}.
5454
+ *
5455
+ * @param guildId - Guild to leave
5456
+ * @param options - Optional sudo / MFA body for user accounts
5457
+ * @example
5458
+ * await client.user.leaveGuild(guildId);
5459
+ */
4491
5460
  async leaveGuild(guildId, options) {
4492
5461
  const body = options ? toSudoBody(options) : void 0;
4493
- await this.client.rest.delete(import_types34.Routes.leaveGuild(guildId), {
5462
+ await this.client.rest.delete(import_types35.Routes.leaveGuild(guildId), {
4494
5463
  body: body && Object.keys(body).length ? body : void 0,
4495
5464
  auth: true
4496
5465
  });
@@ -4498,7 +5467,7 @@ var ClientUser = class extends User {
4498
5467
  /** Delete every message authored by the caller across a guild (sudo). */
4499
5468
  async bulkDeleteMyMessagesInGuild(guildId, options) {
4500
5469
  const body = options ? toSudoBody(options) : void 0;
4501
- await this.client.rest.post(import_types34.Routes.guildBulkDeleteMine(guildId), {
5470
+ await this.client.rest.post(import_types35.Routes.guildBulkDeleteMine(guildId), {
4502
5471
  body: body && Object.keys(body).length ? body : void 0,
4503
5472
  auth: true
4504
5473
  });
@@ -4506,7 +5475,7 @@ var ClientUser = class extends User {
4506
5475
  };
4507
5476
 
4508
5477
  // src/ClientCore/EventHandlers/Helpers.ts
4509
- var import_util19 = require("@fluxerjs/util");
5478
+ var import_util24 = require("@fluxerjs/util");
4510
5479
  function unknownUser(id) {
4511
5480
  return {
4512
5481
  id,
@@ -4665,7 +5634,7 @@ var guildResourceHandlers = {
4665
5634
  role = new Role(client, data.role, data.guild_id);
4666
5635
  guild?.roles.set(role.id, role);
4667
5636
  }
4668
- client.emit(Events.GuildRoleUpdate, { role, oldRole });
5637
+ client.emit(Events.GuildRoleUpdate, oldRole, role);
4669
5638
  },
4670
5639
  GUILD_ROLE_UPDATE_BULK(client, d) {
4671
5640
  const data = d;
@@ -4681,11 +5650,7 @@ var guildResourceHandlers = {
4681
5650
  const guild = client.guilds.get(data.guild_id);
4682
5651
  const role = guild?.roles.get(data.role_id) ?? null;
4683
5652
  guild?.roles.delete(data.role_id);
4684
- client.emit(Events.GuildRoleDelete, {
4685
- roleId: data.role_id,
4686
- guildId: data.guild_id,
4687
- role
4688
- });
5653
+ client.emit(Events.GuildRoleDelete, role, data.guild_id, data.role_id);
4689
5654
  },
4690
5655
  GUILD_BAN_ADD(client, d) {
4691
5656
  const data = d;
@@ -4785,55 +5750,50 @@ var guildHandlers = {
4785
5750
  };
4786
5751
 
4787
5752
  // src/ClientCore/EventHandlers/Invites.ts
4788
- var import_types35 = require("@fluxerjs/types");
5753
+ var import_types36 = require("@fluxerjs/types");
4789
5754
  function normalizeInviteCreate(client, payload) {
4790
- const raw = (0, import_util19.asRecord)(payload);
4791
- const code = (0, import_util19.str)(raw?.code);
5755
+ const raw = (0, import_util24.asRecord)(payload);
5756
+ const code = (0, import_util24.str)(raw?.code);
4792
5757
  if (!raw || !code) return null;
4793
- const typeNum = (0, import_util19.num)(raw.type);
4794
- const type = typeNum === import_types35.InviteType.GroupDM || typeNum === import_types35.InviteType.EmojiPack || typeNum === import_types35.InviteType.StickerPack ? typeNum : import_types35.InviteType.Guild;
5758
+ const typeNum = (0, import_util24.num)(raw.type);
5759
+ const type = typeNum === import_types36.InviteType.GroupDM ? import_types36.InviteType.GroupDM : import_types36.InviteType.Guild;
4795
5760
  const shared = {
4796
5761
  code,
4797
5762
  inviter: raw.inviter ?? null,
4798
- member_count: (0, import_util19.num)(raw.member_count),
5763
+ member_count: (0, import_util24.num)(raw.member_count),
4799
5764
  expires_at: raw.expires_at ?? void 0,
4800
5765
  temporary: typeof raw.temporary === "boolean" ? raw.temporary : void 0,
4801
- created_at: (0, import_util19.str)(raw.created_at),
4802
- uses: (0, import_util19.num)(raw.uses),
4803
- max_uses: (0, import_util19.num)(raw.max_uses),
4804
- max_age: (0, import_util19.num)(raw.max_age)
5766
+ created_at: (0, import_util24.str)(raw.created_at),
5767
+ uses: (0, import_util24.num)(raw.uses),
5768
+ max_uses: (0, import_util24.num)(raw.max_uses),
5769
+ max_age: (0, import_util24.num)(raw.max_age)
4805
5770
  };
4806
- if (type === import_types35.InviteType.EmojiPack || type === import_types35.InviteType.StickerPack) {
4807
- const pack = (0, import_util19.asRecord)(raw.pack);
4808
- if (!pack || !(0, import_util19.str)(pack.id) || !(0, import_util19.str)(pack.name)) return null;
4809
- return { ...shared, type, pack };
4810
- }
4811
- const guildObj = (0, import_util19.asRecord)(raw.guild);
4812
- const channelObj = (0, import_util19.asRecord)(raw.channel);
4813
- const guildId = (0, import_util19.str)(guildObj?.id) ?? (0, import_util19.str)(raw.guild_id) ?? "0";
4814
- const channelId = (0, import_util19.str)(channelObj?.id) ?? (0, import_util19.str)(raw.channel_id) ?? "0";
5771
+ const guildObj = (0, import_util24.asRecord)(raw.guild);
5772
+ const channelObj = (0, import_util24.asRecord)(raw.channel);
5773
+ const guildId = (0, import_util24.str)(guildObj?.id) ?? (0, import_util24.str)(raw.guild_id) ?? "0";
5774
+ const channelId = (0, import_util24.str)(channelObj?.id) ?? (0, import_util24.str)(raw.channel_id) ?? "0";
4815
5775
  const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
4816
5776
  const cachedChannel = channelId !== "0" ? client.channels.get(channelId) : null;
4817
5777
  const channel = {
4818
5778
  id: channelId,
4819
- type: (0, import_util19.num)(channelObj?.type) ?? cachedChannel?.type ?? import_types35.ChannelType.GuildText,
4820
- name: (0, import_util19.str)(channelObj?.name) ?? cachedChannel?.name ?? null,
5779
+ type: (0, import_util24.num)(channelObj?.type) ?? cachedChannel?.type ?? import_types36.ChannelType.GuildText,
5780
+ name: (0, import_util24.str)(channelObj?.name) ?? cachedChannel?.name ?? null,
4821
5781
  icon: channelObj?.icon ?? null
4822
5782
  };
4823
- if (type === import_types35.InviteType.GroupDM) return { ...shared, type, channel };
5783
+ if (type === import_types36.InviteType.GroupDM) return { ...shared, type, channel };
4824
5784
  return {
4825
5785
  ...shared,
4826
- type: import_types35.InviteType.Guild,
5786
+ type: import_types36.InviteType.Guild,
4827
5787
  guild: {
4828
5788
  id: guildId,
4829
- name: (0, import_util19.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
5789
+ name: (0, import_util24.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
4830
5790
  icon: guildObj?.icon ?? null,
4831
5791
  banner: guildObj?.banner ?? null,
4832
5792
  splash: guildObj?.splash ?? null,
4833
5793
  features: Array.isArray(guildObj?.features) ? guildObj.features : void 0
4834
5794
  },
4835
5795
  channel,
4836
- presence_count: (0, import_util19.num)(raw.presence_count)
5796
+ presence_count: (0, import_util24.num)(raw.presence_count)
4837
5797
  };
4838
5798
  }
4839
5799
  var inviteHandlers = {
@@ -4859,6 +5819,30 @@ var inviteHandlers = {
4859
5819
  }
4860
5820
  };
4861
5821
 
5822
+ // src/Domain/Guild/PartialGuildMember.ts
5823
+ var PartialGuildMember = class {
5824
+ partial = true;
5825
+ client;
5826
+ id;
5827
+ user;
5828
+ guildId;
5829
+ guild;
5830
+ constructor(data) {
5831
+ this.client = data.client;
5832
+ this.id = data.id;
5833
+ this.user = data.user;
5834
+ this.guild = data.guild;
5835
+ this.guildId = data.guild.id;
5836
+ }
5837
+ /**
5838
+ * Fetch the full {@link GuildMember} from the API (cache-aware via `guild.members.fetch`).
5839
+ * @throws FluxerError with MEMBER_NOT_FOUND if the user is not in the guild
5840
+ */
5841
+ async fetch() {
5842
+ return this.guild.members.fetch(this.id);
5843
+ }
5844
+ };
5845
+
4862
5846
  // src/ClientCore/EventHandlers/Members.ts
4863
5847
  var memberHandlers = {
4864
5848
  GUILD_MEMBER_ADD(client, d) {
@@ -4885,28 +5869,15 @@ var memberHandlers = {
4885
5869
  const data = d;
4886
5870
  const guild = client.guilds.get(data.guild_id);
4887
5871
  if (!guild || !data.user?.id) return;
4888
- let member = guild.members.get(data.user.id);
4889
- if (member) {
4890
- guild.members.delete(data.user.id);
4891
- } else {
4892
- member = new GuildMember(
4893
- client,
4894
- {
4895
- user: {
4896
- ...unknownUser(data.user.id),
4897
- ...data.user,
4898
- username: data.user.username ?? "Unknown",
4899
- discriminator: data.user.discriminator ?? "0"
4900
- },
4901
- roles: [],
4902
- joined_at: (/* @__PURE__ */ new Date(0)).toISOString(),
4903
- nick: null,
4904
- mute: false,
4905
- deaf: false
4906
- },
4907
- guild
4908
- );
4909
- }
5872
+ const cached = guild.members.get(data.user.id);
5873
+ if (cached) guild.members.delete(data.user.id);
5874
+ const user = client.getOrCreateUser(data.user);
5875
+ const member = cached ?? new PartialGuildMember({
5876
+ client,
5877
+ id: data.user.id,
5878
+ user,
5879
+ guild
5880
+ });
4910
5881
  guild.adjustMemberCount(-1);
4911
5882
  client.emit(Events.GuildMemberRemove, member);
4912
5883
  },
@@ -4925,7 +5896,7 @@ var memberHandlers = {
4925
5896
  members,
4926
5897
  chunkIndex: data.chunk_index,
4927
5898
  chunkCount: data.chunk_count,
4928
- notFound: [],
5899
+ notFound: data.not_found ?? [],
4929
5900
  nonce: data.nonce ?? null
4930
5901
  };
4931
5902
  client.emit(Events.GuildMembersChunk, payload);
@@ -4933,7 +5904,35 @@ var memberHandlers = {
4933
5904
  };
4934
5905
 
4935
5906
  // src/ClientCore/EventHandlers/Messages.ts
4936
- function toReactionEmoji2(emoji) {
5907
+ var import_util25 = require("@fluxerjs/util");
5908
+ function cachedTextChannel(client, channelId) {
5909
+ const channel = client.channels.get(channelId);
5910
+ return channel?.isTextBased() ? channel : null;
5911
+ }
5912
+ function cachedMessage(client, channelId, messageId) {
5913
+ const data = client._getMessageCache(channelId)?.get(messageId);
5914
+ return data ? new Message(client, data) : null;
5915
+ }
5916
+ function isHydratableMessage(data) {
5917
+ return Boolean(data.author?.id && data.timestamp);
5918
+ }
5919
+ function toPartialMessage(client, args) {
5920
+ const cached = args.cached;
5921
+ const authorId = args.authorId ?? cached?.author?.id ?? null;
5922
+ const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
5923
+ const createdAt = cached?.timestamp ? new Date(cached.timestamp) : import_util25.SnowflakeUtil.isValid(args.id) ? import_util25.SnowflakeUtil.dateFromSnowflake(args.id) : null;
5924
+ return new PartialMessage(client, {
5925
+ id: args.id,
5926
+ channelId: args.channelId,
5927
+ guildId: args.guildId ?? cached?.guild_id ?? null,
5928
+ channel: cachedTextChannel(client, args.channelId),
5929
+ content: args.content ?? cached?.content ?? null,
5930
+ authorId,
5931
+ author,
5932
+ createdAt
5933
+ });
5934
+ }
5935
+ function toReactionEmoji(emoji) {
4937
5936
  return {
4938
5937
  name: emoji.name,
4939
5938
  ...emoji.id !== void 0 ? { id: emoji.id } : {},
@@ -4950,9 +5949,12 @@ function emitReaction(event) {
4950
5949
  const payload = {
4951
5950
  reaction,
4952
5951
  user,
5952
+ message: cachedMessage(client, data.channel_id, data.message_id),
5953
+ channel: cachedTextChannel(client, data.channel_id),
5954
+ member,
4953
5955
  messageId: data.message_id,
4954
5956
  channelId: data.channel_id,
4955
- emoji: toReactionEmoji2(data.emoji),
5957
+ emoji: toReactionEmoji(data.emoji),
4956
5958
  userId: data.user_id
4957
5959
  };
4958
5960
  client.emit(event, payload);
@@ -4972,37 +5974,60 @@ var messageHandlers = {
4972
5974
  },
4973
5975
  MESSAGE_UPDATE(client, d) {
4974
5976
  const partial = d;
4975
- const cache = client._getMessageCache(partial.channel_id);
4976
- let oldMessage = null;
4977
- let mergedData = partial;
4978
- if (cache) {
4979
- const oldData = cache.get(partial.id);
4980
- if (oldData) {
4981
- oldMessage = new Message(client, oldData);
4982
- mergedData = { ...oldData, ...partial };
4983
- }
5977
+ const oldData = client._getMessageCache(partial.channel_id)?.get(partial.id);
5978
+ const oldMessage = oldData ? new Message(client, oldData) : null;
5979
+ const mergedData = oldData ? { ...oldData, ...partial } : partial;
5980
+ if (isHydratableMessage(mergedData)) {
5981
+ client._addMessageToCache(partial.channel_id, mergedData);
5982
+ client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
5983
+ return;
4984
5984
  }
4985
- client._addMessageToCache(partial.channel_id, mergedData);
4986
- client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
5985
+ client.emit(
5986
+ Events.MessageUpdate,
5987
+ oldMessage,
5988
+ toPartialMessage(client, {
5989
+ id: partial.id,
5990
+ channelId: partial.channel_id,
5991
+ guildId: partial.guild_id ?? oldData?.guild_id ?? null,
5992
+ content: partial.content ?? oldData?.content ?? null,
5993
+ authorId: partial.author?.id ?? oldData?.author?.id ?? null,
5994
+ cached: oldData
5995
+ })
5996
+ );
4987
5997
  },
4988
5998
  MESSAGE_DELETE(client, d) {
4989
5999
  const data = d;
4990
- client._removeMessageFromCache(data.channel_id, data.id);
4991
- client.emit(Events.MessageDelete, {
6000
+ const cached = client._getMessageCache(data.channel_id)?.get(data.id);
6001
+ const payload = toPartialMessage(client, {
4992
6002
  id: data.id,
4993
6003
  channelId: data.channel_id,
4994
- channel: client.channels.get(data.channel_id) ?? null,
4995
- content: data.content ?? null,
4996
- authorId: data.author_id ?? null
6004
+ guildId: data.guild_id ?? cached?.guild_id ?? null,
6005
+ content: data.content ?? cached?.content ?? null,
6006
+ authorId: data.author_id ?? cached?.author?.id ?? null,
6007
+ cached
4997
6008
  });
6009
+ client._removeMessageFromCache(data.channel_id, data.id);
6010
+ client.emit(Events.MessageDelete, payload);
4998
6011
  },
4999
6012
  MESSAGE_DELETE_BULK(client, d) {
5000
6013
  const data = d;
5001
- for (const id of data.ids ?? []) client._removeMessageFromCache(data.channel_id, id);
6014
+ const ids = data.ids ?? [];
6015
+ const cache = client._getMessageCache(data.channel_id);
6016
+ const messages = ids.map(
6017
+ (id) => toPartialMessage(client, {
6018
+ id,
6019
+ channelId: data.channel_id,
6020
+ guildId: data.guild_id ?? cache?.get(id)?.guild_id ?? null,
6021
+ cached: cache?.get(id)
6022
+ })
6023
+ );
6024
+ for (const id of ids) client._removeMessageFromCache(data.channel_id, id);
5002
6025
  client.emit(Events.MessageDeleteBulk, {
5003
- ids: data.ids ?? [],
6026
+ ids,
5004
6027
  channelId: data.channel_id,
5005
- guildId: data.guild_id ?? null
6028
+ guildId: data.guild_id ?? null,
6029
+ channel: cachedTextChannel(client, data.channel_id),
6030
+ messages
5006
6031
  });
5007
6032
  },
5008
6033
  MESSAGE_REACTION_ADD: emitReaction(Events.MessageReactionAdd),
@@ -5012,7 +6037,9 @@ var messageHandlers = {
5012
6037
  const payload = {
5013
6038
  messageId: data.message_id,
5014
6039
  channelId: data.channel_id,
5015
- guildId: data.guild_id ?? null
6040
+ guildId: data.guild_id ?? null,
6041
+ message: cachedMessage(client, data.channel_id, data.message_id),
6042
+ channel: cachedTextChannel(client, data.channel_id)
5016
6043
  };
5017
6044
  client.emit(Events.MessageReactionRemoveAll, payload);
5018
6045
  },
@@ -5022,7 +6049,9 @@ var messageHandlers = {
5022
6049
  messageId: data.message_id,
5023
6050
  channelId: data.channel_id,
5024
6051
  guildId: data.guild_id ?? null,
5025
- emoji: toReactionEmoji2(data.emoji)
6052
+ emoji: toReactionEmoji(data.emoji),
6053
+ message: cachedMessage(client, data.channel_id, data.message_id),
6054
+ channel: cachedTextChannel(client, data.channel_id)
5026
6055
  };
5027
6056
  client.emit(Events.MessageReactionRemoveEmoji, payload);
5028
6057
  },
@@ -5041,7 +6070,7 @@ var messageHandlers = {
5041
6070
  }
5042
6071
  reactions.push({
5043
6072
  userId: entry.user_id,
5044
- emoji: toReactionEmoji2(entry.emoji),
6073
+ emoji: toReactionEmoji(entry.emoji),
5045
6074
  member
5046
6075
  });
5047
6076
  }
@@ -5049,6 +6078,8 @@ var messageHandlers = {
5049
6078
  channelId: data.channel_id,
5050
6079
  messageId: data.message_id,
5051
6080
  guildId: data.guild_id ?? null,
6081
+ message: cachedMessage(client, data.channel_id, data.message_id),
6082
+ channel: cachedTextChannel(client, data.channel_id),
5052
6083
  reactions
5053
6084
  };
5054
6085
  client.emit(Events.MessageReactionAddMany, payload);
@@ -5259,15 +6290,27 @@ function handleReadyPayload(client, data) {
5259
6290
  const waitForGuilds = client.options.waitForGuilds === true;
5260
6291
  const guilds = data.guilds ?? [];
5261
6292
  const pending = hydrateReadyGuilds(client, guilds, waitForGuilds);
6293
+ if (client.readyAt !== null) {
6294
+ if (pending !== null && pending.size > 0) {
6295
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6296
+ for (const id of pending) existing.add(id);
6297
+ client._pendingGuildIds = existing;
6298
+ }
6299
+ return;
6300
+ }
5262
6301
  if (pending !== null && pending.size > 0) {
5263
- client._pendingGuildIds = pending;
6302
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6303
+ for (const id of pending) existing.add(id);
6304
+ client._pendingGuildIds = existing;
5264
6305
  return;
5265
6306
  }
5266
6307
  if (waitForGuilds && guilds.length === 0) {
5267
- client._guildStreamSettleTimeout = setTimeout(() => {
5268
- client._guildStreamSettleTimeout = null;
5269
- finalizeClientReady(client);
5270
- }, GUILD_STREAM_SETTLE_MS);
6308
+ if (client._guildStreamSettleTimeout === null) {
6309
+ client._guildStreamSettleTimeout = setTimeout(() => {
6310
+ client._guildStreamSettleTimeout = null;
6311
+ if (client.readyAt === null) finalizeClientReady(client);
6312
+ }, GUILD_STREAM_SETTLE_MS);
6313
+ }
5271
6314
  return;
5272
6315
  }
5273
6316
  finalizeClientReady(client);
@@ -5279,7 +6322,7 @@ async function connectClientGateway(client, token, signal) {
5279
6322
  const ws = new import_ws.WebSocketManager({
5280
6323
  token,
5281
6324
  intents: client.options.intents ?? 0,
5282
- presence: client.options.presence,
6325
+ presence: client.options.presence ? toPresenceWire(client.options.presence) : void 0,
5283
6326
  flags: client.options.identifyFlags,
5284
6327
  ignoredEvents: client.options.ignoredEvents,
5285
6328
  initialGuildId: client.options.initialGuildId,
@@ -5288,24 +6331,57 @@ async function connectClientGateway(client, token, signal) {
5288
6331
  },
5289
6332
  version: client.options.rest?.version ?? "1",
5290
6333
  debug: client.options.gatewayDebug !== false,
5291
- WebSocket: client.options.WebSocket
6334
+ WebSocket: client.options.WebSocket,
6335
+ shardCount: client.options.shardCount ?? client.options.totalShards,
6336
+ shardIds: client.options.shardIds ?? client.options.shardList,
6337
+ guildsPerShard: client.options.guildsPerShard,
6338
+ buildStrategy: client.options.buildStrategy,
6339
+ sessionStore: client.options.sessionStore,
6340
+ identifyThrottler: client.options.identifyThrottler
5292
6341
  });
5293
6342
  ws.on("dispatch", ({ payload }) => {
5294
6343
  handleGatewayDispatch(client, payload, client._deferredGatewayDispatches).catch(
5295
6344
  (err) => emitClientError(client, err)
5296
6345
  );
5297
6346
  });
5298
- ws.on("ready", ({ data }) => {
5299
- handleReadyPayload(client, data);
6347
+ ws.on("ready", ({ shardId, data }) => {
6348
+ client.emit(Events.ShardReady, shardId);
6349
+ try {
6350
+ handleReadyPayload(client, data);
6351
+ } catch (err) {
6352
+ emitClientError(client, err);
6353
+ }
6354
+ });
6355
+ ws.on("resumed", (shardId) => {
6356
+ client.emit(Events.ShardResumed, shardId);
6357
+ });
6358
+ ws.on("close", ({ shardId, code }) => {
6359
+ client.emit(Events.ShardDisconnect, shardId, code);
6360
+ if (code === import_ws.GatewayCloseCodes.AuthenticationFailed) {
6361
+ emitClientError(
6362
+ client,
6363
+ new import_util2.FluxerError("Gateway authentication failed (4004). Check the bot token.", {
6364
+ code: import_util.ErrorCodes.InvalidToken
6365
+ })
6366
+ );
6367
+ }
5300
6368
  });
5301
- ws.on("error", ({ error }) => {
5302
- client.logger.error("gateway error", { error: error.message, name: error.name });
6369
+ ws.on("error", ({ shardId, error }) => {
6370
+ if (shardId >= 0) client.emit(Events.ShardError, shardId, error);
6371
+ client.logger.error("gateway error", {
6372
+ error: error.message,
6373
+ name: error.name,
6374
+ shardId
6375
+ });
5303
6376
  client.emit(Events.Error, error);
5304
6377
  });
5305
6378
  ws.on("debug", (msg) => {
5306
6379
  client.logger.debug(msg);
5307
6380
  client.emit(Events.Debug, msg);
5308
6381
  });
6382
+ ws.on("shardingRequired", (payload) => {
6383
+ client.emit(Events.ShardingRequired, payload);
6384
+ });
5309
6385
  client._ws = ws;
5310
6386
  const onAbort = () => {
5311
6387
  ws.destroy();
@@ -5331,9 +6407,9 @@ async function connectClientGateway(client, token, signal) {
5331
6407
  }
5332
6408
 
5333
6409
  // src/ClientCore/GuildManager.ts
5334
- var import_collection10 = require("@fluxerjs/collection");
5335
- var import_types36 = require("@fluxerjs/types");
5336
- var GuildManager = class extends import_collection10.LimitedCollection {
6410
+ var import_collection13 = require("@fluxerjs/collection");
6411
+ var import_types37 = require("@fluxerjs/types");
6412
+ var GuildManager = class extends import_collection13.LimitedCollection {
5337
6413
  constructor(client) {
5338
6414
  super({
5339
6415
  maxSize: client.cache.limits.guilds,
@@ -5342,8 +6418,8 @@ var GuildManager = class extends import_collection10.LimitedCollection {
5342
6418
  this.client = client;
5343
6419
  }
5344
6420
  /**
5345
- * Remove a guild and cascade its channels / message caches.
5346
- * FIFO eviction uses `onEvict` instead (via `super.delete` in LimitedCollection).
6421
+ * Remove a guild from cache and cascade its channels / message caches.
6422
+ * Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
5347
6423
  */
5348
6424
  delete(key) {
5349
6425
  const guild = this.get(key);
@@ -5371,7 +6447,7 @@ var GuildManager = class extends import_collection10.LimitedCollection {
5371
6447
  const cached = this.get(guildId);
5372
6448
  if (cached && !options?.force) return cached;
5373
6449
  try {
5374
- const data = await this.client.rest.get(import_types36.Routes.guild(guildId));
6450
+ const data = await this.client.rest.get(import_types37.Routes.guild(guildId));
5375
6451
  if (cached) {
5376
6452
  cached._patch(data);
5377
6453
  return cached;
@@ -5456,180 +6532,11 @@ var MessageCache = class {
5456
6532
  }
5457
6533
  };
5458
6534
 
5459
- // src/ClientCore/PackManager.ts
5460
- var import_types37 = require("@fluxerjs/types");
5461
- function toPackSummaryPayload(data) {
5462
- return {
5463
- id: data.id,
5464
- name: data.name,
5465
- description: data.description,
5466
- type: data.type,
5467
- creatorId: data.creator_id,
5468
- createdAt: data.created_at,
5469
- updatedAt: data.updated_at,
5470
- ...data.installed_at !== void 0 ? { installedAt: data.installed_at } : {}
5471
- };
5472
- }
5473
- function toEmojiPayload(data) {
5474
- return {
5475
- id: data.id,
5476
- name: data.name,
5477
- animated: data.animated
5478
- };
5479
- }
5480
- function toStickerPayload(data) {
5481
- return {
5482
- id: data.id,
5483
- name: data.name,
5484
- description: data.description,
5485
- tags: data.tags,
5486
- animated: data.animated,
5487
- nsfw: data.nsfw
5488
- };
5489
- }
5490
- function toInvitePayload(data) {
5491
- return {
5492
- code: data.code,
5493
- ...data.max_uses !== void 0 ? { maxUses: data.max_uses } : {},
5494
- ...data.max_age !== void 0 ? { maxAge: data.max_age } : {},
5495
- ...data.uses !== void 0 ? { uses: data.uses } : {},
5496
- ...data.temporary !== void 0 ? { temporary: data.temporary } : {},
5497
- ...data.created_at !== void 0 ? { createdAt: data.created_at } : {},
5498
- ...data.expires_at !== void 0 ? { expiresAt: data.expires_at } : {}
5499
- };
5500
- }
5501
- function mapDashboardSection(section) {
5502
- return {
5503
- installedLimit: section.installed_limit,
5504
- createdLimit: section.created_limit,
5505
- installed: section.installed.map(toPackSummaryPayload),
5506
- created: section.created.map(toPackSummaryPayload)
5507
- };
5508
- }
5509
- var PackManager = class {
5510
- constructor(client) {
5511
- this.client = client;
5512
- }
5513
- /** Fetch the current user's pack dashboard (camelCase summaries). */
5514
- async fetchDashboard() {
5515
- const data = await this.client.rest.get(import_types37.Routes.packs());
5516
- return {
5517
- emoji: mapDashboardSection(data.emoji),
5518
- sticker: mapDashboardSection(data.sticker)
5519
- };
5520
- }
5521
- /** Create a pack. */
5522
- async create(packType, body) {
5523
- const data = await this.client.rest.post(import_types37.Routes.packsByType(packType), {
5524
- body
5525
- });
5526
- return toPackSummaryPayload(data);
5527
- }
5528
- /** Edit a pack. */
5529
- async edit(packId, body) {
5530
- const data = await this.client.rest.patch(import_types37.Routes.pack(packId), { body });
5531
- return toPackSummaryPayload(data);
5532
- }
5533
- /** Delete a pack. */
5534
- async delete(packId) {
5535
- await this.client.rest.delete(import_types37.Routes.pack(packId));
5536
- }
5537
- /** Install a pack for the current user. */
5538
- async install(packId) {
5539
- await this.client.rest.post(import_types37.Routes.packInstall(packId));
5540
- }
5541
- /** Uninstall a pack for the current user. */
5542
- async uninstall(packId) {
5543
- await this.client.rest.delete(import_types37.Routes.packInstall(packId));
5544
- }
5545
- /** List invites for a pack. */
5546
- async listInvites(packId) {
5547
- const data = await this.client.rest.get(import_types37.Routes.packInvites(packId));
5548
- return data.map(toInvitePayload);
5549
- }
5550
- /** Create an invite for a pack. */
5551
- async createInvite(packId, options = {}) {
5552
- const body = toPackInviteBody(options);
5553
- const data = await this.client.rest.post(import_types37.Routes.packInvites(packId), {
5554
- body: Object.keys(body).length ? body : void 0
5555
- });
5556
- return toInvitePayload(data);
5557
- }
5558
- /** List emojis in a pack. */
5559
- async listEmojis(packId) {
5560
- const data = await this.client.rest.get(import_types37.Routes.packEmojis(packId));
5561
- return data.map(toEmojiPayload);
5562
- }
5563
- /** Create an emoji in a pack. */
5564
- async createEmoji(packId, options) {
5565
- const data = await this.client.rest.post(import_types37.Routes.packEmojis(packId), {
5566
- body: toEmojiCreateBody(options)
5567
- });
5568
- return toEmojiPayload(data);
5569
- }
5570
- /** Bulk-create emojis in a pack. */
5571
- async createEmojisBulk(packId, emojis) {
5572
- const data = await this.client.rest.post(
5573
- import_types37.Routes.packEmojisBulk(packId),
5574
- { body: { emojis: emojis.map(toEmojiCreateBody) } }
5575
- );
5576
- return {
5577
- success: data.success.map(toEmojiPayload),
5578
- failed: data.failed
5579
- };
5580
- }
5581
- /** Edit an emoji in a pack. */
5582
- async editEmoji(packId, emojiId, options) {
5583
- const data = await this.client.rest.patch(import_types37.Routes.packEmoji(packId, emojiId), {
5584
- body: toEmojiEditBody(options)
5585
- });
5586
- return toEmojiPayload(data);
5587
- }
5588
- /** Delete an emoji from a pack. */
5589
- async deleteEmoji(packId, emojiId) {
5590
- await this.client.rest.delete(import_types37.Routes.packEmoji(packId, emojiId));
5591
- }
5592
- /** List stickers in a pack. */
5593
- async listStickers(packId) {
5594
- const data = await this.client.rest.get(import_types37.Routes.packStickers(packId));
5595
- return data.map(toStickerPayload);
5596
- }
5597
- /** Create a sticker in a pack. */
5598
- async createSticker(packId, options) {
5599
- const data = await this.client.rest.post(import_types37.Routes.packStickers(packId), {
5600
- body: toStickerCreateBody(options)
5601
- });
5602
- return toStickerPayload(data);
5603
- }
5604
- /** Bulk-create stickers in a pack. */
5605
- async createStickersBulk(packId, stickers) {
5606
- const data = await this.client.rest.post(
5607
- import_types37.Routes.packStickersBulk(packId),
5608
- { body: { stickers: stickers.map(toStickerCreateBody) } }
5609
- );
5610
- return {
5611
- success: data.success.map(toStickerPayload),
5612
- failed: data.failed
5613
- };
5614
- }
5615
- /** Edit a sticker in a pack. */
5616
- async editSticker(packId, stickerId, options) {
5617
- const data = await this.client.rest.patch(import_types37.Routes.packSticker(packId, stickerId), {
5618
- body: toStickerEditBody(options)
5619
- });
5620
- return toStickerPayload(data);
5621
- }
5622
- /** Delete a sticker from a pack. */
5623
- async deleteSticker(packId, stickerId) {
5624
- await this.client.rest.delete(import_types37.Routes.packSticker(packId, stickerId));
5625
- }
5626
- };
5627
-
5628
6535
  // src/ClientCore/UserManager.ts
5629
- var import_collection11 = require("@fluxerjs/collection");
6536
+ var import_collection14 = require("@fluxerjs/collection");
5630
6537
  var import_types38 = require("@fluxerjs/types");
5631
6538
  var soft = (p) => p.catch(() => null);
5632
- var UserManager = class extends import_collection11.LimitedCollection {
6539
+ var UserManager = class extends import_collection14.LimitedCollection {
5633
6540
  constructor(client) {
5634
6541
  super({ maxSize: client.cache.limits.users });
5635
6542
  this.client = client;
@@ -5647,11 +6554,17 @@ var UserManager = class extends import_collection11.LimitedCollection {
5647
6554
  }
5648
6555
  return removed;
5649
6556
  }
5650
- /** Fetch a user by ID and update cache. */
5651
- async fetch(userId) {
6557
+ /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
6558
+ async fetch(userId, options) {
6559
+ const cached = this.get(userId);
6560
+ if (cached && !options?.force) return cached;
5652
6561
  const data = await this.client.rest.get(import_types38.Routes.user(userId));
5653
6562
  return this.client.getOrCreateUser(data);
5654
6563
  }
6564
+ /** Return a cached user, otherwise {@link fetch}. */
6565
+ async resolve(userId) {
6566
+ return this.get(userId) ?? this.fetch(userId);
6567
+ }
5655
6568
  /**
5656
6569
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
5657
6570
  * @example
@@ -5711,14 +6624,22 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5711
6624
  users;
5712
6625
  /** Cache limits, stats, sweeps, and cascade entry points. */
5713
6626
  cache;
5714
- /** Emoji/sticker pack REST wrappers (`/packs/*`). */
5715
- packs = new PackManager(this);
5716
- /** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
6627
+ /** Typed event handlers. Prefer `client.on(Events.*, ...)`. */
5717
6628
  events;
5718
6629
  /** The authenticated bot user. Null until READY is received. */
5719
6630
  user = null;
5720
6631
  /** Timestamp when the client became ready. Null until READY is received. */
5721
6632
  readyAt = null;
6633
+ /**
6634
+ * Milliseconds since {@link readyAt}, or `null` if the client is not ready.
6635
+ * @example
6636
+ * client.on(Events.Ready, () => {
6637
+ * console.log(client.uptime);
6638
+ * });
6639
+ */
6640
+ get uptime() {
6641
+ return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
6642
+ }
5722
6643
  /** @internal WebSocket manager. */
5723
6644
  _ws = null;
5724
6645
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
@@ -5740,7 +6661,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5740
6661
  cache: resolved.cache,
5741
6662
  defaultReplyPing: options.defaultReplyPing ?? true
5742
6663
  };
5743
- this.logger = options.logger ?? (0, import_util20.createLogger)({
6664
+ this.logger = options.logger ?? (0, import_util26.createLogger)({
5744
6665
  level: options.logLevel ?? "warn"
5745
6666
  });
5746
6667
  this.cache = new CacheController(this, resolved.limits);
@@ -5859,33 +6780,23 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5859
6780
  return fetchApplication(this);
5860
6781
  }
5861
6782
  /**
5862
- * Fetch OAuth2 applications owned by this bot.
5863
- * @returns Array of OAuth application objects
6783
+ * Fetch OAuth2 applications (`GET /oauth2/applications/@me`).
6784
+ * A bot token returns the bot application object (normalized to a one-element array).
6785
+ * A user token returns the owner's application list.
5864
6786
  */
5865
6787
  fetchOAuthApplications() {
5866
6788
  return fetchOAuthApplications(this);
5867
6789
  }
5868
- /**
5869
- * Check username#discriminator availability.
5870
- * @param username - Username to check
5871
- * @param discriminator - Discriminator to check
5872
- * @returns Availability result
5873
- */
5874
- checkUsernameTag(username, discriminator) {
5875
- return checkUsernameTag(this, username, discriminator);
5876
- }
5877
6790
  /**
5878
6791
  * Preload recent messages for multiple channels (batch endpoint).
5879
- * @param channelIds - Array of channel IDs to preload
5880
- * @returns Preload response with message counts/timestamps
6792
+ * Prefer this over {@link bulkFetchMessages} for bots (`bulkFetchMessages` is user-account only).
5881
6793
  */
5882
6794
  preloadMessages(channelIds) {
5883
6795
  return preloadMessages(this, channelIds);
5884
6796
  }
5885
6797
  /**
5886
6798
  * Preload recent messages (alternate endpoint).
5887
- * @param channelIds - Array of channel IDs to preload
5888
- * @returns Preload response with message counts/timestamps
6799
+ * Prefer this over {@link bulkFetchMessages} for bots.
5889
6800
  */
5890
6801
  preloadMessagesAlt(channelIds) {
5891
6802
  return preloadMessagesAlt(this, channelIds);
@@ -5893,6 +6804,14 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5893
6804
  bulkFetchMessages(requests, options = {}) {
5894
6805
  return bulkFetchMessages(this, requests, options);
5895
6806
  }
6807
+ /**
6808
+ * Search messages in the current bot scope (`POST /search/messages`, `scope: current`).
6809
+ * Other scopes are denied for bots (`BOT_SEARCH_SCOPE_UNAVAILABLE`).
6810
+ * Returns camelCase results (`hitsPerPage`) or `{ indexing: true }` while channels are indexed.
6811
+ */
6812
+ searchMessages(options) {
6813
+ return searchMessages(this, options);
6814
+ }
5896
6815
  /** @internal */
5897
6816
  _getMessageCache(channelId) {
5898
6817
  return this._messageCache.get(channelId);
@@ -5916,12 +6835,16 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5916
6835
  /**
5917
6836
  * Sweep cached messages (remove entries matching filter).
5918
6837
  * Prefer {@link CacheController.sweepMessages} (`client.cache.sweepMessages`).
6838
+ * The filter receives a hydrated {@link Message} (`createdAt`), not the stored wire payload.
5919
6839
  * @param filter - Predicate to test each message (return true to remove)
5920
6840
  * @param channelId - Optional channel ID to scope sweep
5921
6841
  * @returns Count of messages removed
5922
6842
  */
5923
6843
  sweepMessages(filter, channelId) {
5924
- return this._messageCache.sweep(filter, channelId);
6844
+ return this._messageCache.sweep(
6845
+ filter ? (data, chId) => filter(new Message(this, data), chId) : void 0,
6846
+ channelId
6847
+ );
5925
6848
  }
5926
6849
  /**
5927
6850
  * Sweep cached members across all guilds (remove entries matching filter).
@@ -5954,6 +6877,9 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5954
6877
  }
5955
6878
  /**
5956
6879
  * The underlying {@link WebSocketManager} (throws if not logged in).
6880
+ * Gateway heartbeat ACK latency: `client.ws.ping` (ms, or `-1` before the first ACK).
6881
+ * @example
6882
+ * console.log(client.ws.ping);
5957
6883
  * @throws {@link FluxerError} with {@link ErrorCodes.NotLoggedIn}
5958
6884
  */
5959
6885
  get ws() {
@@ -5992,6 +6918,37 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5992
6918
  if (options.nonce !== void 0) data.nonce = options.nonce;
5993
6919
  this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildMembers, d: data });
5994
6920
  }
6921
+ /**
6922
+ * Request guild member/online counts via gateway opcode 15.
6923
+ * Listen for `guildCountsUpdate`. Cached `guild.memberCount` / `guild.onlineCount` update when that event arrives.
6924
+ */
6925
+ requestGuildCounts(options) {
6926
+ const guildIds = [...new Set(options.guildIds.filter(Boolean))];
6927
+ if (!guildIds.length) {
6928
+ throw new import_util2.FluxerError("requestGuildCounts requires at least one guildId", {
6929
+ code: import_util.ErrorCodes.InvalidGatewayRequest
6930
+ });
6931
+ }
6932
+ const data = { guild_ids: guildIds };
6933
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6934
+ this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildCounts, d: data });
6935
+ }
6936
+ /**
6937
+ * Request per-channel member counts via gateway opcode 16.
6938
+ * Event-only: listen for `channelMemberCountsUpdate`. There is no `channel.memberCount` field.
6939
+ */
6940
+ requestChannelMemberCounts(options) {
6941
+ if (!options.guildId) {
6942
+ throw new import_util2.FluxerError("requestChannelMemberCounts requires guildId", {
6943
+ code: import_util.ErrorCodes.InvalidGatewayRequest
6944
+ });
6945
+ }
6946
+ const data = { guild_id: options.guildId };
6947
+ if (options.channelId !== void 0) data.channel_id = options.channelId;
6948
+ if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
6949
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6950
+ this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestChannelMemberCounts, d: data });
6951
+ }
5995
6952
  /**
5996
6953
  * Broadcast a gateway payload to all shards.
5997
6954
  * @param payload - Gateway send payload
@@ -6005,9 +6962,13 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6005
6962
  }
6006
6963
  /**
6007
6964
  * Connect to the gateway with a bot token.
6965
+ * @example
6966
+ * const client = new Client();
6967
+ * client.on(Events.Ready, () => console.log('Ready!'));
6968
+ * await client.login(process.env.FLUXER_BOT_TOKEN);
6008
6969
  * @param token - Bot token from the developer portal
6009
6970
  * @param options - Optional abort signal for cancellation
6010
- * @returns The token that was used (echo)
6971
+ * @returns This client (for chaining)
6011
6972
  * @throws {@link FluxerError} if already logged in or token is invalid
6012
6973
  */
6013
6974
  async login(token, options) {
@@ -6022,7 +6983,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6022
6983
  this.rest.setToken(token);
6023
6984
  try {
6024
6985
  this._ws = await connectClientGateway(this, token, options?.signal);
6025
- return token;
6986
+ return this;
6026
6987
  } catch (err) {
6027
6988
  this._ws?.destroy();
6028
6989
  this._ws = null;
@@ -6075,6 +7036,20 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6075
7036
  );
6076
7037
  }
6077
7038
  }
7039
+ /**
7040
+ * REST path helpers ({@link Routes}). Pass the path to {@link REST client.rest}.
7041
+ * Prefer high-level helpers (`channel.send()`, `guild.members.fetch()`) when they exist.
7042
+ *
7043
+ * @example
7044
+ * const channel = await client.rest.get(Client.Routes.channel(channelId));
7045
+ *
7046
+ * @example
7047
+ * await client.rest.post(Client.Routes.channelMessages(channelId), {
7048
+ * body: { content: 'hello' },
7049
+ * });
7050
+ *
7051
+ * @see {@link Routes}
7052
+ */
6078
7053
  static get Routes() {
6079
7054
  return import_types39.Routes;
6080
7055
  }