@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/client.js CHANGED
@@ -29,90 +29,13 @@ module.exports = __toCommonJS(SubpathClient_exports);
29
29
  var import_node_events3 = require("events");
30
30
  var import_rest3 = require("@fluxerjs/rest");
31
31
  var import_types39 = require("@fluxerjs/types");
32
- var import_util20 = require("@fluxerjs/util");
33
-
34
- // src/Domain/User.ts
35
- var import_types15 = require("@fluxerjs/types");
36
- var import_util9 = require("@fluxerjs/util");
37
-
38
- // src/Helpers/Constants.ts
39
- var import_rest = require("@fluxerjs/rest");
40
- var CDN_URL = "https://fluxerusercontent.com";
41
- var STATIC_CDN_URL = "https://fluxerstatic.com";
42
-
43
- // src/Helpers/Cdn.ts
44
- function mediaBase(options) {
45
- return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
46
- }
47
- function staticBase(options) {
48
- return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
49
- }
50
- function getExtension(hash, options) {
51
- const ext = options?.extension ?? "png";
52
- if (hash?.startsWith("a_")) return "gif";
53
- return ext;
54
- }
55
- function appendSize(options) {
56
- return options?.size ? `?size=${options.size}` : "";
57
- }
58
- function cdnAvatarURL(userId, avatarHash, options) {
59
- if (!avatarHash) return null;
60
- const ext = getExtension(avatarHash, options);
61
- const size = appendSize(options);
62
- return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
63
- }
64
- function cdnBannerURL(resourceId, bannerHash, options) {
65
- if (!bannerHash) return null;
66
- const ext = getExtension(bannerHash, options);
67
- const size = appendSize(options);
68
- return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
69
- }
70
- function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
71
- if (!avatarHash) return null;
72
- const ext = getExtension(avatarHash, options);
73
- const size = appendSize(options);
74
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
75
- }
76
- function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
77
- if (!bannerHash) return null;
78
- const ext = getExtension(bannerHash, options);
79
- const size = appendSize(options);
80
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
81
- }
82
- function cdnDefaultAvatarURL(userIdOrIndex, options) {
83
- const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
84
- return `${staticBase(options)}/avatars/${index}.png`;
85
- }
86
- function cdnGuildAssetURL(kind, id, hash, options) {
87
- if (!hash) return null;
88
- const size = options?.size ? `?size=${options.size}` : "";
89
- return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
90
- }
91
- function cdnEmojiURL(emojiId, animated, options) {
92
- const ext = animated ? "gif" : "png";
93
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
94
- }
95
- function cdnStickerURL(stickerId, animated, options) {
96
- const ext = animated ? "gif" : "png";
97
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
98
- }
99
-
100
- // src/Domain/Base.ts
101
- var Base = class {
102
- };
103
-
104
- // src/Domain/Channel/Base.ts
105
- var import_types8 = require("@fluxerjs/types");
106
- var import_util5 = require("@fluxerjs/util");
107
-
108
- // src/ClientCore/MessageManager.ts
109
- var import_collection3 = require("@fluxerjs/collection");
110
- var import_types6 = require("@fluxerjs/types");
32
+ var import_util26 = require("@fluxerjs/util");
111
33
 
112
34
  // src/Domain/Message/Message.ts
113
35
  var import_builders3 = require("@fluxerjs/builders");
114
- var import_collection2 = require("@fluxerjs/collection");
36
+ var import_collection3 = require("@fluxerjs/collection");
115
37
  var import_types5 = require("@fluxerjs/types");
38
+ var import_util6 = require("@fluxerjs/util");
116
39
 
117
40
  // src/ClientCore/SdkOptions/Attachments.ts
118
41
  function toMessageAttachmentEditWire(attachments) {
@@ -179,21 +102,66 @@ function toAttachmentUploadPlanResponse(data) {
179
102
  }
180
103
 
181
104
  // src/ClientCore/SdkOptions/Channels.ts
105
+ var import_util = require("@fluxerjs/util");
106
+ function toOverwriteWire(overwrite) {
107
+ return {
108
+ id: overwrite.id,
109
+ type: overwrite.type,
110
+ allow: overwrite.allow !== void 0 ? (0, import_util.resolvePermissionsToBitfield)(overwrite.allow) : "0",
111
+ deny: overwrite.deny !== void 0 ? (0, import_util.resolvePermissionsToBitfield)(overwrite.deny) : "0"
112
+ };
113
+ }
182
114
  function toChannelEditBody(options) {
183
115
  const body = {};
184
116
  if (options.name !== void 0) body.name = options.name;
185
117
  if (options.topic !== void 0) body.topic = options.topic;
118
+ if (options.url !== void 0) body.url = options.url;
186
119
  if (options.parentId !== void 0) body.parent_id = options.parentId;
187
120
  if (options.bitrate !== void 0) body.bitrate = options.bitrate;
188
121
  if (options.userLimit !== void 0) body.user_limit = options.userLimit;
122
+ if (options.voiceConnectionLimit !== void 0) {
123
+ body.voice_connection_limit = options.voiceConnectionLimit;
124
+ }
189
125
  if (options.nsfw !== void 0) body.nsfw = options.nsfw;
126
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
127
+ if (options.contentWarningLevel !== void 0) {
128
+ body.content_warning_level = options.contentWarningLevel;
129
+ }
130
+ if (options.contentWarningText !== void 0) {
131
+ body.content_warning_text = options.contentWarningText;
132
+ }
190
133
  if (options.rateLimitPerUser !== void 0) {
191
134
  body.rate_limit_per_user = options.rateLimitPerUser;
192
135
  }
193
136
  if (options.rtcRegion !== void 0) body.rtc_region = options.rtcRegion;
137
+ if (options.icon !== void 0) body.icon = options.icon;
138
+ if (options.permissionOverwrites !== void 0) {
139
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
140
+ }
141
+ return body;
142
+ }
143
+ function toChannelCreateBody(options) {
144
+ const body = { name: options.name, type: options.type };
145
+ if (options.topic !== void 0) body.topic = options.topic;
146
+ if (options.url !== void 0) body.url = options.url;
147
+ if (options.parentId !== void 0) body.parent_id = options.parentId;
148
+ if (options.bitrate !== void 0) body.bitrate = options.bitrate;
149
+ if (options.userLimit !== void 0) body.user_limit = options.userLimit;
150
+ if (options.voiceConnectionLimit !== void 0) {
151
+ body.voice_connection_limit = options.voiceConnectionLimit;
152
+ }
194
153
  if (options.permissionOverwrites !== void 0) {
195
- body.permission_overwrites = options.permissionOverwrites;
154
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
155
+ }
156
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
157
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
158
+ if (options.contentWarningLevel !== void 0) {
159
+ body.content_warning_level = options.contentWarningLevel;
160
+ }
161
+ if (options.contentWarningText !== void 0) {
162
+ body.content_warning_text = options.contentWarningText;
196
163
  }
164
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
197
165
  return body;
198
166
  }
199
167
  function toChannelInviteBody(options) {
@@ -204,6 +172,13 @@ function toChannelInviteBody(options) {
204
172
  if (options.temporary !== void 0) body.temporary = options.temporary;
205
173
  return body;
206
174
  }
175
+ function toGroupDmEditBody(options) {
176
+ const body = { type: 3 };
177
+ if (options.name !== void 0) body.name = options.name;
178
+ if (options.icon !== void 0) body.icon = options.icon;
179
+ if (options.nicks !== void 0) body.nicks = options.nicks;
180
+ return body;
181
+ }
207
182
 
208
183
  // src/ClientCore/SdkOptions/Discovery.ts
209
184
  function toDiscoveryBody(options) {
@@ -239,32 +214,8 @@ function toDiscoveryStatusPayload(data) {
239
214
  };
240
215
  }
241
216
 
242
- // src/ClientCore/SdkOptions/Expressions.ts
243
- function toEmojiCreateBody(options) {
244
- return { name: options.name, image: options.image };
245
- }
246
- function toEmojiEditBody(options) {
247
- return { name: options.name };
248
- }
249
- function toStickerCreateBody(options) {
250
- const body = {
251
- name: options.name,
252
- image: options.file
253
- };
254
- if (options.description !== void 0) body.description = options.description;
255
- if (options.tags !== void 0) body.tags = options.tags;
256
- return body;
257
- }
258
- function toStickerEditBody(options) {
259
- const body = {};
260
- if (options.name !== void 0) body.name = options.name;
261
- if (options.description !== void 0) body.description = options.description;
262
- if (options.tags !== void 0) body.tags = options.tags;
263
- return body;
264
- }
265
-
266
217
  // src/ClientCore/SdkOptions/Guild.ts
267
- var import_util = require("@fluxerjs/util");
218
+ var import_util2 = require("@fluxerjs/util");
268
219
  function toGuildEditBody(options) {
269
220
  const body = {};
270
221
  if (options.name !== void 0) body.name = options.name;
@@ -292,6 +243,16 @@ function toGuildEditBody(options) {
292
243
  body.splash_card_alignment = options.splashCardAlignment;
293
244
  }
294
245
  if (options.nsfwLevel !== void 0) body.nsfw_level = options.nsfwLevel;
246
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
247
+ if (options.contentWarningLevel !== void 0) {
248
+ body.content_warning_level = options.contentWarningLevel;
249
+ }
250
+ if (options.contentWarningText !== void 0) {
251
+ body.content_warning_text = options.contentWarningText;
252
+ }
253
+ if (options.messageHistoryCutoff !== void 0) {
254
+ body.message_history_cutoff = options.messageHistoryCutoff;
255
+ }
295
256
  if (options.features !== void 0) body.features = options.features;
296
257
  return body;
297
258
  }
@@ -301,6 +262,9 @@ function toGuildBanBody(options) {
301
262
  if (options.deleteMessageDays !== void 0) {
302
263
  body.delete_message_days = options.deleteMessageDays;
303
264
  }
265
+ if (options.deleteMessageSeconds !== void 0) {
266
+ body.delete_message_seconds = options.deleteMessageSeconds;
267
+ }
304
268
  if (options.banDurationSeconds !== void 0) {
305
269
  body.ban_duration_seconds = options.banDurationSeconds;
306
270
  }
@@ -315,18 +279,26 @@ function toChannelPositionBody(updates) {
315
279
  return row;
316
280
  });
317
281
  }
318
- function toRoleRequestBody(options) {
282
+ function toRolePermissionsBody(options) {
319
283
  const body = {};
284
+ if (options.permissions !== void 0) {
285
+ body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util2.resolvePermissionsToBitfield)(options.permissions);
286
+ }
287
+ return body;
288
+ }
289
+ function toRoleCreateBody(options) {
290
+ const body = { ...toRolePermissionsBody(options) };
291
+ if (options.name !== void 0) body.name = options.name;
292
+ if (options.color !== void 0) body.color = options.color;
293
+ return body;
294
+ }
295
+ function toRoleEditBody(options) {
296
+ const body = { ...toRolePermissionsBody(options) };
320
297
  if (options.name !== void 0) body.name = options.name;
321
298
  if (options.color !== void 0) body.color = options.color;
322
299
  if (options.hoist !== void 0) body.hoist = options.hoist;
323
300
  if (options.mentionable !== void 0) body.mentionable = options.mentionable;
324
- if (options.unicodeEmoji !== void 0) body.unicode_emoji = options.unicodeEmoji;
325
- if (options.position !== void 0) body.position = options.position;
326
301
  if (options.hoistPosition !== void 0) body.hoist_position = options.hoistPosition;
327
- if (options.permissions !== void 0) {
328
- body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util.resolvePermissionsToBitfield)(options.permissions);
329
- }
330
302
  return body;
331
303
  }
332
304
 
@@ -344,6 +316,8 @@ function toMemberSearchBody(options) {
344
316
  if (options.userCreatedAtLte !== void 0) body.user_created_at_lte = options.userCreatedAtLte;
345
317
  if (options.sortBy !== void 0) body.sort_by = options.sortBy;
346
318
  if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
319
+ if (options.joinSourceType !== void 0) body.join_source_type = options.joinSourceType;
320
+ if (options.sourceInviteCode !== void 0) body.source_invite_code = options.sourceInviteCode;
347
321
  return body;
348
322
  }
349
323
  function toMemberEditBody(options) {
@@ -356,6 +330,7 @@ function toMemberEditBody(options) {
356
330
  if (options.pronouns !== void 0) body.pronouns = options.pronouns;
357
331
  if (options.accentColor !== void 0) body.accent_color = options.accentColor;
358
332
  if (options.profileFlags !== void 0) body.profile_flags = options.profileFlags;
333
+ if (options.mentionFlags !== void 0) body.mention_flags = options.mentionFlags;
359
334
  if (options.mute !== void 0) body.mute = options.mute;
360
335
  if (options.deaf !== void 0) body.deaf = options.deaf;
361
336
  if (options.communicationDisabledUntil !== void 0) {
@@ -377,15 +352,54 @@ function toBulkFetchWire(requests) {
377
352
  ...r.around !== void 0 ? { around: r.around } : {}
378
353
  }));
379
354
  }
380
-
381
- // src/ClientCore/SdkOptions/Packs.ts
382
- function toPackInviteBody(options) {
383
- const body = {};
384
- if (options.maxUses !== void 0) body.max_uses = options.maxUses;
385
- if (options.maxAge !== void 0) body.max_age = options.maxAge;
386
- if (options.unique !== void 0) body.unique = options.unique;
355
+ function toMessageSearchBody(options = {}) {
356
+ const body = { scope: "current" };
357
+ if (options.content !== void 0) body.content = options.content;
358
+ if (options.contents !== void 0) body.contents = options.contents;
359
+ if (options.exactPhrases !== void 0) body.exact_phrases = options.exactPhrases;
360
+ if (options.channelIds !== void 0) {
361
+ body.channel_id = options.channelIds;
362
+ body.channel_ids = options.channelIds;
363
+ }
364
+ if (options.excludeChannelIds !== void 0) body.exclude_channel_id = options.excludeChannelIds;
365
+ if (options.contextGuildId !== void 0) body.context_guild_id = options.contextGuildId;
366
+ if (options.contextChannelId !== void 0) body.context_channel_id = options.contextChannelId;
367
+ if (options.hitsPerPage !== void 0) body.hits_per_page = options.hitsPerPage;
368
+ if (options.page !== void 0) body.page = options.page;
369
+ if (options.cursor !== void 0) body.cursor = options.cursor;
370
+ if (options.minId !== void 0) body.min_id = options.minId;
371
+ if (options.maxId !== void 0) body.max_id = options.maxId;
372
+ if (options.authorIds !== void 0) body.author_id = options.authorIds;
373
+ if (options.excludeAuthorIds !== void 0) body.exclude_author_id = options.excludeAuthorIds;
374
+ if (options.authorType !== void 0) body.author_type = options.authorType;
375
+ if (options.excludeAuthorType !== void 0) body.exclude_author_type = options.excludeAuthorType;
376
+ if (options.mentions !== void 0) body.mentions = options.mentions;
377
+ if (options.excludeMentions !== void 0) body.exclude_mentions = options.excludeMentions;
378
+ if (options.mentionEveryone !== void 0) body.mention_everyone = options.mentionEveryone;
379
+ if (options.pinned !== void 0) body.pinned = options.pinned;
380
+ if (options.includeNsfw !== void 0) body.include_nsfw = options.includeNsfw;
381
+ if (options.has !== void 0) body.has = options.has;
382
+ if (options.excludeHas !== void 0) body.exclude_has = options.excludeHas;
383
+ if (options.sortBy !== void 0) body.sort_by = options.sortBy;
384
+ if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
387
385
  return body;
388
386
  }
387
+ function isMessageSearchIndexing(data) {
388
+ return "indexing" in data && data.indexing === true;
389
+ }
390
+ function toMessageSearchResponse(data) {
391
+ if (isMessageSearchIndexing(data)) {
392
+ return { indexing: true };
393
+ }
394
+ return {
395
+ messages: data.messages,
396
+ channels: data.channels,
397
+ total: data.total,
398
+ hitsPerPage: data.hits_per_page,
399
+ page: data.page,
400
+ ...data.cursor !== void 0 ? { cursor: data.cursor } : {}
401
+ };
402
+ }
389
403
 
390
404
  // src/ClientCore/SdkOptions/Presence.ts
391
405
  function toPresenceWire(options) {
@@ -439,31 +453,31 @@ var import_builders = require("@fluxerjs/builders");
439
453
  var import_types = require("@fluxerjs/types");
440
454
 
441
455
  // src/LibErrors/ErrorCodes.ts
442
- var import_util2 = require("@fluxerjs/util");
456
+ var import_util3 = require("@fluxerjs/util");
443
457
 
444
458
  // src/LibErrors/FluxerError.ts
445
- var import_util3 = require("@fluxerjs/util");
459
+ var import_util4 = require("@fluxerjs/util");
446
460
 
447
461
  // src/Helpers/MessageUtils/Files.ts
448
462
  var FILE_FETCH_TIMEOUT_MS = 3e4;
449
463
  async function fetchFileBuffer(url, index) {
450
464
  if (!URL.canParse(url)) {
451
- throw new import_util3.FluxerError(`Invalid file URL at index ${index}: ${url}`, {
452
- code: import_util2.ErrorCodes.InvalidFileUrl
465
+ throw new import_util4.FluxerError(`Invalid file URL at index ${index}: ${url}`, {
466
+ code: import_util3.ErrorCodes.InvalidFileUrl
453
467
  });
454
468
  }
455
469
  let res;
456
470
  try {
457
471
  res = await fetch(url, { signal: AbortSignal.timeout(FILE_FETCH_TIMEOUT_MS) });
458
472
  } catch (err) {
459
- throw new import_util3.FluxerError(`Failed to fetch file from ${url}`, {
460
- code: import_util2.ErrorCodes.FileFetchFailed,
473
+ throw new import_util4.FluxerError(`Failed to fetch file from ${url}`, {
474
+ code: import_util3.ErrorCodes.FileFetchFailed,
461
475
  cause: err instanceof Error ? err : void 0
462
476
  });
463
477
  }
464
478
  if (!res.ok) {
465
- throw new import_util3.FluxerError(`Failed to fetch file from ${url}: ${res.status} ${res.statusText}`, {
466
- code: import_util2.ErrorCodes.FileFetchFailed
479
+ throw new import_util4.FluxerError(`Failed to fetch file from ${url}: ${res.status} ${res.statusText}`, {
480
+ code: import_util3.ErrorCodes.FileFetchFailed
467
481
  });
468
482
  }
469
483
  return res.arrayBuffer();
@@ -479,8 +493,8 @@ async function resolveMessageFiles(files) {
479
493
  } else if ("data" in f && f.data != null) {
480
494
  result.push({ name: f.name, data: f.data, filename });
481
495
  } else {
482
- throw new import_util3.FluxerError(`File at index ${i} must have either "data" or "url"`, {
483
- code: import_util2.ErrorCodes.InvalidAttachment
496
+ throw new import_util4.FluxerError(`File at index ${i} must have either "data" or "url"`, {
497
+ code: import_util3.ErrorCodes.InvalidAttachment
484
498
  });
485
499
  }
486
500
  }
@@ -505,6 +519,37 @@ function applyReplyPingSuppression(body) {
505
519
  function assignIfDefined(target, key, value) {
506
520
  if (value !== void 0) target[key] = value;
507
521
  }
522
+ function normalizeSendFiles(files) {
523
+ if (!files?.length) return void 0;
524
+ const normalized = [];
525
+ const metaFromBuilders = [];
526
+ let anyBuilderMeta = false;
527
+ for (let i = 0; i < files.length; i++) {
528
+ const file = files[i];
529
+ if (!file) continue;
530
+ if (file instanceof import_builders.AttachmentBuilder) {
531
+ normalized.push(file.toFileData());
532
+ const meta = {
533
+ id: i,
534
+ filename: file.filename,
535
+ ...file.description != null ? { description: file.description } : {},
536
+ ...file.spoiler ? { flags: import_types.MessageAttachmentFlags.IS_SPOILER } : {}
537
+ };
538
+ if (file.description != null || file.spoiler) anyBuilderMeta = true;
539
+ metaFromBuilders.push(meta);
540
+ } else {
541
+ normalized.push(file);
542
+ metaFromBuilders.push({
543
+ id: i,
544
+ filename: file.filename ?? file.name
545
+ });
546
+ }
547
+ }
548
+ return {
549
+ files: normalized,
550
+ metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
551
+ };
552
+ }
508
553
  function buildSendBody(options) {
509
554
  const body = typeof options === "string" ? { content: options } : options;
510
555
  const result = {};
@@ -512,16 +557,17 @@ function buildSendBody(options) {
512
557
  if (body.embeds?.length) {
513
558
  result.embeds = body.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
514
559
  }
560
+ const normalizedFiles = normalizeSendFiles(body.files);
515
561
  if (body.uploadedAttachments?.length) {
516
562
  result.attachments = body.uploadedAttachments;
517
- } else if (body.files?.length) {
563
+ } else if (normalizedFiles?.files.length) {
518
564
  result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
519
565
  id: a.id,
520
566
  filename: a.filename,
521
567
  ...a.title != null && { title: a.title },
522
568
  ...a.description != null && { description: a.description },
523
569
  ...a.flags != null && { flags: a.flags }
524
- })) : body.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
570
+ })) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
525
571
  }
526
572
  if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
527
573
  if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
@@ -581,7 +627,7 @@ async function prepareMessagePostPayload(options, defaults) {
581
627
  let normalized = options instanceof import_builders.MessagePayload ? messagePayloadToSendOptions(options) : options;
582
628
  if (typeof normalized === "string") {
583
629
  if (normalized.length === 0) {
584
- throw new import_util3.FluxerError("Cannot send an empty message", { code: import_util2.ErrorCodes.EmptyMessage });
630
+ throw new import_util4.FluxerError("Cannot send an empty message", { code: import_util3.ErrorCodes.EmptyMessage });
585
631
  }
586
632
  normalized = { content: normalized };
587
633
  } else {
@@ -592,20 +638,20 @@ async function prepareMessagePostPayload(options, defaults) {
592
638
  }
593
639
  const { replyTo, forward, ping, files, allowedMentions, uploadedAttachments, ...sendFields } = normalized;
594
640
  if (files?.length && uploadedAttachments?.length) {
595
- throw new import_util3.FluxerError("Cannot combine multipart files with uploadedAttachments", {
596
- code: import_util2.ErrorCodes.InvalidMessageOptions
641
+ throw new import_util4.FluxerError("Cannot combine multipart files with uploadedAttachments", {
642
+ code: import_util3.ErrorCodes.InvalidMessageOptions
597
643
  });
598
644
  }
599
645
  if (replyTo && forward) {
600
- throw new import_util3.FluxerError("Cannot combine replyTo and forward", {
601
- code: import_util2.ErrorCodes.InvalidMessageOptions
646
+ throw new import_util4.FluxerError("Cannot combine replyTo and forward", {
647
+ code: import_util3.ErrorCodes.InvalidMessageOptions
602
648
  });
603
649
  }
604
650
  const body = buildSendBody({ ...sendFields, files, allowedMentions, uploadedAttachments });
605
651
  if (forward) {
606
652
  if (!forward.channelId || !forward.messageId) {
607
- throw new import_util3.FluxerError("forward requires channelId and messageId", {
608
- code: import_util2.ErrorCodes.InvalidMessageOptions
653
+ throw new import_util4.FluxerError("forward requires channelId and messageId", {
654
+ code: import_util3.ErrorCodes.InvalidMessageOptions
609
655
  });
610
656
  }
611
657
  body.message_reference = toMessageReference(forward, true);
@@ -615,9 +661,10 @@ async function prepareMessagePostPayload(options, defaults) {
615
661
  } else if (allowedMentions?.repliedUser === false) {
616
662
  applyReplyPingSuppression(body);
617
663
  }
664
+ const resolvedFiles = normalizeSendFiles(files);
618
665
  return {
619
666
  body,
620
- files: !uploadedAttachments?.length && files?.length ? await resolveMessageFiles(files) : void 0
667
+ files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
621
668
  };
622
669
  }
623
670
 
@@ -629,9 +676,9 @@ var import_collection = require("@fluxerjs/collection");
629
676
  var import_types2 = require("@fluxerjs/types");
630
677
 
631
678
  // src/Helpers/HttpErrors.ts
632
- var import_rest2 = require("@fluxerjs/rest");
679
+ var import_rest = require("@fluxerjs/rest");
633
680
  function httpStatus(err) {
634
- if (err instanceof import_rest2.FluxerAPIError) return err.statusCode;
681
+ if (err instanceof import_rest.FluxerAPIError) return err.statusCode;
635
682
  if (typeof err === "object" && err !== null && "statusCode" in err) {
636
683
  const code = err.statusCode;
637
684
  return typeof code === "number" ? code : void 0;
@@ -644,15 +691,15 @@ function errorMessage(err, fallback) {
644
691
  return fallback;
645
692
  }
646
693
  function rethrowMapped(err, options) {
647
- if (err instanceof import_rest2.RateLimitError) throw err;
648
- if (err instanceof import_util3.FluxerError) throw err;
694
+ if (err instanceof import_rest.RateLimitError) throw err;
695
+ if (err instanceof import_util4.FluxerError) throw err;
649
696
  if (options.notFound && httpStatus(err) === 404) {
650
- throw new import_util3.FluxerError(options.notFound.message, {
697
+ throw new import_util4.FluxerError(options.notFound.message, {
651
698
  code: options.notFound.code,
652
699
  cause: err
653
700
  });
654
701
  }
655
- throw new import_util3.FluxerError(errorMessage(err, options.fallback), {
702
+ throw new import_util4.FluxerError(errorMessage(err, options.fallback), {
656
703
  code: options.code,
657
704
  cause: err
658
705
  });
@@ -666,14 +713,22 @@ function qs(params) {
666
713
  return out ? `?${out}` : "";
667
714
  }
668
715
 
716
+ // src/Domain/Base.ts
717
+ var Base = class {
718
+ };
719
+
669
720
  // src/Domain/Message/MessageReaction.ts
670
- var MessageReaction = class extends Base {
721
+ var MessageReaction = class _MessageReaction extends Base {
671
722
  client;
672
723
  messageId;
673
724
  channelId;
674
725
  guildId;
675
726
  emoji;
676
- /** Raw gateway payload for low-level access. */
727
+ /** Total count when hydrated from a message payload; `1` for gateway add events. */
728
+ count;
729
+ /** Whether the current user reacted (message payload); false for gateway remove. */
730
+ me;
731
+ /** Raw gateway payload for low-level access (null when built from a message aggregate). */
677
732
  _data;
678
733
  constructor(client, data) {
679
734
  super();
@@ -687,6 +742,26 @@ var MessageReaction = class extends Base {
687
742
  ...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
688
743
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
689
744
  };
745
+ this.count = 1;
746
+ this.me = false;
747
+ }
748
+ /** Build a reaction aggregate from a message's `reactions` array entry. */
749
+ static fromMessage(message, data) {
750
+ const reaction = new _MessageReaction(message.client, {
751
+ user_id: message.client.user?.id ?? "0",
752
+ message_id: message.id,
753
+ channel_id: message.channelId,
754
+ guild_id: message.guildId ?? void 0,
755
+ emoji: {
756
+ name: data.emoji.name,
757
+ id: data.emoji.id ?? void 0,
758
+ animated: data.emoji.animated ?? void 0
759
+ }
760
+ });
761
+ Object.defineProperty(reaction, "_data", { value: null });
762
+ reaction.count = data.count;
763
+ reaction.me = data.me ?? false;
764
+ return reaction;
690
765
  }
691
766
  /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
692
767
  get emojiIdentifier() {
@@ -696,12 +771,23 @@ var MessageReaction = class extends Base {
696
771
  get guild() {
697
772
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
698
773
  }
774
+ /** Cached message this reaction belongs to, or null if the message was not cached. */
775
+ get message() {
776
+ const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
777
+ return cached ? new Message(this.client, cached) : null;
778
+ }
779
+ /** Cached text-capable channel, or null if uncached / not text-based. */
780
+ get channel() {
781
+ const channel = this.client.channels.get(this.channelId);
782
+ return channel?.isTextBased() ? channel : null;
783
+ }
699
784
  /**
700
- * Fetch the message this reaction belongs to.
701
- * Use when you need to edit, delete, or otherwise interact with the message.
785
+ * Fetch the message this reaction belongs to (cache first, then REST).
702
786
  * @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
703
787
  */
704
788
  async fetchMessage() {
789
+ const cached = this.message;
790
+ if (cached) return cached;
705
791
  try {
706
792
  const data = await this.client.rest.get(
707
793
  import_types2.Routes.channelMessage(this.channelId, this.messageId)
@@ -710,7 +796,7 @@ var MessageReaction = class extends Base {
710
796
  } catch (err) {
711
797
  rethrowMapped(err, {
712
798
  notFound: {
713
- code: import_util2.ErrorCodes.MessageNotFound,
799
+ code: import_util3.ErrorCodes.MessageNotFound,
714
800
  message: `Message ${this.messageId} not found in channel ${this.channelId}`
715
801
  },
716
802
  fallback: `Failed to fetch message ${this.messageId}`
@@ -772,11 +858,17 @@ var Events = {
772
858
  WebhooksUpdate: "webhooksUpdate",
773
859
  Resumed: "resumed",
774
860
  Error: "error",
775
- Debug: "debug"
861
+ Debug: "debug",
862
+ ShardReady: "shardReady",
863
+ ShardResumed: "shardResumed",
864
+ ShardDisconnect: "shardDisconnect",
865
+ ShardReconnecting: "shardReconnecting",
866
+ ShardError: "shardError",
867
+ ShardingRequired: "shardingRequired"
776
868
  };
777
869
 
778
870
  // src/Helpers/ReactionCollector.ts
779
- var ReactionCollector = class extends import_node_events.EventEmitter {
871
+ var ReactionCollector = class _ReactionCollector extends import_node_events.EventEmitter {
780
872
  client;
781
873
  messageId;
782
874
  channelId;
@@ -819,15 +911,17 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
819
911
  ...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
820
912
  }
821
913
  });
822
- const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
914
+ const cached = this.client.users.get(entry.userId);
915
+ const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
916
+ {
823
917
  id: entry.userId,
824
918
  username: "Unknown",
825
919
  discriminator: "0",
826
- global_name: null,
920
+ globalName: null,
827
921
  avatar: null,
828
- avatar_color: null,
829
- flags: 0
830
- });
922
+ bot: false,
923
+ system: false
924
+ };
831
925
  this._collect(reaction, user, entry.userId);
832
926
  }
833
927
  };
@@ -859,6 +953,21 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
859
953
  }
860
954
  this.emit("end", this.collected, reason);
861
955
  }
956
+ /**
957
+ * One-shot helper used by {@link Message.awaitReactions}.
958
+ * Resolves with the collected reactions when the collector ends.
959
+ * Rejects if `options.errors` includes the end reason.
960
+ */
961
+ static awaitReactions(client, messageId, channelId, options) {
962
+ const errors = options?.errors ?? [];
963
+ return new Promise((resolve, reject) => {
964
+ const collector = new _ReactionCollector(client, messageId, channelId, options);
965
+ collector.on("end", (collected, reason) => {
966
+ if (errors.includes(reason)) reject(collected);
967
+ else resolve(collected);
968
+ });
969
+ });
970
+ }
862
971
  on(event, listener) {
863
972
  return super.on(event, listener);
864
973
  }
@@ -867,127 +976,281 @@ var ReactionCollector = class extends import_node_events.EventEmitter {
867
976
  }
868
977
  };
869
978
 
870
- // src/Domain/Message/Reactions.ts
871
- var import_types3 = require("@fluxerjs/types");
872
- var import_util4 = require("@fluxerjs/util");
873
- async function emojiPath(message, emoji) {
874
- return message.client.resolveEmoji(emoji, message.guildId);
875
- }
876
- function toReactionEmoji(emoji) {
877
- if (typeof emoji !== "string") {
878
- return {
879
- name: emoji.name,
880
- ...emoji.id !== void 0 ? { id: emoji.id } : {},
881
- ...emoji.animated !== void 0 ? { animated: emoji.animated } : {}
882
- };
883
- }
884
- const animatedWire = /^a:(\w+):(\d+)$/.exec(emoji);
885
- if (animatedWire) {
886
- return { name: animatedWire[1], id: animatedWire[2], animated: true };
887
- }
888
- const parsed = (0, import_util4.parseEmoji)(emoji);
889
- if (parsed?.id) {
890
- return {
891
- name: parsed.name,
892
- id: parsed.id,
893
- ...parsed.animated ? { animated: true } : {}
894
- };
895
- }
896
- let name = emoji;
897
- try {
898
- name = decodeURIComponent(emoji);
899
- } catch {
900
- }
901
- return { name: parsed?.name ?? name };
902
- }
903
- function emitOwnReactionAdd(message, wireOrInput) {
904
- const user = message.client.user;
905
- if (!user) return;
906
- const emojiPayload = toReactionEmoji(wireOrInput);
907
- const reaction = new MessageReaction(message.client, {
908
- user_id: user.id,
909
- channel_id: message.channelId,
910
- message_id: message.id,
911
- guild_id: message.guildId ?? void 0,
912
- emoji: {
913
- name: emojiPayload.name,
914
- ...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
915
- ...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
916
- }
917
- });
918
- const payload = {
919
- reaction,
920
- user,
921
- messageId: message.id,
922
- channelId: message.channelId,
923
- emoji: emojiPayload,
924
- userId: user.id
979
+ // src/Domain/Message/Attachment.ts
980
+ function toMessageAttachment(data) {
981
+ return {
982
+ id: data.id,
983
+ filename: data.filename,
984
+ title: data.title ?? null,
985
+ description: data.description ?? null,
986
+ contentType: data.content_type ?? null,
987
+ contentHash: data.content_hash ?? null,
988
+ size: data.size,
989
+ url: data.url ?? null,
990
+ proxyUrl: data.proxy_url ?? null,
991
+ width: data.width ?? null,
992
+ height: data.height ?? null,
993
+ placeholder: data.placeholder ?? null,
994
+ flags: data.flags ?? 0,
995
+ nsfw: data.nsfw ?? false,
996
+ duration: data.duration ?? null,
997
+ waveform: data.waveform ?? null,
998
+ expiresAt: data.expires_at ? new Date(data.expires_at) : null,
999
+ expired: data.expired ?? false
925
1000
  };
926
- message.client.emit(Events.MessageReactionAdd, payload);
927
- }
928
- async function reactToMessage(message, emoji) {
929
- const wire = await emojiPath(message, emoji);
930
- await message.client.rest.put(
931
- import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
932
- );
933
- emitOwnReactionAdd(message, wire);
934
- }
935
- async function removeMessageReaction(message, emoji, userId) {
936
- const e = await emojiPath(message, emoji);
937
- const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
938
- await message.client.rest.delete(route);
939
- }
940
- async function removeAllMessageReactions(message) {
941
- await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
942
- }
943
- async function removeMessageReactionEmoji(message, emoji) {
944
- const e = await emojiPath(message, emoji);
945
- await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
946
1001
  }
947
- async function fetchMessageReactionUsers(message, emoji, options) {
948
- return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
1002
+
1003
+ // src/Domain/Message/Embed.ts
1004
+ function toMessageEmbedAuthor(data) {
1005
+ return {
1006
+ name: data.name ?? null,
1007
+ url: data.url ?? null,
1008
+ iconUrl: data.icon_url ?? null,
1009
+ proxyIconUrl: data.proxy_icon_url ?? null
1010
+ };
949
1011
  }
950
- async function fetchMessageReactionUsersPage(message, emoji, options) {
951
- const e = await emojiPath(message, emoji);
952
- const params = new URLSearchParams();
953
- if (options?.limit != null) params.set("limit", String(options.limit));
954
- if (options?.after) params.set("after", options.after);
955
- const qs2 = params.toString();
956
- const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
957
- const data = await message.client.rest.get(route);
958
- if (Array.isArray(data)) {
959
- return {
960
- users: data.map((u) => message.client.getOrCreateUser(u)),
961
- hasMore: false,
962
- nextAfter: null
963
- };
964
- }
965
- const list = data.items ?? data.users ?? [];
1012
+ function toMessageEmbedFooter(data) {
966
1013
  return {
967
- users: list.map((u) => message.client.getOrCreateUser(u)),
968
- hasMore: data.has_more ?? false,
969
- nextAfter: data.next_after ?? null
1014
+ text: data.text,
1015
+ iconUrl: data.icon_url ?? null,
1016
+ proxyIconUrl: data.proxy_icon_url ?? null
970
1017
  };
971
1018
  }
972
-
973
- // src/Domain/Message/Send.ts
974
- var import_builders2 = require("@fluxerjs/builders");
975
- var import_types4 = require("@fluxerjs/types");
976
- function toReplyTarget(ref) {
1019
+ function toMessageEmbedMedia(data) {
977
1020
  return {
978
- channelId: ref.channel_id,
979
- messageId: ref.message_id,
980
- ...ref.guild_id != null ? { guildId: ref.guild_id } : {}
1021
+ url: data.url,
1022
+ proxyUrl: data.proxy_url ?? null,
1023
+ contentType: data.content_type ?? null,
1024
+ contentHash: data.content_hash ?? null,
1025
+ width: data.width ?? null,
1026
+ height: data.height ?? null,
1027
+ description: data.description ?? null,
1028
+ placeholder: data.placeholder ?? null,
1029
+ duration: data.duration ?? null,
1030
+ flags: data.flags ?? null
981
1031
  };
982
1032
  }
983
- function toSendOptions(content) {
984
- if (typeof content === "string") return { content };
985
- if (content instanceof import_builders2.MessagePayload) return messagePayloadToSendOptions(content);
986
- return { ...content };
1033
+ function toMessageEmbed(data) {
1034
+ const full = data;
1035
+ return {
1036
+ type: data.type ?? "rich",
1037
+ url: data.url ?? null,
1038
+ title: data.title ?? null,
1039
+ color: data.color ?? null,
1040
+ timestamp: data.timestamp ? new Date(data.timestamp) : null,
1041
+ description: data.description ?? null,
1042
+ author: data.author ? toMessageEmbedAuthor(data.author) : null,
1043
+ image: data.image ? toMessageEmbedMedia(data.image) : null,
1044
+ thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
1045
+ footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
1046
+ fields: (data.fields ?? []).map((f) => ({
1047
+ name: f.name,
1048
+ value: f.value,
1049
+ inline: f.inline ?? false
1050
+ })),
1051
+ provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
1052
+ video: data.video ? toMessageEmbedMedia(data.video) : null,
1053
+ audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
1054
+ nsfw: data.nsfw ?? false,
1055
+ children: (full.children ?? []).map(toMessageEmbed),
1056
+ html: full.html ?? null,
1057
+ htmlWidth: full.html_width ?? null,
1058
+ htmlHeight: full.html_height ?? null
1059
+ };
987
1060
  }
988
- async function createMessageBody(content, referenced_message, ping) {
1061
+
1062
+ // src/Domain/Message/MessageReactionManager.ts
1063
+ var import_collection2 = require("@fluxerjs/collection");
1064
+ var MessageReactionManager = class {
1065
+ constructor(message) {
1066
+ this.message = message;
1067
+ }
1068
+ _cache = new import_collection2.Collection();
1069
+ /** Reactions keyed by unicode name or `name:id`. */
1070
+ get cache() {
1071
+ return this._cache;
1072
+ }
1073
+ get size() {
1074
+ return this._cache.size;
1075
+ }
1076
+ [Symbol.iterator]() {
1077
+ return this._cache.values();
1078
+ }
1079
+ /** @internal Sync from an API message payload. */
1080
+ _patch(reactions) {
1081
+ this._cache.clear();
1082
+ for (const data of reactions ?? []) {
1083
+ const reaction = MessageReaction.fromMessage(this.message, data);
1084
+ this._cache.set(reaction.emojiIdentifier, reaction);
1085
+ }
1086
+ }
1087
+ };
1088
+
1089
+ // src/Domain/Message/MessageSticker.ts
1090
+ var import_util5 = require("@fluxerjs/util");
1091
+
1092
+ // src/Helpers/Constants.ts
1093
+ var import_rest2 = require("@fluxerjs/rest");
1094
+ var CDN_URL = "https://fluxerusercontent.com";
1095
+ var STATIC_CDN_URL = "https://fluxerstatic.com";
1096
+
1097
+ // src/Helpers/Cdn.ts
1098
+ function mediaBase(options) {
1099
+ return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1100
+ }
1101
+ function staticBase(options) {
1102
+ return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
1103
+ }
1104
+ function getExtension(hash, options) {
1105
+ const ext = options?.extension ?? "png";
1106
+ if (hash?.startsWith("a_")) return "gif";
1107
+ return ext;
1108
+ }
1109
+ function appendSize(options) {
1110
+ return options?.size ? `?size=${options.size}` : "";
1111
+ }
1112
+ function cdnAvatarURL(userId, avatarHash, options) {
1113
+ if (!avatarHash) return null;
1114
+ const ext = getExtension(avatarHash, options);
1115
+ const size = appendSize(options);
1116
+ return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1117
+ }
1118
+ function cdnBannerURL(resourceId, bannerHash, options) {
1119
+ if (!bannerHash) return null;
1120
+ const ext = getExtension(bannerHash, options);
1121
+ const size = appendSize(options);
1122
+ return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1123
+ }
1124
+ function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1125
+ if (!avatarHash) return null;
1126
+ const ext = getExtension(avatarHash, options);
1127
+ const size = appendSize(options);
1128
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1129
+ }
1130
+ function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1131
+ if (!bannerHash) return null;
1132
+ const ext = getExtension(bannerHash, options);
1133
+ const size = appendSize(options);
1134
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1135
+ }
1136
+ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1137
+ const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
1138
+ return `${staticBase(options)}/avatars/${index}.png`;
1139
+ }
1140
+ function cdnGuildAssetURL(kind, id, hash, options) {
1141
+ if (!hash) return null;
1142
+ const size = options?.size ? `?size=${options.size}` : "";
1143
+ return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1144
+ }
1145
+ function cdnEmojiURL(emojiId, animated, options) {
1146
+ const ext = animated ? "gif" : "png";
1147
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1148
+ }
1149
+ function cdnStickerURL(stickerId, animated, options) {
1150
+ const ext = animated ? "gif" : "png";
1151
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1152
+ }
1153
+
1154
+ // src/Domain/Message/MessageSticker.ts
1155
+ var MessageSticker = class extends Base {
1156
+ client;
1157
+ id;
1158
+ name;
1159
+ description;
1160
+ tags;
1161
+ animated;
1162
+ constructor(client, data) {
1163
+ super();
1164
+ this.client = client;
1165
+ this.id = data.id;
1166
+ this.name = data.name;
1167
+ this.description = data.description ?? "";
1168
+ this.tags = data.tags ?? [];
1169
+ this.animated = data.animated ?? false;
1170
+ }
1171
+ /** CDN URL for this sticker image. */
1172
+ get url() {
1173
+ return cdnStickerURL(this.id, this.animated, {
1174
+ mediaBase: this.client.instance.endpoints.media
1175
+ });
1176
+ }
1177
+ /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
1178
+ get createdTimestamp() {
1179
+ return import_util5.SnowflakeUtil.timestampFromSnowflake(this.id);
1180
+ }
1181
+ /** Date when this sticker was created, derived from its snowflake ID. */
1182
+ get createdAt() {
1183
+ return import_util5.SnowflakeUtil.dateFromSnowflake(this.id);
1184
+ }
1185
+ };
1186
+
1187
+ // src/Domain/Message/Reactions.ts
1188
+ var import_types3 = require("@fluxerjs/types");
1189
+ async function emojiPath(message, emoji) {
1190
+ return message.client.resolveEmoji(emoji, message.guildId);
1191
+ }
1192
+ async function reactToMessage(message, emoji) {
1193
+ const wire = await emojiPath(message, emoji);
1194
+ await message.client.rest.put(
1195
+ import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, wire)
1196
+ );
1197
+ }
1198
+ async function removeMessageReaction(message, emoji, userId) {
1199
+ const e = await emojiPath(message, emoji);
1200
+ const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
1201
+ await message.client.rest.delete(route);
1202
+ }
1203
+ async function removeAllMessageReactions(message) {
1204
+ await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
1205
+ }
1206
+ async function removeMessageReactionEmoji(message, emoji) {
1207
+ const e = await emojiPath(message, emoji);
1208
+ await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
1209
+ }
1210
+ async function fetchMessageReactionUsers(message, emoji, options) {
1211
+ return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
1212
+ }
1213
+ async function fetchMessageReactionUsersPage(message, emoji, options) {
1214
+ const e = await emojiPath(message, emoji);
1215
+ const params = new URLSearchParams();
1216
+ if (options?.limit != null) params.set("limit", String(options.limit));
1217
+ if (options?.after) params.set("after", options.after);
1218
+ const qs2 = params.toString();
1219
+ const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs2 ? `?${qs2}` : "");
1220
+ const data = await message.client.rest.get(route);
1221
+ if (Array.isArray(data)) {
1222
+ return {
1223
+ users: data.map((u) => message.client.getOrCreateUser(u)),
1224
+ hasMore: false,
1225
+ nextAfter: null
1226
+ };
1227
+ }
1228
+ const list = data.items ?? data.users ?? [];
1229
+ return {
1230
+ users: list.map((u) => message.client.getOrCreateUser(u)),
1231
+ hasMore: data.has_more ?? false,
1232
+ nextAfter: data.next_after ?? null
1233
+ };
1234
+ }
1235
+
1236
+ // src/Domain/Message/Send.ts
1237
+ var import_builders2 = require("@fluxerjs/builders");
1238
+ var import_types4 = require("@fluxerjs/types");
1239
+ function toReplyTarget(ref) {
1240
+ return {
1241
+ channelId: ref.channel_id,
1242
+ messageId: ref.message_id,
1243
+ ...ref.guild_id != null ? { guildId: ref.guild_id } : {}
1244
+ };
1245
+ }
1246
+ function toSendOptions(content) {
1247
+ if (typeof content === "string") return { content };
1248
+ if (content instanceof import_builders2.MessagePayload) return messagePayloadToSendOptions(content);
1249
+ return { ...content };
1250
+ }
1251
+ async function createMessageBody(content, referenced_message, ping) {
989
1252
  if (typeof content === "string" && content.length === 0) {
990
- throw new import_util3.FluxerError("Cannot send an empty message", { code: import_util2.ErrorCodes.EmptyMessage });
1253
+ throw new import_util4.FluxerError("Cannot send an empty message", { code: import_util3.ErrorCodes.EmptyMessage });
991
1254
  }
992
1255
  const opts = toSendOptions(content);
993
1256
  if (referenced_message) {
@@ -1036,7 +1299,33 @@ async function replyToMessage(message, options, replyOptions) {
1036
1299
  }
1037
1300
 
1038
1301
  // src/Domain/Message/Message.ts
1302
+ function toMessageCall(data) {
1303
+ return {
1304
+ participants: data.participants,
1305
+ endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
1306
+ };
1307
+ }
1308
+ function toMessageSnapshot(client, data) {
1309
+ return {
1310
+ content: data.content ?? null,
1311
+ createdAt: new Date(data.timestamp),
1312
+ editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
1313
+ mentionUserIds: data.mentions ?? [],
1314
+ mentionRoles: data.mention_roles ?? [],
1315
+ embeds: (data.embeds ?? []).map(toMessageEmbed),
1316
+ attachments: (data.attachments ?? []).map(toMessageAttachment),
1317
+ stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
1318
+ ...data.type !== void 0 ? { type: data.type } : {}
1319
+ };
1320
+ }
1321
+ function resolveMessageFlags(flags) {
1322
+ if (flags === void 0) return void 0;
1323
+ if (typeof flags === "number") return flags;
1324
+ return Number(import_util6.MessageFlagsBitField.resolve(flags));
1325
+ }
1039
1326
  var Message = class _Message extends Base {
1327
+ /** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
1328
+ partial = false;
1040
1329
  /** The {@link Client} that instantiated this message. */
1041
1330
  client;
1042
1331
  /** Snowflake ID of this message. */
@@ -1065,7 +1354,7 @@ var Message = class _Message extends Base {
1065
1354
  mentionEveryone;
1066
1355
  /** Whether this is a text-to-speech message. */
1067
1356
  tts;
1068
- /** Embedded content (rich previews, etc.). */
1357
+ /** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
1069
1358
  embeds;
1070
1359
  /** Stickers sent with the message. */
1071
1360
  stickers;
@@ -1087,26 +1376,41 @@ var Message = class _Message extends Base {
1087
1376
  mentionRoles;
1088
1377
  /** Client-side nonce for deduplication. */
1089
1378
  nonce;
1090
- /** Cached text/DM/guild channel, or null if uncached. */
1379
+ /**
1380
+ * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1381
+ * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
1382
+ */
1091
1383
  get channel() {
1092
- return this.client.channels.get(this.channelId) ?? null;
1384
+ const channel = this.client.channels.get(this.channelId) ?? null;
1385
+ return channel?.isTextBased() ? channel : null;
1093
1386
  }
1094
1387
  /** Cached guild, or null for DMs / uncached. */
1095
1388
  get guild() {
1096
1389
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
1097
1390
  }
1098
- /** Fetch and resolve the channel this message is in. */
1391
+ /** Cached guild member for the author, or null in DMs / if uncached. */
1392
+ get member() {
1393
+ return this.guild?.members.get(this.author.id) ?? null;
1394
+ }
1395
+ /**
1396
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1397
+ * has {@link Channel.delete} and {@link Channel.send}.
1398
+ * @example
1399
+ * const channel = await message.resolveChannel();
1400
+ * await channel.delete();
1401
+ */
1099
1402
  async resolveChannel() {
1100
1403
  return this.client.channels.resolve(this.channelId);
1101
1404
  }
1102
- /** Fetch and resolve the guild, or null if a DM. */
1405
+ /**
1406
+ * Fetch and resolve the guild, or null if a DM.
1407
+ * Propagates network/auth errors; only returns null when there is no guildId.
1408
+ * @example
1409
+ * const guild = await message.resolveGuild();
1410
+ */
1103
1411
  async resolveGuild() {
1104
1412
  if (!this.guildId) return null;
1105
- try {
1106
- return await this.client.guilds.resolve(this.guildId);
1107
- } catch {
1108
- return null;
1109
- }
1413
+ return this.client.guilds.resolve(this.guildId);
1110
1414
  }
1111
1415
  /**
1112
1416
  * Construct a message from API data.
@@ -1123,29 +1427,73 @@ var Message = class _Message extends Base {
1123
1427
  this.createdAt = new Date(data.timestamp);
1124
1428
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1125
1429
  this.pinned = data.pinned;
1126
- this.attachments = new import_collection2.Collection();
1127
- for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
1430
+ this.attachments = new import_collection3.Collection();
1431
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1128
1432
  this.type = data.type ?? import_types5.MessageType.Default;
1129
- this.flags = data.flags ?? 0;
1433
+ this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
1130
1434
  this.mentionEveryone = data.mention_everyone ?? false;
1131
1435
  this.tts = data.tts ?? false;
1132
- this.embeds = data.embeds ?? [];
1133
- this.stickers = data.stickers ?? [];
1134
- this.reactions = data.reactions ?? [];
1135
- this.messageReference = data.message_reference ?? null;
1136
- this.messageSnapshots = data.message_snapshots ?? [];
1137
- this.call = data.call ?? null;
1436
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1437
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
1438
+ this.reactions = new MessageReactionManager(this);
1439
+ this.reactions._patch(data.reactions);
1440
+ this.messageReference = data.message_reference ? {
1441
+ channelId: data.message_reference.channel_id,
1442
+ messageId: data.message_reference.message_id,
1443
+ guildId: data.message_reference.guild_id ?? null,
1444
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1445
+ } : null;
1446
+ this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
1447
+ this.call = data.call ? toMessageCall(data.call) : null;
1138
1448
  this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
1139
1449
  this.webhookId = data.webhook_id ?? null;
1140
1450
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1141
1451
  this.mentionRoles = data.mention_roles ?? [];
1142
1452
  this.nonce = data.nonce ?? null;
1143
1453
  }
1144
- /** Send a message in this channel without replying. */
1454
+ /**
1455
+ * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
1456
+ * @internal
1457
+ */
1458
+ _patch(data) {
1459
+ this.content = data.content;
1460
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1461
+ this.pinned = data.pinned;
1462
+ this.attachments.clear();
1463
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1464
+ this.flags = new import_util6.MessageFlagsBitField(BigInt(data.flags ?? 0));
1465
+ this.mentionEveryone = data.mention_everyone ?? false;
1466
+ this.tts = data.tts ?? false;
1467
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1468
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1469
+ this.reactions._patch(data.reactions);
1470
+ this.messageReference = data.message_reference ? {
1471
+ channelId: data.message_reference.channel_id,
1472
+ messageId: data.message_reference.message_id,
1473
+ guildId: data.message_reference.guild_id ?? null,
1474
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1475
+ } : null;
1476
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
1477
+ (s) => toMessageSnapshot(this.client, s)
1478
+ );
1479
+ this.call = data.call ? toMessageCall(data.call) : null;
1480
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
1481
+ this.webhookId = data.webhook_id ?? null;
1482
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1483
+ this.mentionRoles = data.mention_roles ?? [];
1484
+ this.nonce = data.nonce ?? null;
1485
+ }
1486
+ /**
1487
+ * Send a standalone message in this channel (not a reply).
1488
+ * Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
1489
+ */
1145
1490
  async send(options) {
1146
1491
  return sendMessage(this, options);
1147
1492
  }
1148
- /** Send a message to another channel by ID. */
1493
+ /**
1494
+ * Send a message to another channel by ID.
1495
+ * Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
1496
+ */
1149
1497
  async sendTo(channelId, options) {
1150
1498
  return sendMessageTo(this, channelId, options);
1151
1499
  }
@@ -1159,6 +1507,16 @@ var Message = class _Message extends Base {
1159
1507
  async reply(options, replyOptions) {
1160
1508
  return replyToMessage(this, options, replyOptions);
1161
1509
  }
1510
+ /**
1511
+ * Hydrate a partial message, or return the message as-is.
1512
+ * @example
1513
+ * client.on(Events.MessageUpdate, async (_old, msg) => {
1514
+ * const message = await Message.resolve(msg);
1515
+ * });
1516
+ */
1517
+ static async resolve(message) {
1518
+ return message.partial ? message.fetch() : message;
1519
+ }
1162
1520
  /** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
1163
1521
  static async _createMessageBody(content, referenced_message, ping) {
1164
1522
  return createMessageBody(content, referenced_message, ping);
@@ -1171,7 +1529,7 @@ var Message = class _Message extends Base {
1171
1529
  async edit(options) {
1172
1530
  const body = {};
1173
1531
  if (options.content !== void 0) body.content = options.content;
1174
- if (options.embeds?.length) {
1532
+ if (options.embeds !== void 0) {
1175
1533
  body.embeds = options.embeds.map(
1176
1534
  (e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e
1177
1535
  );
@@ -1179,7 +1537,8 @@ var Message = class _Message extends Base {
1179
1537
  if (options.allowedMentions) {
1180
1538
  body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
1181
1539
  }
1182
- if (options.flags !== void 0) body.flags = options.flags;
1540
+ const flags = resolveMessageFlags(options.flags);
1541
+ if (flags !== void 0) body.flags = flags;
1183
1542
  if (options.attachments !== void 0) {
1184
1543
  body.attachments = toMessageAttachmentEditWire(options.attachments);
1185
1544
  }
@@ -1194,6 +1553,13 @@ var Message = class _Message extends Base {
1194
1553
  createReactionCollector(options) {
1195
1554
  return new ReactionCollector(this.client, this.id, this.channelId, options);
1196
1555
  }
1556
+ /**
1557
+ * Wait for reactions matching the filter, then resolve the collected set.
1558
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
1559
+ */
1560
+ awaitReactions(options) {
1561
+ return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
1562
+ }
1197
1563
  /** Fetch the latest version of this message from the API. */
1198
1564
  async fetch() {
1199
1565
  return this.client.channels.fetchMessage(this.channelId, this.id);
@@ -1247,7 +1613,68 @@ var Message = class _Message extends Base {
1247
1613
  }
1248
1614
  };
1249
1615
 
1616
+ // src/Domain/Message/PartialMessage.ts
1617
+ var import_util7 = require("@fluxerjs/util");
1618
+ var PartialMessage = class {
1619
+ partial = true;
1620
+ client;
1621
+ id;
1622
+ channelId;
1623
+ guildId;
1624
+ content;
1625
+ authorId;
1626
+ author;
1627
+ createdAt;
1628
+ constructor(client, data) {
1629
+ this.client = client;
1630
+ this.id = data.id;
1631
+ this.channelId = data.channelId;
1632
+ this.guildId = data.guildId ?? null;
1633
+ this.content = data.content ?? null;
1634
+ this.authorId = data.authorId ?? null;
1635
+ this.author = data.author ?? null;
1636
+ this.createdAt = data.createdAt ?? (import_util7.SnowflakeUtil.isValid(data.id) ? import_util7.SnowflakeUtil.dateFromSnowflake(data.id) : null);
1637
+ }
1638
+ /**
1639
+ * Live text-capable channel from cache, or null if uncached / not text-based.
1640
+ * Same contract as {@link Message.channel}.
1641
+ */
1642
+ get channel() {
1643
+ const channel = this.client.channels.get(this.channelId) ?? null;
1644
+ return channel?.isTextBased() ? channel : null;
1645
+ }
1646
+ /**
1647
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1648
+ * has {@link Channel.delete} and {@link Channel.send}.
1649
+ * @example
1650
+ * const channel = await message.resolveChannel();
1651
+ * await channel.delete();
1652
+ */
1653
+ async resolveChannel() {
1654
+ return this.client.channels.resolve(this.channelId);
1655
+ }
1656
+ /**
1657
+ * Fetch the full message from the API.
1658
+ * @example
1659
+ * const message = await partial.fetch();
1660
+ * await message.reply('Pong!');
1661
+ */
1662
+ async fetch() {
1663
+ return this.client.channels.fetchMessage(this.channelId, this.id);
1664
+ }
1665
+ };
1666
+
1667
+ // src/Domain/User.ts
1668
+ var import_types16 = require("@fluxerjs/types");
1669
+ var import_util14 = require("@fluxerjs/util");
1670
+
1671
+ // src/Domain/Channel/Base.ts
1672
+ var import_types8 = require("@fluxerjs/types");
1673
+ var import_util8 = require("@fluxerjs/util");
1674
+
1250
1675
  // src/ClientCore/MessageManager.ts
1676
+ var import_collection4 = require("@fluxerjs/collection");
1677
+ var import_types6 = require("@fluxerjs/types");
1251
1678
  var BULK = {
1252
1679
  requests: { min: 1, max: 25 },
1253
1680
  limit: { min: 1, max: 25 },
@@ -1256,23 +1683,23 @@ var BULK = {
1256
1683
  function validateBulkMessageFetchRequests(requests) {
1257
1684
  const { requests: req, limit, totalMax } = BULK;
1258
1685
  if (requests.length < req.min || requests.length > req.max) {
1259
- throw new import_util3.FluxerError(`bulkFetchMessages requires between ${req.min} and ${req.max} requests`, {
1260
- code: import_util2.ErrorCodes.InvalidFetchLimit
1686
+ throw new import_util4.FluxerError(`bulkFetchMessages requires between ${req.min} and ${req.max} requests`, {
1687
+ code: import_util3.ErrorCodes.InvalidFetchLimit
1261
1688
  });
1262
1689
  }
1263
1690
  let total = 0;
1264
1691
  for (const request of requests) {
1265
1692
  if (request.limit < limit.min || request.limit > limit.max) {
1266
- throw new import_util3.FluxerError(
1693
+ throw new import_util4.FluxerError(
1267
1694
  `limit must be between ${limit.min} and ${limit.max} for channel ${request.channelId}`,
1268
- { code: import_util2.ErrorCodes.InvalidFetchLimit }
1695
+ { code: import_util3.ErrorCodes.InvalidFetchLimit }
1269
1696
  );
1270
1697
  }
1271
1698
  total += request.limit;
1272
1699
  }
1273
1700
  if (total > totalMax) {
1274
- throw new import_util3.FluxerError(`bulkFetchMessages total message limit must not exceed ${totalMax}`, {
1275
- code: import_util2.ErrorCodes.InvalidFetchLimit
1701
+ throw new import_util4.FluxerError(`bulkFetchMessages total message limit must not exceed ${totalMax}`, {
1702
+ code: import_util3.ErrorCodes.InvalidFetchLimit
1276
1703
  });
1277
1704
  }
1278
1705
  }
@@ -1281,19 +1708,40 @@ var MessageManager = class {
1281
1708
  this.client = client;
1282
1709
  this.channelId = channelId;
1283
1710
  }
1711
+ /** Structure cache keyed by message id (identity for {@link get}). */
1712
+ _structures = new import_collection4.Collection();
1284
1713
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
1285
1714
  get(messageId) {
1286
1715
  const data = this.client._getMessageCache(this.channelId)?.get(messageId);
1287
- return data ? new Message(this.client, data) : void 0;
1716
+ if (!data) {
1717
+ this._structures.delete(messageId);
1718
+ return void 0;
1719
+ }
1720
+ const existing = this._structures.get(messageId);
1721
+ if (existing) return existing;
1722
+ const message = new Message(this.client, data);
1723
+ this._structures.set(messageId, message);
1724
+ return message;
1725
+ }
1726
+ /** Retrieve from cache, otherwise {@link fetch}. */
1727
+ async resolve(messageId) {
1728
+ return this.get(messageId) ?? this.fetch(messageId);
1288
1729
  }
1289
1730
  async fetch(idOrOptions) {
1290
1731
  return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
1291
1732
  }
1292
- /** Cache API data and return a {@link Message} built from the cached entry when present. */
1733
+ /** Cache API data and return a {@link Message} (reusing identity when present). */
1293
1734
  wrap(data) {
1294
1735
  this.client._addMessageToCache(this.channelId, data);
1295
1736
  const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
1296
- return new Message(this.client, cached);
1737
+ const existing = this._structures.get(data.id);
1738
+ if (existing) {
1739
+ existing._patch(cached);
1740
+ return existing;
1741
+ }
1742
+ const message = new Message(this.client, cached);
1743
+ this._structures.set(data.id, message);
1744
+ return message;
1297
1745
  }
1298
1746
  /** Fetch a single message from the API. */
1299
1747
  async fetchOne(messageId) {
@@ -1305,7 +1753,7 @@ var MessageManager = class {
1305
1753
  } catch (err) {
1306
1754
  rethrowMapped(err, {
1307
1755
  notFound: {
1308
- code: import_util2.ErrorCodes.MessageNotFound,
1756
+ code: import_util3.ErrorCodes.MessageNotFound,
1309
1757
  message: `Message ${messageId} not found in channel ${this.channelId}`
1310
1758
  },
1311
1759
  fallback: `Failed to fetch message ${messageId}`
@@ -1315,8 +1763,8 @@ var MessageManager = class {
1315
1763
  /** Fetch multiple messages from the API with pagination/filtering. */
1316
1764
  async fetchMany(options) {
1317
1765
  if (options.limit != null && (options.limit < 1 || options.limit > 100)) {
1318
- throw new import_util3.FluxerError("limit must be between 1 and 100", {
1319
- code: import_util2.ErrorCodes.InvalidFetchLimit
1766
+ throw new import_util4.FluxerError("limit must be between 1 and 100", {
1767
+ code: import_util3.ErrorCodes.InvalidFetchLimit
1320
1768
  });
1321
1769
  }
1322
1770
  const qs2 = new URLSearchParams();
@@ -1326,12 +1774,110 @@ var MessageManager = class {
1326
1774
  }
1327
1775
  const base = import_types6.Routes.channelMessages(this.channelId);
1328
1776
  const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
1329
- const collection = new import_collection3.Collection();
1777
+ const collection = new import_collection4.Collection();
1330
1778
  for (const msg of data) collection.set(msg.id, this.wrap(msg));
1331
1779
  return collection;
1332
1780
  }
1333
1781
  };
1334
1782
 
1783
+ // src/Helpers/MessageCollector.ts
1784
+ var import_node_events2 = require("events");
1785
+ var import_collection5 = require("@fluxerjs/collection");
1786
+ function requireCollectorBounds(options) {
1787
+ const time = options.time ?? 0;
1788
+ const max = options.max ?? 0;
1789
+ if (time <= 0 && max <= 0) {
1790
+ throw new import_util4.FluxerError("MessageCollector requires `time` and/or `max`", {
1791
+ code: import_util3.ErrorCodes.CollectorOptionsRequired
1792
+ });
1793
+ }
1794
+ }
1795
+ var MessageCollector = class _MessageCollector extends import_node_events2.EventEmitter {
1796
+ client;
1797
+ channelId;
1798
+ options;
1799
+ collected = new import_collection5.Collection();
1800
+ _timeout = null;
1801
+ _ended = false;
1802
+ _listener;
1803
+ constructor(client, channelId, options = {}) {
1804
+ super();
1805
+ requireCollectorBounds(options);
1806
+ this.client = client;
1807
+ this.channelId = channelId;
1808
+ this.options = {
1809
+ filter: options.filter ?? (() => true),
1810
+ time: options.time ?? 0,
1811
+ max: options.max ?? 0
1812
+ };
1813
+ this._listener = (message) => {
1814
+ if (this._ended || message.channelId !== this.channelId) return;
1815
+ if (!this.options.filter(message)) return;
1816
+ this.collected.set(message.id, message);
1817
+ this.emit("collect", message);
1818
+ if (this.options.max > 0 && this.collected.size >= this.options.max) {
1819
+ this.stop("limit");
1820
+ }
1821
+ };
1822
+ this.client.on(Events.MessageCreate, this._listener);
1823
+ if (this.options.time > 0) {
1824
+ this._timeout = setTimeout(() => this.stop("time"), this.options.time);
1825
+ }
1826
+ }
1827
+ stop(reason = "user") {
1828
+ if (this._ended) return;
1829
+ this._ended = true;
1830
+ this.client.off(Events.MessageCreate, this._listener);
1831
+ if (this._timeout) {
1832
+ clearTimeout(this._timeout);
1833
+ this._timeout = null;
1834
+ }
1835
+ this.emit("end", this.collected, reason);
1836
+ }
1837
+ /**
1838
+ * One-shot helper used by {@link Channel.awaitMessages}.
1839
+ * Resolves with the collected messages when the collector ends for `user` (or when
1840
+ * the end reason is not listed in `errors`).
1841
+ * By default, `time` and `limit` reject with {@link FluxerError}
1842
+ * (`CollectorIdle` / `CollectorMax`).
1843
+ */
1844
+ static awaitMessages(client, channelId, options) {
1845
+ const errors = options?.errors ?? ["time", "limit"];
1846
+ return new Promise((resolve, reject) => {
1847
+ const collector = new _MessageCollector(client, channelId, options);
1848
+ collector.on("end", (collected, reason) => {
1849
+ if (!errors.includes(reason)) {
1850
+ resolve(collected);
1851
+ return;
1852
+ }
1853
+ if (reason === "time") {
1854
+ reject(
1855
+ new import_util4.FluxerError("Message collector timed out", {
1856
+ code: import_util3.ErrorCodes.CollectorIdle
1857
+ })
1858
+ );
1859
+ return;
1860
+ }
1861
+ if (reason === "limit") {
1862
+ reject(
1863
+ new import_util4.FluxerError("Message collector reached max", {
1864
+ code: import_util3.ErrorCodes.CollectorMax
1865
+ })
1866
+ );
1867
+ return;
1868
+ }
1869
+ reject(collected);
1870
+ });
1871
+ });
1872
+ }
1873
+ on(event, listener) {
1874
+ return super.on(event, listener);
1875
+ }
1876
+ emit(event, ...args) {
1877
+ return super.emit(event, ...args);
1878
+ }
1879
+ };
1880
+
1335
1881
  // src/Domain/Channel/Attachments.ts
1336
1882
  var import_types7 = require("@fluxerjs/types");
1337
1883
  function asBytes(data) {
@@ -1347,8 +1893,8 @@ async function putBlob(url, body, contentType) {
1347
1893
  body
1348
1894
  });
1349
1895
  if (!res.ok) {
1350
- throw new import_util3.FluxerError(`Presigned upload failed: ${res.status}`, {
1351
- code: import_util2.ErrorCodes.AttachmentUploadFailed
1896
+ throw new import_util4.FluxerError(`Presigned upload failed: ${res.status}`, {
1897
+ code: import_util3.ErrorCodes.AttachmentUploadFailed
1352
1898
  });
1353
1899
  }
1354
1900
  }
@@ -1372,8 +1918,8 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1372
1918
  for (const item of plan.attachments) {
1373
1919
  const file = files.find((f) => f.id === item.id);
1374
1920
  if (!file) {
1375
- throw new import_util3.FluxerError(`No file data for planned attachment id ${item.id}`, {
1376
- code: import_util2.ErrorCodes.InvalidAttachmentInput
1921
+ throw new import_util4.FluxerError(`No file data for planned attachment id ${item.id}`, {
1922
+ code: import_util3.ErrorCodes.InvalidAttachmentInput
1377
1923
  });
1378
1924
  }
1379
1925
  const bytes = asBytes(file.data);
@@ -1410,6 +1956,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1410
1956
 
1411
1957
  // src/Domain/Channel/Base.ts
1412
1958
  var Channel = class extends Base {
1959
+ #messages;
1413
1960
  /** The {@link Client} that instantiated this channel. */
1414
1961
  client;
1415
1962
  /** Snowflake ID of this channel. */
@@ -1433,11 +1980,11 @@ var Channel = class extends Base {
1433
1980
  }
1434
1981
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
1435
1982
  get createdTimestamp() {
1436
- return import_util5.SnowflakeUtil.timestampFromSnowflake(this.id);
1983
+ return import_util8.SnowflakeUtil.timestampFromSnowflake(this.id);
1437
1984
  }
1438
1985
  /** Date when this channel was created, derived from its snowflake ID. */
1439
1986
  get createdAt() {
1440
- return import_util5.SnowflakeUtil.dateFromSnowflake(this.id);
1987
+ return import_util8.SnowflakeUtil.dateFromSnowflake(this.id);
1441
1988
  }
1442
1989
  /**
1443
1990
  * Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
@@ -1451,19 +1998,36 @@ var Channel = class extends Base {
1451
1998
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1452
1999
  }
1453
2000
  }
1454
- /** Wired in `structures/channel/index.ts` after subclasses load. */
2001
+ /** @internal Factory wired after subclasses load. */
1455
2002
  static from(_c, _d) {
1456
2003
  throw new Error("Channel.from not initialized");
1457
2004
  }
2005
+ /** @internal Factory wired after subclasses load. */
1458
2006
  static fromOrCreate(_c, _d) {
1459
2007
  throw new Error("Channel.fromOrCreate not initialized");
1460
2008
  }
2009
+ /** @internal Factory wired after subclasses load. */
1461
2010
  static createDM(_c, _d) {
1462
2011
  throw new Error("Channel.createDM not initialized");
1463
2012
  }
1464
- /** Check if this channel supports sending messages (text/DM). */
2013
+ /**
2014
+ * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
2015
+ * Checks {@link ChannelType}, not whether `send` exists on the instance.
2016
+ */
1465
2017
  isTextBased() {
1466
- return "send" in this;
2018
+ 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;
2019
+ }
2020
+ /** Check if this is a guild channel (text, voice, category, or link). */
2021
+ isGuild() {
2022
+ 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;
2023
+ }
2024
+ /** Check if this is a guild text channel. */
2025
+ isText() {
2026
+ return this.type === import_types8.ChannelType.GuildText;
2027
+ }
2028
+ /** Check if this is a category channel. */
2029
+ isCategory() {
2030
+ return this.type === import_types8.ChannelType.GuildCategory;
1467
2031
  }
1468
2032
  /** Check if this is a DM, group DM, or personal notes channel. */
1469
2033
  isDM() {
@@ -1475,11 +2039,11 @@ var Channel = class extends Base {
1475
2039
  }
1476
2040
  /** Check if this is a voice channel. */
1477
2041
  isVoice() {
1478
- return "bitrate" in this;
2042
+ return this.type === import_types8.ChannelType.GuildVoice;
1479
2043
  }
1480
2044
  /** Check if this is a link channel. */
1481
2045
  isLink() {
1482
- return "url" in this;
2046
+ return this.type === import_types8.ChannelType.GuildLink;
1483
2047
  }
1484
2048
  /**
1485
2049
  * Delete recent messages or an explicit ID list.
@@ -1490,8 +2054,8 @@ var Channel = class extends Base {
1490
2054
  let ids;
1491
2055
  if (typeof countOrIds === "number") {
1492
2056
  if (!Number.isInteger(countOrIds) || countOrIds < 1 || countOrIds > 100) {
1493
- throw new import_util3.FluxerError("bulkDelete count must be between 1 and 100", {
1494
- code: import_util2.ErrorCodes.InvalidBulkDelete
2057
+ throw new import_util4.FluxerError("bulkDelete count must be between 1 and 100", {
2058
+ code: import_util3.ErrorCodes.InvalidBulkDelete
1495
2059
  });
1496
2060
  }
1497
2061
  ids = [
@@ -1507,8 +2071,8 @@ var Channel = class extends Base {
1507
2071
  return ids;
1508
2072
  }
1509
2073
  if (ids.length > 100) {
1510
- throw new import_util3.FluxerError("bulkDelete requires at most 100 message IDs", {
1511
- code: import_util2.ErrorCodes.InvalidBulkDelete
2074
+ throw new import_util4.FluxerError("bulkDelete requires at most 100 message IDs", {
2075
+ code: import_util3.ErrorCodes.InvalidBulkDelete
1512
2076
  });
1513
2077
  }
1514
2078
  await this.client.rest.post(import_types8.Routes.channelBulkDelete(this.id), {
@@ -1518,7 +2082,7 @@ var Channel = class extends Base {
1518
2082
  for (const id of ids) this.client._removeMessageFromCache(this.id, id);
1519
2083
  return ids;
1520
2084
  }
1521
- /** Delete all messages sent by the bot in this channel (user account feature). */
2085
+ /** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
1522
2086
  async bulkDeleteMyMessages(options) {
1523
2087
  const body = options ? toSudoBody(options) : void 0;
1524
2088
  await this.client.rest.post(import_types8.Routes.channelBulkDeleteMine(this.id), {
@@ -1526,11 +2090,17 @@ var Channel = class extends Base {
1526
2090
  auth: true
1527
2091
  });
1528
2092
  }
1529
- /** Mark all pinned messages as read in this channel. */
2093
+ /**
2094
+ * Mark all pinned messages as read in this channel.
2095
+ * Session-token helper; bots usually skip this.
2096
+ */
1530
2097
  async acknowledgePins() {
1531
2098
  await this.client.rest.post(import_types8.Routes.channelPinsAck(this.id), { auth: true });
1532
2099
  }
1533
- /** Clear the read state for this channel. */
2100
+ /**
2101
+ * Clear the read state for this channel.
2102
+ * Session-token helper; bots usually skip this.
2103
+ */
1534
2104
  async clearReadState() {
1535
2105
  await this.client.rest.delete(import_types8.Routes.channelMessagesAck(this.id), { auth: true });
1536
2106
  }
@@ -1566,28 +2136,80 @@ var Channel = class extends Base {
1566
2136
  async sendTyping() {
1567
2137
  await this.client.rest.post(import_types8.Routes.channelTyping(this.id), { auth: true });
1568
2138
  }
1569
- /** Fetch available RTC regions for voice channels. */
2139
+ /**
2140
+ * Fetch available RTC regions for voice channels.
2141
+ * User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
2142
+ * Bots should skip this and join voice with `@fluxerjs/voice` instead.
2143
+ */
1570
2144
  async fetchRtcRegions() {
1571
2145
  const data = await this.client.rest.get(import_types8.Routes.channelRtcRegions(this.id), {
1572
2146
  auth: true
1573
2147
  });
1574
- return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
1575
- }
1576
- /** Fetch slowmode state for this channel. */
1577
- async fetchSlowmode() {
1578
- const data = await this.client.rest.get(
1579
- import_types8.Routes.channelSlowmode(this.id),
1580
- { auth: true }
1581
- );
1582
- return {
1583
- rateLimitPerUser: data.rate_limit_per_user,
1584
- retryAfterMs: data.retry_after_ms,
1585
- nextSendAllowedAt: data.next_send_allowed_at
1586
- };
2148
+ return data.map((r) => ({ id: r.id, name: r.name, emoji: r.emoji }));
2149
+ }
2150
+ /** Fetch slowmode state for this channel. */
2151
+ async fetchSlowmode() {
2152
+ const data = await this.client.rest.get(
2153
+ import_types8.Routes.channelSlowmode(this.id),
2154
+ { auth: true }
2155
+ );
2156
+ return {
2157
+ rateLimitPerUser: data.rate_limit_per_user,
2158
+ retryAfterMs: data.retry_after_ms,
2159
+ nextSendAllowedAt: data.next_send_allowed_at
2160
+ };
2161
+ }
2162
+ /** Whether this channel type can carry messages (does not check permissions). */
2163
+ canSendMessage() {
2164
+ return this.isTextBased();
2165
+ }
2166
+ /** Per-channel message cache + fetch. */
2167
+ get messages() {
2168
+ if (!this.#messages) {
2169
+ this.#messages = new MessageManager(this.client, this.id);
2170
+ }
2171
+ return this.#messages;
2172
+ }
2173
+ /** Collect messages in this channel until time/max/stop. */
2174
+ createMessageCollector(options) {
2175
+ return new MessageCollector(this.client, this.id, options);
2176
+ }
2177
+ /**
2178
+ * Wait for messages matching the filter, then resolve the collected set.
2179
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
2180
+ * @example
2181
+ * const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
2182
+ */
2183
+ awaitMessages(options) {
2184
+ return MessageCollector.awaitMessages(this.client, this.id, options);
2185
+ }
2186
+ /**
2187
+ * Delete this channel (or close it if it is a DM).
2188
+ * Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
2189
+ * @example
2190
+ * const channel = await client.channels.fetch(channelId);
2191
+ * await channel.delete();
2192
+ */
2193
+ async delete(options) {
2194
+ const params = new URLSearchParams();
2195
+ if (options?.silent) params.set("silent", "true");
2196
+ if (options?.deleteMessages) params.set("delete_messages", "true");
2197
+ const qs2 = params.toString();
2198
+ const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2199
+ const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2200
+ await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2201
+ body,
2202
+ auth: true
2203
+ });
2204
+ this.client.channels.delete(this.id);
2205
+ this.client._clearMessageCache(this.id);
2206
+ if (this.isGuild() && this.guildId) {
2207
+ this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2208
+ }
1587
2209
  }
1588
- /** Check if the bot can send messages in this channel. */
1589
- canSendMessage() {
1590
- return this.isDM();
2210
+ /** Channel mention (`<#id>`). */
2211
+ toString() {
2212
+ return `<#${this.id}>`;
1591
2213
  }
1592
2214
  };
1593
2215
 
@@ -1596,60 +2218,6 @@ var import_types10 = require("@fluxerjs/types");
1596
2218
 
1597
2219
  // src/Domain/Channel/TextCapable.ts
1598
2220
  var import_types9 = require("@fluxerjs/types");
1599
-
1600
- // src/Helpers/MessageCollector.ts
1601
- var import_node_events2 = require("events");
1602
- var import_collection4 = require("@fluxerjs/collection");
1603
- var MessageCollector = class extends import_node_events2.EventEmitter {
1604
- client;
1605
- channelId;
1606
- options;
1607
- collected = new import_collection4.Collection();
1608
- _timeout = null;
1609
- _ended = false;
1610
- _listener;
1611
- constructor(client, channelId, options = {}) {
1612
- super();
1613
- this.client = client;
1614
- this.channelId = channelId;
1615
- this.options = {
1616
- filter: options.filter ?? (() => true),
1617
- time: options.time ?? 0,
1618
- max: options.max ?? 0
1619
- };
1620
- this._listener = (message) => {
1621
- if (this._ended || message.channelId !== this.channelId) return;
1622
- if (!this.options.filter(message)) return;
1623
- this.collected.set(message.id, message);
1624
- this.emit("collect", message);
1625
- if (this.options.max > 0 && this.collected.size >= this.options.max) {
1626
- this.stop("limit");
1627
- }
1628
- };
1629
- this.client.on(Events.MessageCreate, this._listener);
1630
- if (this.options.time > 0) {
1631
- this._timeout = setTimeout(() => this.stop("time"), this.options.time);
1632
- }
1633
- }
1634
- stop(reason = "user") {
1635
- if (this._ended) return;
1636
- this._ended = true;
1637
- this.client.off(Events.MessageCreate, this._listener);
1638
- if (this._timeout) {
1639
- clearTimeout(this._timeout);
1640
- this._timeout = null;
1641
- }
1642
- this.emit("end", this.collected, reason);
1643
- }
1644
- on(event, listener) {
1645
- return super.on(event, listener);
1646
- }
1647
- emit(event, ...args) {
1648
- return super.emit(event, ...args);
1649
- }
1650
- };
1651
-
1652
- // src/Domain/Channel/TextCapable.ts
1653
2221
  async function fetchPinnedMessagesPageFor(client, channelId, options) {
1654
2222
  const params = new URLSearchParams();
1655
2223
  if (options?.limit != null) params.set("limit", String(options.limit));
@@ -1667,27 +2235,19 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
1667
2235
  }
1668
2236
  function TextCapable(Base2) {
1669
2237
  class TextCapableChannel extends Base2 {
1670
- #messages;
2238
+ /**
2239
+ * Send a message in this channel.
2240
+ * @example
2241
+ * await channel.send('hi');
2242
+ */
1671
2243
  async send(options) {
1672
- const payload = await prepareMessagePostPayload(options, {
1673
- defaultAllowedMentions: this.client.options.defaultAllowedMentions
1674
- });
1675
- const data = await this.client.rest.post(import_types9.Routes.channelMessages(this.id), payload);
1676
- this.client._addMessageToCache(this.id, data);
1677
- return new Message(this.client, data);
1678
- }
1679
- get messages() {
1680
- if (!this.#messages) {
1681
- this.#messages = new MessageManager(this.client, this.id);
1682
- }
1683
- return this.#messages;
1684
- }
1685
- createMessageCollector(options) {
1686
- return new MessageCollector(this.client, this.id, options);
2244
+ return this.client.channels.send(this.id, options);
1687
2245
  }
2246
+ /** Fetch pinned messages in this channel. */
1688
2247
  async fetchPinnedMessages(options) {
1689
2248
  return (await this.fetchPinnedMessagesPage(options)).messages;
1690
2249
  }
2250
+ /** Fetch a page of pinned messages plus pagination metadata. */
1691
2251
  async fetchPinnedMessagesPage(options) {
1692
2252
  return fetchPinnedMessagesPageFor(this.client, this.id, options);
1693
2253
  }
@@ -1713,11 +2273,42 @@ var DMChannel = class extends TextCapable(Channel) {
1713
2273
  this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
1714
2274
  this.nicks = full.nicks ?? {};
1715
2275
  }
1716
- /** Purge all messages from personal notes. Only works on personal notes channels. */
2276
+ /**
2277
+ * Apply DM/group-DM fields in place.
2278
+ * @internal
2279
+ */
2280
+ _patch(data) {
2281
+ super._patch(data);
2282
+ const full = data;
2283
+ if ("last_message_id" in full && full.last_message_id !== void 0) {
2284
+ this.lastMessageId = full.last_message_id ?? null;
2285
+ }
2286
+ if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2287
+ if ("recipients" in full && full.recipients !== void 0) {
2288
+ this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2289
+ }
2290
+ if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2291
+ }
2292
+ /**
2293
+ * Edit this group DM (name, icon, nicks).
2294
+ * Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
2295
+ */
2296
+ async edit(options) {
2297
+ const data = await this.client.rest.patch(import_types10.Routes.channel(this.id), {
2298
+ body: toGroupDmEditBody(options),
2299
+ auth: true
2300
+ });
2301
+ this._patch(data);
2302
+ return this;
2303
+ }
2304
+ /**
2305
+ * Purge all messages from personal notes. Only works on personal notes channels.
2306
+ * Notes-only; bots usually skip this.
2307
+ */
1717
2308
  async purgeMessages() {
1718
2309
  if (this.type !== import_types10.ChannelType.DMPersonalNotes) {
1719
- throw new import_util3.FluxerError("purgeMessages is only available on personal notes channels", {
1720
- code: import_util2.ErrorCodes.InvalidChannelType
2310
+ throw new import_util4.FluxerError("purgeMessages is only available on personal notes channels", {
2311
+ code: import_util3.ErrorCodes.InvalidChannelType
1721
2312
  });
1722
2313
  }
1723
2314
  const data = await this.client.rest.post(
@@ -1726,15 +2317,24 @@ var DMChannel = class extends TextCapable(Channel) {
1726
2317
  );
1727
2318
  return data.deleted_count;
1728
2319
  }
1729
- /** Pin this DM channel to the top of the DM list. */
2320
+ /**
2321
+ * Pin this DM channel to the top of the DM list.
2322
+ * Session-token helper; bots usually skip this.
2323
+ */
1730
2324
  async pinInList() {
1731
2325
  await this.client.rest.put(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
1732
2326
  }
1733
- /** Unpin this DM channel from the DM list. */
2327
+ /**
2328
+ * Unpin this DM channel from the DM list.
2329
+ * Session-token helper; bots usually skip this.
2330
+ */
1734
2331
  async unpinFromList() {
1735
2332
  await this.client.rest.delete(import_types10.Routes.userMeChannelPin(this.id), { auth: true });
1736
2333
  }
1737
- /** Add a user to this group DM. */
2334
+ /**
2335
+ * Add a user to this group DM.
2336
+ * Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
2337
+ */
1738
2338
  async addRecipient(userId) {
1739
2339
  await this.client.rest.put(import_types10.Routes.channelRecipient(this.id, userId), { auth: true });
1740
2340
  const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
@@ -1750,14 +2350,14 @@ var DMChannel = class extends TextCapable(Channel) {
1750
2350
  };
1751
2351
 
1752
2352
  // src/Domain/Channel/Guild.ts
1753
- var import_types13 = require("@fluxerjs/types");
1754
- var import_util8 = require("@fluxerjs/util");
2353
+ var import_types14 = require("@fluxerjs/types");
2354
+ var import_util13 = require("@fluxerjs/util");
1755
2355
 
1756
2356
  // src/Domain/Invite.ts
1757
2357
  var import_types11 = require("@fluxerjs/types");
1758
2358
 
1759
2359
  // src/Helpers/Instance.ts
1760
- var import_util6 = require("@fluxerjs/util");
2360
+ var import_util9 = require("@fluxerjs/util");
1761
2361
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
1762
2362
  api: "https://api.fluxer.app",
1763
2363
  api_client: "https://web.fluxer.app/api",
@@ -1787,8 +2387,8 @@ var ENDPOINT_KEYS = [
1787
2387
  function requireString(obj, key, path) {
1788
2388
  const value = obj[key];
1789
2389
  if (typeof value !== "string" || value.length === 0) {
1790
- throw new import_util3.FluxerError(`Invalid instance discovery: ${path}.${key} must be a non-empty string`, {
1791
- code: import_util2.ErrorCodes.InvalidInstanceDiscovery
2390
+ throw new import_util4.FluxerError(`Invalid instance discovery: ${path}.${key} must be a non-empty string`, {
2391
+ code: import_util3.ErrorCodes.InvalidInstanceDiscovery
1792
2392
  });
1793
2393
  }
1794
2394
  return value;
@@ -1801,19 +2401,19 @@ function normalizeInviteBase(invite) {
1801
2401
  return invite.trim().replace(/\/+$/, "");
1802
2402
  }
1803
2403
  function parseInstanceDiscovery(raw) {
1804
- if (!(0, import_util6.isRecord)(raw)) {
1805
- throw new import_util3.FluxerError("Invalid instance discovery: expected an object", {
1806
- code: import_util2.ErrorCodes.InvalidInstanceDiscovery
2404
+ if (!(0, import_util9.isRecord)(raw)) {
2405
+ throw new import_util4.FluxerError("Invalid instance discovery: expected an object", {
2406
+ code: import_util3.ErrorCodes.InvalidInstanceDiscovery
1807
2407
  });
1808
2408
  }
1809
2409
  if (typeof raw.api_code_version !== "number" || !Number.isFinite(raw.api_code_version)) {
1810
- throw new import_util3.FluxerError("Invalid instance discovery: api_code_version must be a number", {
1811
- code: import_util2.ErrorCodes.InvalidInstanceDiscovery
2410
+ throw new import_util4.FluxerError("Invalid instance discovery: api_code_version must be a number", {
2411
+ code: import_util3.ErrorCodes.InvalidInstanceDiscovery
1812
2412
  });
1813
2413
  }
1814
- if (!(0, import_util6.isRecord)(raw.endpoints)) {
1815
- throw new import_util3.FluxerError("Invalid instance discovery: endpoints must be an object", {
1816
- code: import_util2.ErrorCodes.InvalidInstanceDiscovery
2414
+ if (!(0, import_util9.isRecord)(raw.endpoints)) {
2415
+ throw new import_util4.FluxerError("Invalid instance discovery: endpoints must be an object", {
2416
+ code: import_util3.ErrorCodes.InvalidInstanceDiscovery
1817
2417
  });
1818
2418
  }
1819
2419
  const endpoints = {};
@@ -1881,7 +2481,7 @@ function resolveInstanceEndpoints(input) {
1881
2481
  discovery: null
1882
2482
  });
1883
2483
  }
1884
- const isFull = "endpoints" in input && (0, import_util6.isRecord)(input.endpoints) && typeof input.api_code_version === "number";
2484
+ const isFull = "endpoints" in input && (0, import_util9.isRecord)(input.endpoints) && typeof input.api_code_version === "number";
1885
2485
  if (isFull) {
1886
2486
  const discovery = parseInstanceDiscovery(input);
1887
2487
  return Object.freeze({
@@ -1911,9 +2511,9 @@ function resolveRestApi(instanceApi, restApi) {
1911
2511
  if (restApi === void 0) return fromInstance;
1912
2512
  const fromRest = normalizeApiOrigin(restApi);
1913
2513
  if (fromRest !== fromInstance) {
1914
- throw new import_util3.FluxerError(
2514
+ throw new import_util4.FluxerError(
1915
2515
  `Conflicting API hosts: instance.api (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
1916
- { code: import_util2.ErrorCodes.ConflictingInstanceConfig }
2516
+ { code: import_util3.ErrorCodes.ConflictingInstanceConfig }
1917
2517
  );
1918
2518
  }
1919
2519
  return fromInstance;
@@ -1926,7 +2526,7 @@ function inviteUrl(inviteBase, code) {
1926
2526
  function parseInviteCode(codeOrUrl) {
1927
2527
  const input = codeOrUrl.trim();
1928
2528
  if (!input) {
1929
- throw new import_util3.FluxerError("Invite code cannot be empty", { code: import_util2.ErrorCodes.InvalidInvite });
2529
+ throw new import_util4.FluxerError("Invite code cannot be empty", { code: import_util3.ErrorCodes.InvalidInvite });
1930
2530
  }
1931
2531
  const fromUrl = (value) => {
1932
2532
  if (!URL.canParse(value)) return null;
@@ -1944,17 +2544,40 @@ function parseInviteCode(codeOrUrl) {
1944
2544
  const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(input);
1945
2545
  const code = (hasScheme ? fromUrl(input) : null) ?? (!hasScheme && URL.canParse(`https://${input}`) ? fromUrl(`https://${input}`) : null) ?? decodeURIComponent(input).trim();
1946
2546
  if (!code || /[\s/?#]/.test(code)) {
1947
- throw new import_util3.FluxerError("Invalid invite code or URL", { code: import_util2.ErrorCodes.InvalidInvite });
2547
+ throw new import_util4.FluxerError("Invalid invite code or URL", { code: import_util3.ErrorCodes.InvalidInvite });
1948
2548
  }
1949
2549
  return code;
1950
2550
  }
2551
+ function parseOptionalDate(value) {
2552
+ if (value == null || value === "") return null;
2553
+ const date = new Date(value);
2554
+ return Number.isNaN(date.getTime()) ? null : date;
2555
+ }
2556
+ function toInviteGuild(data) {
2557
+ return {
2558
+ id: data.id,
2559
+ name: data.name,
2560
+ icon: data.icon ?? null,
2561
+ banner: data.banner ?? null,
2562
+ splash: data.splash ?? null,
2563
+ features: data.features ?? []
2564
+ };
2565
+ }
2566
+ function toInviteChannel(data) {
2567
+ return {
2568
+ id: data.id,
2569
+ name: data.name ?? null,
2570
+ type: data.type,
2571
+ icon: data.icon ?? null,
2572
+ parentId: data.parent_id ?? null
2573
+ };
2574
+ }
1951
2575
  var Invite = class _Invite extends Base {
1952
2576
  client;
1953
2577
  code;
1954
2578
  type;
1955
- guild;
1956
- channel;
1957
- pack;
2579
+ guildSnapshot;
2580
+ channelSnapshot;
1958
2581
  inviter;
1959
2582
  memberCount;
1960
2583
  presenceCount;
@@ -1969,15 +2592,14 @@ var Invite = class _Invite extends Base {
1969
2592
  this.client = client;
1970
2593
  this.code = data.code;
1971
2594
  this.type = data.type;
1972
- this.guild = (0, import_types11.isGuildInvite)(data) ? data.guild : null;
1973
- this.channel = (0, import_types11.isGuildInvite)(data) || (0, import_types11.isGroupDmInvite)(data) ? data.channel : null;
1974
- this.pack = (0, import_types11.isPackInvite)(data) ? data.pack : null;
2595
+ this.guildSnapshot = (0, import_types11.isGuildInvite)(data) ? toInviteGuild(data.guild) : null;
2596
+ this.channelSnapshot = (0, import_types11.isGuildInvite)(data) || (0, import_types11.isGroupDmInvite)(data) ? toInviteChannel(data.channel) : null;
1975
2597
  this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
1976
- this.memberCount = (0, import_types11.isPackInvite)(data) ? null : data.member_count ?? null;
2598
+ this.memberCount = data.member_count ?? null;
1977
2599
  this.presenceCount = (0, import_types11.isGuildInvite)(data) ? data.presence_count ?? null : null;
1978
- this.expiresAt = data.expires_at ?? null;
2600
+ this.expiresAt = parseOptionalDate(data.expires_at);
1979
2601
  this.temporary = data.temporary ?? null;
1980
- this.createdAt = data.created_at ?? null;
2602
+ this.createdAt = parseOptionalDate(data.created_at);
1981
2603
  this.uses = data.uses ?? null;
1982
2604
  this.maxUses = data.max_uses ?? null;
1983
2605
  this.maxAge = data.max_age ?? null;
@@ -1988,16 +2610,25 @@ var Invite = class _Invite extends Base {
1988
2610
  isGroupDM() {
1989
2611
  return this.type === import_types11.InviteType.GroupDM;
1990
2612
  }
1991
- isPack() {
1992
- return this.type === import_types11.InviteType.EmojiPack || this.type === import_types11.InviteType.StickerPack;
1993
- }
1994
2613
  /** Full invite URL (uses this client's instance invite base). */
1995
2614
  get url() {
1996
2615
  return inviteUrl(this.client.instance.endpoints.invite, this.code);
1997
2616
  }
1998
- /** Cached guild for guild invites, else null. */
1999
- getGuild() {
2000
- return this.guild?.id ? this.client.guilds.get(this.guild.id) ?? null : null;
2617
+ /**
2618
+ * Resolve the cached/fetched {@link Guild} for this invite, or null.
2619
+ * `guildSnapshot` is metadata only.
2620
+ */
2621
+ async resolveGuild() {
2622
+ if (!this.guildSnapshot?.id) return null;
2623
+ return this.client.guilds.resolve(this.guildSnapshot.id);
2624
+ }
2625
+ /**
2626
+ * Resolve the cached/fetched {@link Channel} for this invite, or null.
2627
+ * `channelSnapshot` is metadata only.
2628
+ */
2629
+ async resolveChannel() {
2630
+ if (!this.channelSnapshot?.id) return null;
2631
+ return this.client.channels.resolve(this.channelSnapshot.id);
2001
2632
  }
2002
2633
  /** Fetch invite metadata by code or URL (does not join). */
2003
2634
  static async fetch(client, codeOrUrl) {
@@ -2013,7 +2644,7 @@ var Invite = class _Invite extends Base {
2013
2644
  // src/Domain/Webhook.ts
2014
2645
  var import_builders4 = require("@fluxerjs/builders");
2015
2646
  var import_types12 = require("@fluxerjs/types");
2016
- var import_util7 = require("@fluxerjs/util");
2647
+ var import_util10 = require("@fluxerjs/util");
2017
2648
  var Webhook = class _Webhook extends Base {
2018
2649
  /** Parent client instance. */
2019
2650
  client;
@@ -2050,11 +2681,11 @@ var Webhook = class _Webhook extends Base {
2050
2681
  }
2051
2682
  /** Unix timestamp (ms) when this webhook was created, derived from its snowflake ID. */
2052
2683
  get createdTimestamp() {
2053
- return import_util7.SnowflakeUtil.timestampFromSnowflake(this.id);
2684
+ return import_util10.SnowflakeUtil.timestampFromSnowflake(this.id);
2054
2685
  }
2055
2686
  /** Date when this webhook was created, derived from its snowflake ID. */
2056
2687
  get createdAt() {
2057
- return import_util7.SnowflakeUtil.dateFromSnowflake(this.id);
2688
+ return import_util10.SnowflakeUtil.dateFromSnowflake(this.id);
2058
2689
  }
2059
2690
  /** Delete this webhook (token auth when available, otherwise bot auth). */
2060
2691
  async delete() {
@@ -2164,9 +2795,9 @@ var Webhook = class _Webhook extends Base {
2164
2795
  }
2165
2796
  requireToken() {
2166
2797
  if (!this.token) {
2167
- throw new import_util3.FluxerError(
2798
+ throw new import_util4.FluxerError(
2168
2799
  "Webhook token is required. It is only returned when creating a webhook.",
2169
- { code: import_util2.ErrorCodes.WebhookTokenRequired }
2800
+ { code: import_util3.ErrorCodes.WebhookTokenRequired }
2170
2801
  );
2171
2802
  }
2172
2803
  return this.token;
@@ -2176,9 +2807,103 @@ var Webhook = class _Webhook extends Base {
2176
2807
  }
2177
2808
  };
2178
2809
 
2810
+ // src/Domain/Channel/PermissionOverwriteManager.ts
2811
+ var import_collection6 = require("@fluxerjs/collection");
2812
+ var import_types13 = require("@fluxerjs/types");
2813
+ var import_util12 = require("@fluxerjs/util");
2814
+
2815
+ // src/Domain/Channel/PermissionOverwrite.ts
2816
+ var import_util11 = require("@fluxerjs/util");
2817
+ var PermissionOverwrite = class {
2818
+ id;
2819
+ type;
2820
+ /** @internal Raw allow bitfield string. */
2821
+ _allow;
2822
+ /** @internal Raw deny bitfield string. */
2823
+ _deny;
2824
+ constructor(data) {
2825
+ this.id = data.id;
2826
+ this.type = data.type;
2827
+ this._allow = data.allow ?? "0";
2828
+ this._deny = data.deny ?? "0";
2829
+ }
2830
+ /** Allowed permissions for this overwrite. */
2831
+ get allow() {
2832
+ return new import_util11.PermissionsBitField(BigInt(this._allow || "0"));
2833
+ }
2834
+ /** Denied permissions for this overwrite. */
2835
+ get deny() {
2836
+ return new import_util11.PermissionsBitField(BigInt(this._deny || "0"));
2837
+ }
2838
+ /** Wire shape for permission computation / REST. */
2839
+ toJSON() {
2840
+ return {
2841
+ id: this.id,
2842
+ type: this.type,
2843
+ allow: this._allow,
2844
+ deny: this._deny
2845
+ };
2846
+ }
2847
+ };
2848
+
2849
+ // src/Domain/Channel/PermissionOverwriteManager.ts
2850
+ var PermissionOverwriteManager = class {
2851
+ constructor(channel, initial = []) {
2852
+ this.channel = channel;
2853
+ this._patch(initial);
2854
+ }
2855
+ _cache = new import_collection6.Collection();
2856
+ /** Cached overwrites keyed by role/member ID. */
2857
+ get cache() {
2858
+ return this._cache;
2859
+ }
2860
+ get size() {
2861
+ return this._cache.size;
2862
+ }
2863
+ [Symbol.iterator]() {
2864
+ return this._cache.values();
2865
+ }
2866
+ /** Wire-shaped overwrites for permission computation. */
2867
+ toJSON() {
2868
+ return [...this._cache.values()].map((o) => o.toJSON());
2869
+ }
2870
+ /** Edit or create a permission overwrite. */
2871
+ async edit(overwriteId, options) {
2872
+ const allow = options.allow !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.allow) : "0";
2873
+ const deny = options.deny !== void 0 ? (0, import_util12.resolvePermissionsToBitfield)(options.deny) : "0";
2874
+ await this.channel.client.rest.put(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
2875
+ body: { type: options.type, allow, deny },
2876
+ auth: true
2877
+ });
2878
+ this._cache.set(
2879
+ overwriteId,
2880
+ new PermissionOverwrite({
2881
+ id: overwriteId,
2882
+ type: options.type,
2883
+ allow,
2884
+ deny
2885
+ })
2886
+ );
2887
+ }
2888
+ /** Delete a permission overwrite. */
2889
+ async delete(overwriteId) {
2890
+ await this.channel.client.rest.delete(import_types13.Routes.channelPermission(this.channel.id, overwriteId), {
2891
+ auth: true
2892
+ });
2893
+ this._cache.delete(overwriteId);
2894
+ }
2895
+ /** @internal Sync from an API channel payload. */
2896
+ _patch(overwrites) {
2897
+ this._cache.clear();
2898
+ for (const entry of overwrites ?? []) {
2899
+ this._cache.set(entry.id, new PermissionOverwrite(entry));
2900
+ }
2901
+ }
2902
+ };
2903
+
2179
2904
  // src/Domain/Channel/Guild.ts
2180
2905
  var GuildChannel = class extends Channel {
2181
- /** Guild ID this channel belongs to. */
2906
+ /** Guild ID this channel belongs to, or null if missing from the payload. */
2182
2907
  guildId;
2183
2908
  /** Position in the channel list. */
2184
2909
  position;
@@ -2188,11 +2913,14 @@ var GuildChannel = class extends Channel {
2188
2913
  permissionOverwrites;
2189
2914
  constructor(client, data) {
2190
2915
  super(client, data);
2191
- this.guildId = data.guild_id ?? "";
2916
+ this.guildId = data.guild_id ?? null;
2192
2917
  this.name = data.name ?? null;
2193
2918
  this.position = data.position;
2194
2919
  this.parentId = data.parent_id ?? null;
2195
- this.permissionOverwrites = data.permission_overwrites ?? [];
2920
+ this.permissionOverwrites = new PermissionOverwriteManager(
2921
+ this,
2922
+ data.permission_overwrites ?? []
2923
+ );
2196
2924
  }
2197
2925
  /**
2198
2926
  * Apply guild-channel fields in place.
@@ -2204,13 +2932,13 @@ var GuildChannel = class extends Channel {
2204
2932
  if (data.position !== void 0) this.position = data.position;
2205
2933
  if (data.parent_id !== void 0) this.parentId = data.parent_id ?? null;
2206
2934
  if (data.permission_overwrites !== void 0) {
2207
- this.permissionOverwrites = data.permission_overwrites ?? [];
2935
+ this.permissionOverwrites._patch(data.permission_overwrites ?? []);
2208
2936
  }
2209
2937
  this.applyEditPatch(data);
2210
2938
  }
2211
2939
  /** Create a webhook for this channel. Requires Manage Webhooks. */
2212
2940
  async createWebhook(options) {
2213
- const data = await this.client.rest.post(import_types13.Routes.channelWebhooks(this.id), {
2941
+ const data = await this.client.rest.post(import_types14.Routes.channelWebhooks(this.id), {
2214
2942
  body: options,
2215
2943
  auth: true
2216
2944
  });
@@ -2218,13 +2946,13 @@ var GuildChannel = class extends Channel {
2218
2946
  }
2219
2947
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
2220
2948
  async fetchWebhooks() {
2221
- const data = await this.client.rest.get(import_types13.Routes.channelWebhooks(this.id));
2949
+ const data = await this.client.rest.get(import_types14.Routes.channelWebhooks(this.id));
2222
2950
  return data.map((w) => new Webhook(this.client, w));
2223
2951
  }
2224
2952
  /** Create an invite for this channel. Requires Create Instant Invite. */
2225
2953
  async createInvite(options) {
2226
2954
  const body = options ? toChannelInviteBody(options) : {};
2227
- const data = await this.client.rest.post(import_types13.Routes.channelInvites(this.id), {
2955
+ const data = await this.client.rest.post(import_types14.Routes.channelInvites(this.id), {
2228
2956
  body: Object.keys(body).length ? body : void 0,
2229
2957
  auth: true
2230
2958
  });
@@ -2232,109 +2960,160 @@ var GuildChannel = class extends Channel {
2232
2960
  }
2233
2961
  /** Fetch all invites for this channel. Requires Manage Channels. */
2234
2962
  async fetchInvites() {
2235
- const data = await this.client.rest.get(import_types13.Routes.channelInvites(this.id));
2963
+ const data = await this.client.rest.get(import_types14.Routes.channelInvites(this.id));
2236
2964
  return data.map((i) => new Invite(this.client, i));
2237
2965
  }
2238
- /** Edit or create a permission overwrite. Requires Manage Roles. */
2239
- async editPermission(overwriteId, options) {
2240
- await this.client.rest.put(import_types13.Routes.channelPermission(this.id, overwriteId), {
2241
- body: options,
2242
- auth: true
2243
- });
2244
- const entry = {
2245
- id: overwriteId,
2246
- type: options.type,
2247
- allow: options.allow ?? "0",
2248
- deny: options.deny ?? "0"
2249
- };
2250
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2251
- if (idx >= 0) this.permissionOverwrites[idx] = entry;
2252
- else this.permissionOverwrites.push(entry);
2253
- }
2254
- /** Delete a permission overwrite. Requires Manage Roles. */
2255
- async deletePermission(overwriteId) {
2256
- await this.client.rest.delete(import_types13.Routes.channelPermission(this.id, overwriteId), { auth: true });
2257
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2258
- if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
2259
- }
2260
- /** Check if the bot can send messages in this channel (with permissions). */
2966
+ /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
2261
2967
  canSendMessage() {
2968
+ if (!this.guildId) return false;
2262
2969
  const me = this.client.guilds.get(this.guildId)?.members.me;
2263
2970
  if (!me) return false;
2264
2971
  const perms = me.permissionsIn(this);
2265
- return perms.has(import_util8.PermissionFlags.ViewChannel) && perms.has(import_util8.PermissionFlags.SendMessages);
2972
+ return perms.has(import_util13.PermissionFlags.ViewChannel) && perms.has(import_util13.PermissionFlags.SendMessages);
2973
+ }
2974
+ /**
2975
+ * Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
2976
+ * Returns false when the channel has no guildId.
2977
+ */
2978
+ async canSend() {
2979
+ if (!this.guildId) return false;
2980
+ const guild = this.client.guilds.get(this.guildId);
2981
+ if (!guild) return false;
2982
+ if (!guild.members.me) {
2983
+ try {
2984
+ await guild.members.fetchMe();
2985
+ } catch {
2986
+ return false;
2987
+ }
2988
+ }
2989
+ return this.canSendMessage();
2266
2990
  }
2267
2991
  /** Edit this channel's settings. Requires Manage Channels. */
2268
2992
  async edit(options) {
2269
- const data = await this.client.rest.patch(import_types13.Routes.channel(this.id), {
2993
+ const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
2270
2994
  body: toChannelEditBody(options),
2271
2995
  auth: true
2272
2996
  });
2273
2997
  this.name = data.name ?? this.name;
2274
2998
  this.parentId = data.parent_id ?? this.parentId;
2275
- this.permissionOverwrites = data.permission_overwrites ?? this.permissionOverwrites;
2999
+ if (data.permission_overwrites !== void 0) {
3000
+ this.permissionOverwrites._patch(data.permission_overwrites);
3001
+ }
2276
3002
  this.applyEditPatch(data);
2277
3003
  return this;
2278
3004
  }
2279
3005
  applyEditPatch(_data) {
2280
3006
  }
2281
- /** Delete this channel. Requires Manage Channels or channel ownership. */
2282
- async delete(options) {
2283
- const params = new URLSearchParams();
2284
- if (options?.silent) params.set("silent", "true");
2285
- if (options?.deleteMessages) params.set("delete_messages", "true");
2286
- const qs2 = params.toString();
2287
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2288
- const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2289
- await this.client.rest.delete(import_types13.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2290
- body,
2291
- auth: true
2292
- });
2293
- this.client.channels.delete(this.id);
2294
- this.client._clearMessageCache(this.id);
2295
- this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2296
- }
2297
3007
  };
2298
3008
  var TextChannel = class extends TextCapable(GuildChannel) {
2299
3009
  /** Channel topic. */
2300
3010
  topic;
2301
3011
  /** Whether this channel is marked as NSFW. */
2302
3012
  nsfw;
3013
+ /** Per-channel NSFW override (`null` inherits). */
3014
+ nsfwOverride;
2303
3015
  /** Slowmode rate limit in seconds. */
2304
3016
  rateLimitPerUser;
2305
3017
  /** ID of the last message sent in this channel. */
2306
3018
  lastMessageId;
3019
+ /** Content warning level. */
3020
+ contentWarningLevel;
3021
+ /** Custom content warning text. */
3022
+ contentWarningText;
2307
3023
  constructor(client, data) {
2308
3024
  super(client, data);
2309
3025
  this.topic = data.topic ?? null;
2310
3026
  this.nsfw = data.nsfw ?? false;
3027
+ this.nsfwOverride = data.nsfw_override ?? null;
2311
3028
  this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
2312
3029
  this.lastMessageId = data.last_message_id ?? null;
3030
+ this.contentWarningLevel = data.content_warning_level ?? null;
3031
+ this.contentWarningText = data.content_warning_text ?? null;
3032
+ }
3033
+ /**
3034
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3035
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3036
+ */
3037
+ async setSlowmode(seconds) {
3038
+ return this.edit({ rateLimitPerUser: seconds });
2313
3039
  }
2314
3040
  applyEditPatch(data) {
2315
3041
  if ("topic" in data) this.topic = data.topic ?? null;
2316
3042
  if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3043
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
2317
3044
  if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3045
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3046
+ if ("content_warning_level" in data) {
3047
+ this.contentWarningLevel = data.content_warning_level ?? null;
3048
+ }
3049
+ if ("content_warning_text" in data) {
3050
+ this.contentWarningText = data.content_warning_text ?? null;
3051
+ }
2318
3052
  }
2319
3053
  };
2320
3054
  var CategoryChannel = class extends GuildChannel {
2321
3055
  };
2322
- var VoiceChannel = class extends GuildChannel {
3056
+ var VoiceChannel = class extends TextCapable(GuildChannel) {
3057
+ /** Channel topic. */
3058
+ topic;
3059
+ /** Whether this channel is marked as NSFW. */
3060
+ nsfw;
3061
+ /** Per-channel NSFW override (`null` inherits). */
3062
+ nsfwOverride;
3063
+ /** Slowmode rate limit in seconds. */
3064
+ rateLimitPerUser;
3065
+ /** ID of the last message sent in this channel. */
3066
+ lastMessageId;
3067
+ /** Content warning level. */
3068
+ contentWarningLevel;
3069
+ /** Custom content warning text. */
3070
+ contentWarningText;
2323
3071
  /** Voice bitrate. */
2324
3072
  bitrate;
2325
3073
  /** Maximum number of users allowed. */
2326
3074
  userLimit;
3075
+ /** Max active voice connections per user. */
3076
+ voiceConnectionLimit;
2327
3077
  /** RTC region override for this channel. */
2328
3078
  rtcRegion;
2329
3079
  constructor(client, data) {
2330
3080
  super(client, data);
3081
+ this.topic = data.topic ?? null;
3082
+ this.nsfw = data.nsfw ?? false;
3083
+ this.nsfwOverride = data.nsfw_override ?? null;
3084
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3085
+ this.lastMessageId = data.last_message_id ?? null;
3086
+ this.contentWarningLevel = data.content_warning_level ?? null;
3087
+ this.contentWarningText = data.content_warning_text ?? null;
2331
3088
  this.bitrate = data.bitrate ?? null;
2332
3089
  this.userLimit = data.user_limit ?? null;
3090
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
2333
3091
  this.rtcRegion = data.rtc_region ?? null;
2334
3092
  }
3093
+ /**
3094
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3095
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3096
+ */
3097
+ async setSlowmode(seconds) {
3098
+ return this.edit({ rateLimitPerUser: seconds });
3099
+ }
2335
3100
  applyEditPatch(data) {
3101
+ if ("topic" in data) this.topic = data.topic ?? null;
3102
+ if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3103
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
3104
+ if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3105
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3106
+ if ("content_warning_level" in data) {
3107
+ this.contentWarningLevel = data.content_warning_level ?? null;
3108
+ }
3109
+ if ("content_warning_text" in data) {
3110
+ this.contentWarningText = data.content_warning_text ?? null;
3111
+ }
2336
3112
  if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
2337
3113
  if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
3114
+ if ("voice_connection_limit" in data) {
3115
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3116
+ }
2338
3117
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
2339
3118
  }
2340
3119
  };
@@ -2345,20 +3124,23 @@ var LinkChannel = class extends GuildChannel {
2345
3124
  super(client, data);
2346
3125
  this.url = data.url ?? null;
2347
3126
  }
3127
+ applyEditPatch(data) {
3128
+ if ("url" in data) this.url = data.url ?? null;
3129
+ }
2348
3130
  };
2349
3131
 
2350
3132
  // src/Domain/Channel/Factory.ts
2351
- var import_types14 = require("@fluxerjs/types");
3133
+ var import_types15 = require("@fluxerjs/types");
2352
3134
  var GUILD_FACTORIES = {
2353
- [import_types14.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
2354
- [import_types14.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
2355
- [import_types14.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
2356
- [import_types14.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
3135
+ [import_types15.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
3136
+ [import_types15.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3137
+ [import_types15.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
3138
+ [import_types15.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
2357
3139
  };
2358
3140
  var DM_TYPES = /* @__PURE__ */ new Set([
2359
- import_types14.ChannelType.DM,
2360
- import_types14.ChannelType.GroupDM,
2361
- import_types14.ChannelType.DMPersonalNotes
3141
+ import_types15.ChannelType.DM,
3142
+ import_types15.ChannelType.GroupDM,
3143
+ import_types15.ChannelType.DMPersonalNotes
2362
3144
  ]);
2363
3145
  function createDM(client, data) {
2364
3146
  return new DMChannel(client, data);
@@ -2460,11 +3242,11 @@ var User = class extends Base {
2460
3242
  */
2461
3243
  /** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
2462
3244
  get createdTimestamp() {
2463
- return import_util9.SnowflakeUtil.timestampFromSnowflake(this.id);
3245
+ return import_util14.SnowflakeUtil.timestampFromSnowflake(this.id);
2464
3246
  }
2465
3247
  /** Date when this account was created, derived from its snowflake ID. */
2466
3248
  get createdAt() {
2467
- return import_util9.SnowflakeUtil.dateFromSnowflake(this.id);
3249
+ return import_util14.SnowflakeUtil.dateFromSnowflake(this.id);
2468
3250
  }
2469
3251
  toString() {
2470
3252
  return `<@${this.id}>`;
@@ -2474,7 +3256,7 @@ var User = class extends Base {
2474
3256
  * @returns DM channel instance (cached if already open)
2475
3257
  */
2476
3258
  async createDM() {
2477
- const data = await this.client.rest.post(import_types15.Routes.userMeChannels(), {
3259
+ const data = await this.client.rest.post(import_types16.Routes.userMeChannels(), {
2478
3260
  body: { recipient_id: this.id },
2479
3261
  auth: true
2480
3262
  });
@@ -2589,6 +3371,9 @@ var CacheController = class {
2589
3371
  stickers
2590
3372
  };
2591
3373
  }
3374
+ /**
3375
+ * Sweep cached messages. Filter receives a hydrated {@link Message} (`createdAt`).
3376
+ */
2592
3377
  sweepMessages(filter, channelId) {
2593
3378
  return this.client.sweepMessages(filter, channelId);
2594
3379
  }
@@ -2657,7 +3442,7 @@ var CacheController = class {
2657
3442
  * @internal
2658
3443
  */
2659
3444
  cascadeChannel(channel, from = "both") {
2660
- const guildId = "guildId" in channel && typeof channel.guildId === "string" ? channel.guildId : void 0;
3445
+ const guildId = typeof channel.isGuild === "function" && channel.isGuild() ? channel.guildId : void 0;
2661
3446
  const dropFromGuild = () => {
2662
3447
  if (!guildId) return;
2663
3448
  const guildChannels = this.client.guilds.get(guildId)?.channels;
@@ -2687,12 +3472,12 @@ var CacheController = class {
2687
3472
  };
2688
3473
 
2689
3474
  // src/ClientCore/ChannelManager.ts
2690
- var import_collection6 = require("@fluxerjs/collection");
2691
- var import_types22 = require("@fluxerjs/types");
3475
+ var import_collection8 = require("@fluxerjs/collection");
3476
+ var import_types23 = require("@fluxerjs/types");
2692
3477
 
2693
3478
  // src/Domain/Guild/GuildEmoji.ts
2694
- var import_types16 = require("@fluxerjs/types");
2695
- var import_util10 = require("@fluxerjs/util");
3479
+ var import_types17 = require("@fluxerjs/types");
3480
+ var import_util15 = require("@fluxerjs/util");
2696
3481
  var GuildEmoji = class extends Base {
2697
3482
  client;
2698
3483
  id;
@@ -2728,11 +3513,11 @@ var GuildEmoji = class extends Base {
2728
3513
  }
2729
3514
  /** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
2730
3515
  get createdTimestamp() {
2731
- return import_util10.SnowflakeUtil.timestampFromSnowflake(this.id);
3516
+ return import_util15.SnowflakeUtil.timestampFromSnowflake(this.id);
2732
3517
  }
2733
3518
  /** Date when this emoji was created, derived from its snowflake ID. */
2734
3519
  get createdAt() {
2735
- return import_util10.SnowflakeUtil.dateFromSnowflake(this.id);
3520
+ return import_util15.SnowflakeUtil.dateFromSnowflake(this.id);
2736
3521
  }
2737
3522
  /** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
2738
3523
  toString() {
@@ -2740,7 +3525,7 @@ var GuildEmoji = class extends Base {
2740
3525
  }
2741
3526
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
2742
3527
  async delete() {
2743
- await this.client.rest.delete(import_types16.Routes.guildEmoji(this.guildId, this.id), {
3528
+ await this.client.rest.delete(import_types17.Routes.guildEmoji(this.guildId, this.id), {
2744
3529
  auth: true
2745
3530
  });
2746
3531
  const guild = this.client.guilds.get(this.guildId);
@@ -2751,7 +3536,7 @@ var GuildEmoji = class extends Base {
2751
3536
  * Requires Manage Emojis and Stickers permission.
2752
3537
  */
2753
3538
  async edit(options) {
2754
- const data = await this.client.rest.patch(import_types16.Routes.guildEmoji(this.guildId, this.id), {
3539
+ const data = await this.client.rest.patch(import_types17.Routes.guildEmoji(this.guildId, this.id), {
2755
3540
  body: options,
2756
3541
  auth: true
2757
3542
  });
@@ -2761,28 +3546,28 @@ var GuildEmoji = class extends Base {
2761
3546
  };
2762
3547
 
2763
3548
  // src/Domain/Guild/GuildMember.ts
2764
- var import_types19 = require("@fluxerjs/types");
2765
- var import_util12 = require("@fluxerjs/util");
3549
+ var import_types20 = require("@fluxerjs/types");
3550
+ var import_util17 = require("@fluxerjs/util");
2766
3551
 
2767
3552
  // src/Helpers/Permissions.ts
2768
- var import_types17 = require("@fluxerjs/types");
2769
- var import_util11 = require("@fluxerjs/util");
3553
+ var import_types18 = require("@fluxerjs/types");
3554
+ var import_util16 = require("@fluxerjs/util");
2770
3555
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
2771
- if (isOwner) return import_util11.ALL_PERMISSIONS_BIGINT;
3556
+ if (isOwner) return import_util16.ALL_PERMISSIONS_BIGINT;
2772
3557
  let perms = basePermissions;
2773
3558
  for (const overwrite of overwrites ?? []) {
2774
- const applies = overwrite.type === import_types17.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types17.OverwriteType.Member && overwrite.id === memberId;
3559
+ const applies = overwrite.type === import_types18.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types18.OverwriteType.Member && overwrite.id === memberId;
2775
3560
  if (!applies) continue;
2776
3561
  const allow = BigInt(overwrite.allow || "0");
2777
3562
  const deny = BigInt(overwrite.deny || "0");
2778
3563
  perms = perms & ~deny | allow;
2779
3564
  }
2780
- return (perms & import_util11.PermissionFlags.Administrator) !== 0n ? import_util11.ALL_PERMISSIONS_BIGINT : perms;
3565
+ return (perms & import_util16.PermissionFlags.Administrator) !== 0n ? import_util16.ALL_PERMISSIONS_BIGINT : perms;
2781
3566
  }
2782
3567
 
2783
3568
  // src/Domain/Guild/GuildMemberRoleManager.ts
2784
- var import_collection5 = require("@fluxerjs/collection");
2785
- var import_types18 = require("@fluxerjs/types");
3569
+ var import_collection7 = require("@fluxerjs/collection");
3570
+ var import_types19 = require("@fluxerjs/types");
2786
3571
  function roleId(roleOrId) {
2787
3572
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
2788
3573
  }
@@ -2800,7 +3585,7 @@ var GuildMemberRoleManager = class {
2800
3585
  }
2801
3586
  /** Live Role objects from `guild.roles` for this member's role IDs. */
2802
3587
  get cache() {
2803
- const out = new import_collection5.Collection();
3588
+ const out = new import_collection7.Collection();
2804
3589
  for (const id of this.ids) {
2805
3590
  const role = this.member.guild.roles.get(id);
2806
3591
  if (role) out.set(id, role);
@@ -2811,7 +3596,7 @@ var GuildMemberRoleManager = class {
2811
3596
  const id = roleId(roleOrId);
2812
3597
  if (this.ids.includes(id)) return;
2813
3598
  await this.member.client.rest.put(
2814
- import_types18.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
3599
+ import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
2815
3600
  );
2816
3601
  this.ids.push(id);
2817
3602
  }
@@ -2820,13 +3605,13 @@ var GuildMemberRoleManager = class {
2820
3605
  const idx = this.ids.indexOf(id);
2821
3606
  if (idx === -1) return;
2822
3607
  await this.member.client.rest.delete(
2823
- import_types18.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
3608
+ import_types19.Routes.guildMemberRole(this.member.guild.id, this.member.id, id)
2824
3609
  );
2825
3610
  this.ids.splice(idx, 1);
2826
3611
  }
2827
3612
  async set(roleIds) {
2828
3613
  const data = await this.member.client.rest.patch(
2829
- import_types18.Routes.guildMember(this.member.guild.id, this.member.id),
3614
+ import_types19.Routes.guildMember(this.member.guild.id, this.member.id),
2830
3615
  { body: { roles: roleIds }, auth: true }
2831
3616
  );
2832
3617
  this.ids = data.roles ? [...data.roles] : [];
@@ -2839,6 +3624,8 @@ var GuildMemberRoleManager = class {
2839
3624
 
2840
3625
  // src/Domain/Guild/GuildMember.ts
2841
3626
  var GuildMember = class _GuildMember extends Base {
3627
+ /** Discriminant vs {@link PartialGuildMember}: always `false` on a hydrated member. */
3628
+ partial = false;
2842
3629
  /** Parent client instance. */
2843
3630
  client;
2844
3631
  /** User ID (same as `user.id`). */
@@ -2867,6 +3654,12 @@ var GuildMember = class _GuildMember extends Base {
2867
3654
  accentColor;
2868
3655
  /** Guild-specific profile flags. */
2869
3656
  profileFlags;
3657
+ /** Per-guild reply mention preference override. */
3658
+ mentionFlags;
3659
+ /** Guild-specific bio (set from member edit; not always on GET member). */
3660
+ bio;
3661
+ /** Guild-specific pronouns (set from member edit; not always on GET member). */
3662
+ pronouns;
2870
3663
  constructor(client, data, guild) {
2871
3664
  super();
2872
3665
  this.client = client;
@@ -2883,6 +3676,9 @@ var GuildMember = class _GuildMember extends Base {
2883
3676
  this.banner = data.banner ?? null;
2884
3677
  this.accentColor = data.accent_color ?? null;
2885
3678
  this.profileFlags = data.profile_flags ?? null;
3679
+ this.mentionFlags = data.mention_flags ?? null;
3680
+ this.bio = data.bio ?? null;
3681
+ this.pronouns = data.pronouns ?? null;
2886
3682
  }
2887
3683
  /**
2888
3684
  * Apply an API member payload in place (gateway GUILD_MEMBER_UPDATE / REST edit).
@@ -2901,6 +3697,9 @@ var GuildMember = class _GuildMember extends Base {
2901
3697
  if (data.banner !== void 0) this.banner = data.banner ?? null;
2902
3698
  if (data.accent_color !== void 0) this.accentColor = data.accent_color ?? null;
2903
3699
  if (data.profile_flags !== void 0) this.profileFlags = data.profile_flags ?? null;
3700
+ if (data.mention_flags !== void 0) this.mentionFlags = data.mention_flags ?? null;
3701
+ if (data.bio !== void 0) this.bio = data.bio ?? null;
3702
+ if (data.pronouns !== void 0) this.pronouns = data.pronouns ?? null;
2904
3703
  }
2905
3704
  /**
2906
3705
  * Snapshot for `guildMemberUpdate` old-member arg (before in-place patch).
@@ -2929,7 +3728,10 @@ var GuildMember = class _GuildMember extends Base {
2929
3728
  avatar: this.avatar,
2930
3729
  banner: this.banner,
2931
3730
  accent_color: this.accentColor,
2932
- profile_flags: this.profileFlags ?? void 0
3731
+ profile_flags: this.profileFlags ?? void 0,
3732
+ mention_flags: this.mentionFlags,
3733
+ bio: this.bio,
3734
+ pronouns: this.pronouns
2933
3735
  },
2934
3736
  this.guild
2935
3737
  );
@@ -2956,15 +3758,22 @@ var GuildMember = class _GuildMember extends Base {
2956
3758
  mediaBase: this.client.instance.endpoints.media
2957
3759
  });
2958
3760
  }
2959
- /** PATCH member (`/members/@me` when editing the bot). */
3761
+ /**
3762
+ * PATCH member (`/members/@me` when editing the bot).
3763
+ * @example
3764
+ * await member.edit({ nick: 'Ada' });
3765
+ */
2960
3766
  async edit(options) {
2961
3767
  const isMe = this.client.user?.id === this.id;
2962
- const route = isMe ? import_types19.Routes.guildMemberMe(this.guild.id) : import_types19.Routes.guildMember(this.guild.id, this.id);
3768
+ const route = isMe ? import_types20.Routes.guildMemberMe(this.guild.id) : import_types20.Routes.guildMember(this.guild.id, this.id);
2963
3769
  const data = await this.client.rest.patch(route, {
2964
3770
  body: toMemberEditBody(options),
2965
3771
  auth: true
2966
3772
  });
2967
3773
  this._patch(data);
3774
+ if (options.bio !== void 0) this.bio = options.bio;
3775
+ if (options.pronouns !== void 0) this.pronouns = options.pronouns;
3776
+ if (options.mentionFlags !== void 0) this.mentionFlags = options.mentionFlags;
2968
3777
  return this;
2969
3778
  }
2970
3779
  /**
@@ -2972,7 +3781,7 @@ var GuildMember = class _GuildMember extends Base {
2972
3781
  * @see {@link permissionsIn} for channel-specific permissions
2973
3782
  */
2974
3783
  get permissions() {
2975
- return new import_util12.PermissionsBitField(this._effectivePermissions([], []));
3784
+ return new import_util17.PermissionsBitField(this._effectivePermissions([], []));
2976
3785
  }
2977
3786
  /**
2978
3787
  * Effective permissions in a channel (roles + overwrites).
@@ -2980,8 +3789,8 @@ var GuildMember = class _GuildMember extends Base {
2980
3789
  * @returns Computed permissions bitfield
2981
3790
  */
2982
3791
  permissionsIn(channel) {
2983
- return new import_util12.PermissionsBitField(
2984
- this._effectivePermissions(channel.permissionOverwrites, [...this.roles.roleIds])
3792
+ return new import_util17.PermissionsBitField(
3793
+ this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
2985
3794
  );
2986
3795
  }
2987
3796
  /**
@@ -2992,6 +3801,63 @@ var GuildMember = class _GuildMember extends Base {
2992
3801
  async move(channelId, connectionId) {
2993
3802
  await this.edit({ channelId, connectionId });
2994
3803
  }
3804
+ /** Kick this member. Requires Kick Members. */
3805
+ async kick() {
3806
+ await this.guild.kick(this.id);
3807
+ }
3808
+ /** Ban this member. Requires Ban Members. */
3809
+ async ban(options) {
3810
+ await this.guild.ban(this.id, options);
3811
+ }
3812
+ /**
3813
+ * Whether the bot can kick this member (cache-only; needs `members.me`).
3814
+ * False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
3815
+ */
3816
+ get kickable() {
3817
+ return this._moderatableWith(import_util17.PermissionFlags.KickMembers);
3818
+ }
3819
+ /**
3820
+ * Whether the bot can ban this member (cache-only; needs `members.me`).
3821
+ */
3822
+ get bannable() {
3823
+ return this._moderatableWith(import_util17.PermissionFlags.BanMembers);
3824
+ }
3825
+ /**
3826
+ * Whether the bot can timeout this member (cache-only; needs `members.me`).
3827
+ */
3828
+ get moderatable() {
3829
+ return this._moderatableWith(import_util17.PermissionFlags.ModerateMembers);
3830
+ }
3831
+ _moderatableWith(flag) {
3832
+ const me = this.guild.members.me;
3833
+ if (!me) return false;
3834
+ if (this.id === me.id) return false;
3835
+ if (this.guild.ownerId != null && String(this.guild.ownerId) === String(this.id)) return false;
3836
+ if (!me.permissions.has(flag)) return false;
3837
+ return this._compareRolePosition(me) < 0;
3838
+ }
3839
+ /** Negative when this member's highest role is below `other`'s. */
3840
+ _compareRolePosition(other) {
3841
+ const highest = (m) => {
3842
+ let pos = -1;
3843
+ for (const role of m.roles.cache.values()) {
3844
+ if (role.position > pos) pos = role.position;
3845
+ }
3846
+ return pos;
3847
+ };
3848
+ return highest(this) - highest(other);
3849
+ }
3850
+ /**
3851
+ * Timeout this member for `durationMs` milliseconds, or pass `null` to clear.
3852
+ * Requires Moderate Members.
3853
+ */
3854
+ async timeout(durationMs, reason) {
3855
+ const communicationDisabledUntil = durationMs == null || durationMs <= 0 ? null : new Date(Date.now() + durationMs).toISOString();
3856
+ return this.edit({
3857
+ communicationDisabledUntil,
3858
+ ...reason !== void 0 ? { timeoutReason: reason } : {}
3859
+ });
3860
+ }
2995
3861
  _effectivePermissions(overwrites, roleIds) {
2996
3862
  const ownerId = this.guild.ownerId;
2997
3863
  const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
@@ -3011,8 +3877,8 @@ var GuildMember = class _GuildMember extends Base {
3011
3877
  };
3012
3878
 
3013
3879
  // src/Domain/Guild/GuildSticker.ts
3014
- var import_types20 = require("@fluxerjs/types");
3015
- var import_util13 = require("@fluxerjs/util");
3880
+ var import_types21 = require("@fluxerjs/types");
3881
+ var import_util18 = require("@fluxerjs/util");
3016
3882
  var GuildSticker = class extends Base {
3017
3883
  client;
3018
3884
  id;
@@ -3054,15 +3920,15 @@ var GuildSticker = class extends Base {
3054
3920
  }
3055
3921
  /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
3056
3922
  get createdTimestamp() {
3057
- return import_util13.SnowflakeUtil.timestampFromSnowflake(this.id);
3923
+ return import_util18.SnowflakeUtil.timestampFromSnowflake(this.id);
3058
3924
  }
3059
3925
  /** Date when this sticker was created, derived from its snowflake ID. */
3060
3926
  get createdAt() {
3061
- return import_util13.SnowflakeUtil.dateFromSnowflake(this.id);
3927
+ return import_util18.SnowflakeUtil.dateFromSnowflake(this.id);
3062
3928
  }
3063
3929
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3064
3930
  async delete() {
3065
- await this.client.rest.delete(import_types20.Routes.guildSticker(this.guildId, this.id), {
3931
+ await this.client.rest.delete(import_types21.Routes.guildSticker(this.guildId, this.id), {
3066
3932
  auth: true
3067
3933
  });
3068
3934
  const guild = this.client.guilds.get(this.guildId);
@@ -3073,7 +3939,7 @@ var GuildSticker = class extends Base {
3073
3939
  * Requires Manage Emojis and Stickers permission.
3074
3940
  */
3075
3941
  async edit(options) {
3076
- const data = await this.client.rest.patch(import_types20.Routes.guildSticker(this.guildId, this.id), {
3942
+ const data = await this.client.rest.patch(import_types21.Routes.guildSticker(this.guildId, this.id), {
3077
3943
  body: options,
3078
3944
  auth: true
3079
3945
  });
@@ -3085,8 +3951,8 @@ var GuildSticker = class extends Base {
3085
3951
  };
3086
3952
 
3087
3953
  // src/Domain/Guild/Role.ts
3088
- var import_types21 = require("@fluxerjs/types");
3089
- var import_util14 = require("@fluxerjs/util");
3954
+ var import_types22 = require("@fluxerjs/types");
3955
+ var import_util19 = require("@fluxerjs/util");
3090
3956
  var Role = class _Role extends Base {
3091
3957
  /** Parent client instance. */
3092
3958
  client;
@@ -3129,21 +3995,29 @@ var Role = class _Role extends Base {
3129
3995
  */
3130
3996
  get permissions() {
3131
3997
  const bits = BigInt(this._permissions);
3132
- return new import_util14.PermissionsBitField(
3133
- (bits & import_util14.PermissionFlags.Administrator) !== 0n ? import_util14.ALL_PERMISSIONS_BIGINT : bits
3998
+ return new import_util19.PermissionsBitField(
3999
+ (bits & import_util19.PermissionFlags.Administrator) !== 0n ? import_util19.ALL_PERMISSIONS_BIGINT : bits
3134
4000
  );
3135
4001
  }
4002
+ /**
4003
+ * Alias of {@link permissions}.has for discord.js-style checks.
4004
+ * @example
4005
+ * if (role.has(PermissionFlags.BanMembers)) { ... }
4006
+ */
4007
+ has(permission) {
4008
+ return this.permissions.has(permission);
4009
+ }
3136
4010
  /**
3137
4011
  * Format as a mention string (`<@&id>`).
3138
4012
  * @returns Mention syntax
3139
4013
  */
3140
4014
  /** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
3141
4015
  get createdTimestamp() {
3142
- return import_util14.SnowflakeUtil.timestampFromSnowflake(this.id);
4016
+ return import_util19.SnowflakeUtil.timestampFromSnowflake(this.id);
3143
4017
  }
3144
4018
  /** Date when this role was created, derived from its snowflake ID. */
3145
4019
  get createdAt() {
3146
- return import_util14.SnowflakeUtil.dateFromSnowflake(this.id);
4020
+ return import_util19.SnowflakeUtil.dateFromSnowflake(this.id);
3147
4021
  }
3148
4022
  toString() {
3149
4023
  return `<@&${this.id}>`;
@@ -3186,8 +4060,8 @@ var Role = class _Role extends Base {
3186
4060
  * @returns This role instance (updated in-place)
3187
4061
  */
3188
4062
  async edit(options) {
3189
- const body = toRoleRequestBody(options);
3190
- const data = await this.client.rest.patch(import_types21.Routes.guildRole(this.guildId, this.id), {
4063
+ const body = toRoleEditBody(options);
4064
+ const data = await this.client.rest.patch(import_types22.Routes.guildRole(this.guildId, this.id), {
3191
4065
  body: Object.keys(body).length ? body : void 0,
3192
4066
  auth: true
3193
4067
  });
@@ -3198,7 +4072,7 @@ var Role = class _Role extends Base {
3198
4072
  * DELETE role. Requires Manage Roles.
3199
4073
  */
3200
4074
  async delete() {
3201
- await this.client.rest.delete(import_types21.Routes.guildRole(this.guildId, this.id), { auth: true });
4075
+ await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), { auth: true });
3202
4076
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
3203
4077
  }
3204
4078
  };
@@ -3206,17 +4080,15 @@ var Role = class _Role extends Base {
3206
4080
  // src/Domain/Guild/Cache.ts
3207
4081
  function putChannel(client, channel, guild) {
3208
4082
  client.channels.set(channel.id, channel);
3209
- const resolvedGuild = guild ?? (() => {
3210
- const guildId = "guildId" in channel ? channel.guildId : void 0;
3211
- return guildId ? client.guilds.get(guildId) : void 0;
3212
- })();
4083
+ if (!channel.isGuild()) return;
4084
+ const resolvedGuild = guild ?? (channel.guildId ? client.guilds.get(channel.guildId) : void 0);
3213
4085
  if (resolvedGuild) {
3214
4086
  resolvedGuild.channels.set(channel.id, channel);
3215
4087
  }
3216
4088
  }
3217
4089
  function cacheChannel(guild, data) {
3218
4090
  const existing = guild.channels.get(data.id) ?? guild.client.channels.get(data.id);
3219
- if (existing && "guildId" in existing && existing.type === data.type) {
4091
+ if (existing?.isGuild() && existing.type === data.type) {
3220
4092
  existing._patch(data);
3221
4093
  putChannel(guild.client, existing, guild);
3222
4094
  return existing;
@@ -3322,7 +4194,7 @@ function syncStickers(guild, stickers) {
3322
4194
  }
3323
4195
 
3324
4196
  // src/ClientCore/ChannelManager.ts
3325
- var ChannelManager = class extends import_collection6.LimitedCollection {
4197
+ var ChannelManager = class extends import_collection8.LimitedCollection {
3326
4198
  constructor(client) {
3327
4199
  super({
3328
4200
  maxSize: client.cache.limits.channels,
@@ -3330,6 +4202,10 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3330
4202
  });
3331
4203
  this.client = client;
3332
4204
  }
4205
+ /**
4206
+ * Remove a channel from cache. Does not delete it on the API.
4207
+ * Use {@link Channel.delete} after {@link fetch} to delete the channel.
4208
+ */
3333
4209
  delete(key) {
3334
4210
  const channel = this.get(key);
3335
4211
  const deleted = super.delete(key);
@@ -3343,15 +4219,20 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3343
4219
  return this.get(channelId) ?? this.fetch(channelId);
3344
4220
  }
3345
4221
  /**
3346
- * Fetch a channel by ID.
3347
- * Returns the cached channel unless `force` is set, in which case REST metadata is applied.
4222
+ * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
4223
+ * and {@link Channel.send} (send throws if the type is not text-based).
4224
+ * Returns the cached channel unless `force` is set.
4225
+ * @example
4226
+ * const channel = await client.channels.fetch(channelId);
4227
+ * await channel.delete();
4228
+ * await channel.send('hi');
3348
4229
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
3349
4230
  */
3350
4231
  async fetch(channelId, options) {
3351
4232
  const cached = this.get(channelId);
3352
4233
  if (cached && !options?.force) return cached;
3353
4234
  try {
3354
- const data = await this.client.rest.get(import_types22.Routes.channel(channelId));
4235
+ const data = await this.client.rest.get(import_types23.Routes.channel(channelId));
3355
4236
  const guildId = "guild_id" in data ? data.guild_id : void 0;
3356
4237
  if (guildId) {
3357
4238
  const guild = this.client.guilds.get(guildId);
@@ -3362,8 +4243,8 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3362
4243
  }
3363
4244
  const channel = Channel.fromOrCreate(this.client, data);
3364
4245
  if (!channel) {
3365
- throw new import_util3.FluxerError("Channel data invalid or unsupported type", {
3366
- code: import_util2.ErrorCodes.ChannelNotFound
4246
+ throw new import_util4.FluxerError("Channel data invalid or unsupported type", {
4247
+ code: import_util3.ErrorCodes.ChannelNotFound
3367
4248
  });
3368
4249
  }
3369
4250
  putChannel(this.client, channel);
@@ -3371,7 +4252,7 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3371
4252
  } catch (err) {
3372
4253
  rethrowMapped(err, {
3373
4254
  notFound: {
3374
- code: import_util2.ErrorCodes.ChannelNotFound,
4255
+ code: import_util3.ErrorCodes.ChannelNotFound,
3375
4256
  message: `Channel ${channelId} not found`
3376
4257
  },
3377
4258
  fallback: `Channel ${channelId} not found`
@@ -3387,6 +4268,7 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3387
4268
  }
3388
4269
  /**
3389
4270
  * Send to a channel by ID without resolving it first.
4271
+ * Prefer {@link Channel.send} after {@link fetch} when you want the channel object.
3390
4272
  * @example
3391
4273
  * await client.channels.send(logChannelId, 'User joined!');
3392
4274
  */
@@ -3395,7 +4277,7 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3395
4277
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
3396
4278
  });
3397
4279
  const data = await this.client.rest.post(
3398
- import_types22.Routes.channelMessages(channelId),
4280
+ import_types23.Routes.channelMessages(channelId),
3399
4281
  postPayload
3400
4282
  );
3401
4283
  this.client._addMessageToCache(channelId, data);
@@ -3404,83 +4286,86 @@ var ChannelManager = class extends import_collection6.LimitedCollection {
3404
4286
  };
3405
4287
 
3406
4288
  // src/ClientCore/ClientEmoji.ts
3407
- var import_collection7 = require("@fluxerjs/collection");
3408
- var import_types23 = require("@fluxerjs/types");
3409
- var import_util15 = require("@fluxerjs/util");
4289
+ var import_collection9 = require("@fluxerjs/collection");
4290
+ var import_types24 = require("@fluxerjs/types");
4291
+ var import_util20 = require("@fluxerjs/util");
3410
4292
  async function resolveClientEmoji(client, emoji, guildId) {
3411
4293
  if (typeof emoji === "object" && emoji.id) {
3412
- return (0, import_util15.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
4294
+ return (0, import_util20.formatEmoji)({ name: emoji.name, id: emoji.id, animated: emoji.animated });
3413
4295
  }
3414
- const parsed = (0, import_util15.parseEmoji)(
4296
+ const parsed = (0, import_util20.parseEmoji)(
3415
4297
  typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
3416
4298
  );
3417
4299
  if (!parsed) {
3418
- throw new import_util3.FluxerError("Invalid emoji", { code: import_util2.ErrorCodes.InvalidEmoji });
4300
+ throw new import_util4.FluxerError("Invalid emoji", { code: import_util3.ErrorCodes.InvalidEmoji });
3419
4301
  }
3420
4302
  if (parsed.id) {
3421
- return (0, import_util15.formatEmoji)(parsed);
4303
+ return (0, import_util20.formatEmoji)(parsed);
3422
4304
  }
3423
4305
  if (!/^\w+$/.test(parsed.name)) return parsed.name;
3424
- const unicodeFromShortcode = (0, import_util15.getUnicodeFromShortcode)(parsed.name);
4306
+ const unicodeFromShortcode = (0, import_util20.getUnicodeFromShortcode)(parsed.name);
3425
4307
  if (unicodeFromShortcode) return unicodeFromShortcode;
3426
4308
  if (guildId) {
3427
- const emojis = await client.rest.get(import_types23.Routes.guildEmojis(guildId));
4309
+ const emojis = await client.rest.get(import_types24.Routes.guildEmojis(guildId));
3428
4310
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
3429
- if (found) return (0, import_util15.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
3430
- throw new import_util3.FluxerError(
4311
+ if (found) return (0, import_util20.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
4312
+ throw new import_util4.FluxerError(
3431
4313
  `Custom emoji ":${parsed.name}:" not found in guild. Use name:id or <:name:id> format.`,
3432
- { code: import_util2.ErrorCodes.EmojiNotFound }
4314
+ { code: import_util3.ErrorCodes.EmojiNotFound }
3433
4315
  );
3434
4316
  }
3435
4317
  if (/^\w+$/.test(parsed.name)) {
3436
- throw new import_util3.FluxerError(
4318
+ throw new import_util4.FluxerError(
3437
4319
  `Custom emoji ":${parsed.name}:" requires guild context. Use message.react() in a guild channel, or pass guildId to client.resolveEmoji().`,
3438
- { code: import_util2.ErrorCodes.EmojiRequiresGuild }
4320
+ { code: import_util3.ErrorCodes.EmojiRequiresGuild }
3439
4321
  );
3440
4322
  }
3441
4323
  return parsed.name;
3442
4324
  }
3443
4325
  async function fetchInstance(client) {
3444
- const raw = await client.rest.get(import_types23.Routes.instanceDiscovery(), { auth: false });
4326
+ const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), { auth: false });
3445
4327
  return parseInstanceDiscovery(raw);
3446
4328
  }
3447
4329
  function fetchGatewayInfo(client) {
3448
- return client.rest.get(import_types23.Routes.gatewayBot());
4330
+ return client.rest.get(import_types24.Routes.gatewayBot());
3449
4331
  }
3450
4332
  function fetchEmojiMetadata(client, emojiId) {
3451
- return client.rest.get(import_types23.Routes.emojiMetadata(emojiId), { auth: true });
4333
+ return client.rest.get(import_types24.Routes.emojiMetadata(emojiId), { auth: true });
3452
4334
  }
3453
4335
  function fetchStickerMetadata(client, stickerId) {
3454
- return client.rest.get(import_types23.Routes.stickerMetadata(stickerId), { auth: true });
4336
+ return client.rest.get(import_types24.Routes.stickerMetadata(stickerId), { auth: true });
3455
4337
  }
3456
4338
  function fetchApplication(client) {
3457
- return client.rest.get(import_types23.Routes.applicationsMe(), { auth: true });
4339
+ return client.rest.get(import_types24.Routes.applicationsMe(), { auth: true });
3458
4340
  }
3459
4341
  async function fetchOAuthApplications(client) {
3460
- const data = await client.rest.get(import_types23.Routes.oauth2ApplicationsMe(), { auth: true });
3461
- return Array.isArray(data) ? data : data.applications ?? [];
3462
- }
3463
- function checkUsernameTag(client, username, discriminator) {
3464
- const params = new URLSearchParams({ username, discriminator });
3465
- return client.rest.get(`${import_types23.Routes.checkUsernameTag()}?${params}`, { auth: true });
4342
+ const data = await client.rest.get(import_types24.Routes.oauth2ApplicationsMe(), { auth: true });
4343
+ if (Array.isArray(data)) return data;
4344
+ if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
4345
+ return data.applications;
4346
+ }
4347
+ if (data && typeof data === "object" && "id" in data && typeof data.id === "string") {
4348
+ return [data];
4349
+ }
4350
+ return [];
3466
4351
  }
3467
4352
  function assertChannelIdBatch(name, channelIds) {
3468
4353
  if (channelIds.length < 1 || channelIds.length > 100) {
3469
- throw new import_util3.FluxerError(`${name} requires between 1 and 100 channel IDs`, {
3470
- code: import_util2.ErrorCodes.InvalidFetchLimit
4354
+ throw new import_util4.FluxerError(`${name} requires between 1 and 100 channel IDs`, {
4355
+ code: import_util3.ErrorCodes.InvalidFetchLimit
3471
4356
  });
3472
4357
  }
3473
4358
  }
3474
4359
  function preloadMessages(client, channelIds) {
3475
4360
  assertChannelIdBatch("preloadMessages", channelIds);
3476
- return client.rest.post(import_types23.Routes.preloadMessages(), {
4361
+ return client.rest.post(import_types24.Routes.preloadMessages(), {
3477
4362
  body: { channels: channelIds },
3478
4363
  auth: true
3479
4364
  });
3480
4365
  }
3481
4366
  function preloadMessagesAlt(client, channelIds) {
3482
4367
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
3483
- return client.rest.post(import_types23.Routes.preloadMessagesAlt(), {
4368
+ return client.rest.post(import_types24.Routes.preloadMessagesAlt(), {
3484
4369
  body: { channels: channelIds },
3485
4370
  auth: true
3486
4371
  });
@@ -3488,14 +4373,14 @@ function preloadMessagesAlt(client, channelIds) {
3488
4373
  async function bulkFetchMessages(client, requests, options = {}) {
3489
4374
  validateBulkMessageFetchRequests(requests);
3490
4375
  const wire = toBulkFetchWire(requests);
3491
- const data = await client.rest.post(import_types23.Routes.channelsMessagesBulk(), {
4376
+ const data = await client.rest.post(import_types24.Routes.channelsMessagesBulk(), {
3492
4377
  body: { requests: wire },
3493
4378
  auth: true
3494
4379
  });
3495
4380
  if (options.hydrate === false) return data;
3496
4381
  return {
3497
4382
  channels: data.channels.map((entry) => {
3498
- const collection = new import_collection7.Collection();
4383
+ const collection = new import_collection9.Collection();
3499
4384
  for (const msg of entry.messages) {
3500
4385
  client._addMessageToCache(entry.channel_id, msg);
3501
4386
  collection.set(msg.id, new Message(client, msg));
@@ -3504,6 +4389,13 @@ async function bulkFetchMessages(client, requests, options = {}) {
3504
4389
  })
3505
4390
  };
3506
4391
  }
4392
+ async function searchMessages(client, options = {}) {
4393
+ const data = await client.rest.post(import_types24.Routes.searchMessages(), {
4394
+ body: toMessageSearchBody(options),
4395
+ auth: true
4396
+ });
4397
+ return toMessageSearchResponse(data);
4398
+ }
3507
4399
 
3508
4400
  // src/ClientCore/ClientEvents.ts
3509
4401
  function createEventMethods(client) {
@@ -3522,14 +4414,14 @@ function createEventMethods(client) {
3522
4414
  var import_ws = require("@fluxerjs/ws");
3523
4415
 
3524
4416
  // src/Domain/Guild/Guild.ts
3525
- var import_collection9 = require("@fluxerjs/collection");
3526
- var import_types33 = require("@fluxerjs/types");
3527
- var import_util17 = require("@fluxerjs/util");
4417
+ var import_collection12 = require("@fluxerjs/collection");
4418
+ var import_types34 = require("@fluxerjs/types");
4419
+ var import_util22 = require("@fluxerjs/util");
3528
4420
 
3529
4421
  // src/ClientCore/GuildMemberManager.ts
3530
- var import_collection8 = require("@fluxerjs/collection");
3531
- var import_types24 = require("@fluxerjs/types");
3532
- var GuildMemberManager = class extends import_collection8.LimitedCollection {
4422
+ var import_collection10 = require("@fluxerjs/collection");
4423
+ var import_types25 = require("@fluxerjs/types");
4424
+ var GuildMemberManager = class extends import_collection10.LimitedCollection {
3533
4425
  constructor(guild) {
3534
4426
  super({ maxSize: guild.client.cache.limits.members });
3535
4427
  this.guild = guild;
@@ -3545,7 +4437,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3545
4437
  * console.log(member.displayName);
3546
4438
  */
3547
4439
  async resolve(userId) {
3548
- return this.get(userId) ?? this.guild.fetchMember(userId);
4440
+ return this.get(userId) ?? this.fetch(userId);
3549
4441
  }
3550
4442
  /**
3551
4443
  * The current bot user as a GuildMember in this guild.
@@ -3572,17 +4464,20 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3572
4464
  async fetchMe() {
3573
4465
  return this.guild.fetchMe();
3574
4466
  }
3575
- /**
3576
- * Fetch guild members with pagination. GET /guilds/{id}/members.
3577
- * @param options - limit (1-1000), after (user ID for pagination)
3578
- * @returns Array of GuildMember objects (cached in guild.members)
3579
- */
3580
- async fetch(options) {
4467
+ async fetch(userIdOrOptions, options) {
4468
+ if (typeof userIdOrOptions === "string") {
4469
+ const cached = this.get(userIdOrOptions);
4470
+ if (cached && !options?.force) return cached;
4471
+ return this.guild.fetchMember(userIdOrOptions);
4472
+ }
4473
+ return this.fetchMany(userIdOrOptions);
4474
+ }
4475
+ async fetchMany(options) {
3581
4476
  const params = new URLSearchParams();
3582
4477
  if (options?.limit != null) params.set("limit", String(options.limit));
3583
4478
  if (options?.after) params.set("after", options.after);
3584
4479
  const qs2 = params.toString();
3585
- const url = import_types24.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
4480
+ const url = import_types25.Routes.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
3586
4481
  const data = await this.guild.client.rest.get(url, { auth: true });
3587
4482
  const members = [];
3588
4483
  for (const m of data) {
@@ -3605,7 +4500,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3605
4500
  */
3606
4501
  async search(options = {}) {
3607
4502
  const data = await this.guild.client.rest.post(
3608
- import_types24.Routes.guildMembersSearch(this.guild.id),
4503
+ import_types25.Routes.guildMembersSearch(this.guild.id),
3609
4504
  { body: toMemberSearchBody(options), auth: true }
3610
4505
  );
3611
4506
  const offset = options.offset ?? 0;
@@ -3631,7 +4526,7 @@ var GuildMemberManager = class extends import_collection8.LimitedCollection {
3631
4526
  };
3632
4527
 
3633
4528
  // src/Domain/Guild/Admin.ts
3634
- var import_types25 = require("@fluxerjs/types");
4529
+ var import_types26 = require("@fluxerjs/types");
3635
4530
  function toAuditLogEntryPayload(entry, guildId) {
3636
4531
  return {
3637
4532
  id: entry.id,
@@ -3652,7 +4547,7 @@ function toVanityPayload(data) {
3652
4547
  return { code: data.code ?? null, uses: data.uses };
3653
4548
  }
3654
4549
  async function fetchAuditLogs(guild, options) {
3655
- const url = import_types25.Routes.guildAuditLogs(guild.id) + qs({
4550
+ const url = import_types26.Routes.guildAuditLogs(guild.id) + qs({
3656
4551
  limit: options?.limit,
3657
4552
  before: options?.before,
3658
4553
  after: options?.after,
@@ -3676,7 +4571,7 @@ async function fetchAuditLogs(guild, options) {
3676
4571
  };
3677
4572
  }
3678
4573
  async function editGuild(guild, options) {
3679
- const data = await guild.client.rest.patch(import_types25.Routes.guild(guild.id), {
4574
+ const data = await guild.client.rest.patch(import_types26.Routes.guild(guild.id), {
3680
4575
  body: toGuildEditBody(options),
3681
4576
  auth: true
3682
4577
  });
@@ -3684,13 +4579,13 @@ async function editGuild(guild, options) {
3684
4579
  return guild;
3685
4580
  }
3686
4581
  async function fetchVanityURL(guild) {
3687
- const data = await guild.client.rest.get(import_types25.Routes.guildVanityUrl(guild.id), {
4582
+ const data = await guild.client.rest.get(import_types26.Routes.guildVanityUrl(guild.id), {
3688
4583
  auth: true
3689
4584
  });
3690
4585
  return toVanityPayload(data);
3691
4586
  }
3692
4587
  async function editVanityURL(guild, code) {
3693
- const data = await guild.client.rest.patch(import_types25.Routes.guildVanityUrl(guild.id), {
4588
+ const data = await guild.client.rest.patch(import_types26.Routes.guildVanityUrl(guild.id), {
3694
4589
  body: { code },
3695
4590
  auth: true
3696
4591
  });
@@ -3698,14 +4593,14 @@ async function editVanityURL(guild, code) {
3698
4593
  return toVanityPayload(data);
3699
4594
  }
3700
4595
  async function fetchDiscoveryStatus(guild) {
3701
- const data = await guild.client.rest.get(import_types25.Routes.guildDiscovery(guild.id), {
4596
+ const data = await guild.client.rest.get(import_types26.Routes.guildDiscovery(guild.id), {
3702
4597
  auth: true
3703
4598
  });
3704
4599
  return toDiscoveryStatusPayload(data);
3705
4600
  }
3706
4601
  async function applyForDiscovery(guild, options) {
3707
4602
  const data = await guild.client.rest.post(
3708
- import_types25.Routes.guildDiscovery(guild.id),
4603
+ import_types26.Routes.guildDiscovery(guild.id),
3709
4604
  {
3710
4605
  body: toDiscoveryBody(options),
3711
4606
  auth: true
@@ -3715,7 +4610,7 @@ async function applyForDiscovery(guild, options) {
3715
4610
  }
3716
4611
  async function editDiscoveryApplication(guild, options) {
3717
4612
  const data = await guild.client.rest.patch(
3718
- import_types25.Routes.guildDiscovery(guild.id),
4613
+ import_types26.Routes.guildDiscovery(guild.id),
3719
4614
  {
3720
4615
  body: toDiscoveryBody(options),
3721
4616
  auth: true
@@ -3724,34 +4619,34 @@ async function editDiscoveryApplication(guild, options) {
3724
4619
  return toDiscoveryApplicationPayload(data);
3725
4620
  }
3726
4621
  async function withdrawDiscoveryApplication(guild) {
3727
- await guild.client.rest.delete(import_types25.Routes.guildDiscovery(guild.id), { auth: true });
4622
+ await guild.client.rest.delete(import_types26.Routes.guildDiscovery(guild.id), { auth: true });
3728
4623
  }
3729
4624
  async function deleteGuild(guild, options) {
3730
4625
  const body = options ? toSudoBody(options) : {};
3731
- await guild.client.rest.post(import_types25.Routes.guildDelete(guild.id), {
4626
+ await guild.client.rest.post(import_types26.Routes.guildDelete(guild.id), {
3732
4627
  body,
3733
4628
  auth: true
3734
4629
  });
3735
4630
  guild.client.guilds.delete(guild.id);
3736
4631
  }
3737
4632
  async function transferOwnership(guild, newOwnerId, password) {
3738
- await guild.client.rest.post(import_types25.Routes.guildTransferOwnership(guild.id), {
4633
+ await guild.client.rest.post(import_types26.Routes.guildTransferOwnership(guild.id), {
3739
4634
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
3740
4635
  auth: true
3741
4636
  });
3742
4637
  }
3743
4638
 
3744
4639
  // src/Domain/Guild/Channels.ts
3745
- var import_types26 = require("@fluxerjs/types");
3746
- async function createChannel(guild, data) {
3747
- const created = await guild.client.rest.post(import_types26.Routes.guildChannels(guild.id), {
3748
- body: data,
4640
+ var import_types27 = require("@fluxerjs/types");
4641
+ async function createChannel(guild, options) {
4642
+ const created = await guild.client.rest.post(import_types27.Routes.guildChannels(guild.id), {
4643
+ body: toChannelCreateBody(options),
3749
4644
  auth: true
3750
4645
  });
3751
4646
  return cacheChannel(guild, created);
3752
4647
  }
3753
4648
  async function fetchChannels(guild) {
3754
- const data = await guild.client.rest.get(import_types26.Routes.guildChannels(guild.id));
4649
+ const data = await guild.client.rest.get(import_types27.Routes.guildChannels(guild.id));
3755
4650
  const channels = [];
3756
4651
  for (const ch of data) {
3757
4652
  const channel = cacheChannel(guild, ch);
@@ -3760,17 +4655,17 @@ async function fetchChannels(guild) {
3760
4655
  return channels;
3761
4656
  }
3762
4657
  async function setChannelPositions(guild, updates) {
3763
- await guild.client.rest.patch(import_types26.Routes.guildChannels(guild.id), {
4658
+ await guild.client.rest.patch(import_types27.Routes.guildChannels(guild.id), {
3764
4659
  body: toChannelPositionBody(updates),
3765
4660
  auth: true
3766
4661
  });
3767
4662
  }
3768
4663
  async function fetchWebhooks(guild) {
3769
- const data = await guild.client.rest.get(import_types26.Routes.guildWebhooks(guild.id));
4664
+ const data = await guild.client.rest.get(import_types27.Routes.guildWebhooks(guild.id));
3770
4665
  return data.map((w) => new Webhook(guild.client, w));
3771
4666
  }
3772
4667
  async function fetchInvites(guild) {
3773
- const data = await guild.client.rest.get(import_types26.Routes.guildInvites(guild.id));
4668
+ const data = await guild.client.rest.get(import_types27.Routes.guildInvites(guild.id));
3774
4669
  return data.map((invite) => new Invite(guild.client, invite));
3775
4670
  }
3776
4671
  async function fetchInvite(guild, codeOrUrl) {
@@ -3790,31 +4685,31 @@ function resolveGuildOnlineCount(data) {
3790
4685
  }
3791
4686
 
3792
4687
  // src/Domain/Guild/Emojis.ts
3793
- var import_types27 = require("@fluxerjs/types");
4688
+ var import_types28 = require("@fluxerjs/types");
3794
4689
  async function fetchEmojis(guild) {
3795
- const data = await guild.client.rest.get(import_types27.Routes.guildEmojis(guild.id));
4690
+ const data = await guild.client.rest.get(import_types28.Routes.guildEmojis(guild.id));
3796
4691
  return data.map((e) => cacheEmoji(guild, e));
3797
4692
  }
3798
4693
  async function fetchEmoji(guild, emojiId) {
3799
4694
  try {
3800
- const data = await guild.client.rest.get(import_types27.Routes.guildEmoji(guild.id, emojiId));
4695
+ const data = await guild.client.rest.get(import_types28.Routes.guildEmoji(guild.id, emojiId));
3801
4696
  return cacheEmoji(guild, data);
3802
4697
  } catch (err) {
3803
4698
  rethrowMapped(err, {
3804
- notFound: { code: import_util2.ErrorCodes.EmojiNotFound, message: `Emoji ${emojiId} not found in guild` },
4699
+ notFound: { code: import_util3.ErrorCodes.EmojiNotFound, message: `Emoji ${emojiId} not found in guild` },
3805
4700
  fallback: "Failed to fetch guild emoji"
3806
4701
  });
3807
4702
  }
3808
4703
  }
3809
4704
  async function createEmoji(guild, options) {
3810
- const data = await guild.client.rest.post(import_types27.Routes.guildEmojis(guild.id), {
4705
+ const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
3811
4706
  body: options,
3812
4707
  auth: true
3813
4708
  });
3814
4709
  return cacheEmoji(guild, data);
3815
4710
  }
3816
4711
  async function cloneEmoji(guild, sourceEmojiId) {
3817
- const data = await guild.client.rest.post(import_types27.Routes.guildEmojisClone(guild.id), {
4712
+ const data = await guild.client.rest.post(import_types28.Routes.guildEmojisClone(guild.id), {
3818
4713
  body: { source_emoji_id: sourceEmojiId },
3819
4714
  auth: true
3820
4715
  });
@@ -3822,24 +4717,24 @@ async function cloneEmoji(guild, sourceEmojiId) {
3822
4717
  }
3823
4718
  async function createEmojisBulk(guild, emojis) {
3824
4719
  const data = await guild.client.rest.post(
3825
- import_types27.Routes.guildEmojisBulk(guild.id),
4720
+ import_types28.Routes.guildEmojisBulk(guild.id),
3826
4721
  { body: { emojis }, auth: true }
3827
4722
  );
3828
4723
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
3829
4724
  }
3830
4725
 
3831
4726
  // src/Domain/Guild/MemberHttp.ts
3832
- var import_types28 = require("@fluxerjs/types");
4727
+ var import_types29 = require("@fluxerjs/types");
3833
4728
  async function fetchMember(guild, userId) {
3834
4729
  try {
3835
4730
  const data = await guild.client.rest.get(
3836
- import_types28.Routes.guildMember(guild.id, userId)
4731
+ import_types29.Routes.guildMember(guild.id, userId)
3837
4732
  );
3838
4733
  return cacheMember(guild, data);
3839
4734
  } catch (err) {
3840
4735
  rethrowMapped(err, {
3841
4736
  notFound: {
3842
- code: import_util2.ErrorCodes.MemberNotFound,
4737
+ code: import_util3.ErrorCodes.MemberNotFound,
3843
4738
  message: `Member ${userId} not found in guild`
3844
4739
  },
3845
4740
  fallback: "Failed to fetch guild member"
@@ -3848,23 +4743,28 @@ async function fetchMember(guild, userId) {
3848
4743
  }
3849
4744
  async function fetchMe(guild) {
3850
4745
  const data = await guild.client.rest.get(
3851
- import_types28.Routes.guildMemberMe(guild.id),
4746
+ import_types29.Routes.guildMemberMe(guild.id),
3852
4747
  { auth: true }
3853
4748
  );
3854
4749
  return cacheMember(guild, data);
3855
4750
  }
3856
4751
 
3857
4752
  // src/Domain/Guild/Moderation.ts
3858
- var import_types30 = require("@fluxerjs/types");
4753
+ var import_types31 = require("@fluxerjs/types");
3859
4754
 
3860
4755
  // src/Domain/Guild/GuildBan.ts
3861
- var import_types29 = require("@fluxerjs/types");
4756
+ var import_types30 = require("@fluxerjs/types");
4757
+ function parseOptionalDate2(value) {
4758
+ if (value == null || value === "") return null;
4759
+ const date = new Date(value);
4760
+ return Number.isNaN(date.getTime()) ? null : date;
4761
+ }
3862
4762
  var GuildBan = class extends Base {
3863
4763
  client;
3864
4764
  guildId;
3865
4765
  user;
3866
4766
  reason;
3867
- /** ISO timestamp when a temporary ban expires. Null for permanent bans. */
4767
+ /** When a temporary ban expires. Null for permanent bans. */
3868
4768
  expiresAt;
3869
4769
  /** @param data - API ban from GET /guilds/{id}/bans or gateway GUILD_BAN_ADD */
3870
4770
  constructor(client, data, guildId) {
@@ -3873,14 +4773,14 @@ var GuildBan = class extends Base {
3873
4773
  this.guildId = data.guild_id ?? guildId;
3874
4774
  this.user = client.getOrCreateUser(data.user);
3875
4775
  this.reason = data.reason ?? null;
3876
- this.expiresAt = data.expires_at ?? null;
4776
+ this.expiresAt = parseOptionalDate2(data.expires_at);
3877
4777
  }
3878
4778
  /**
3879
4779
  * Remove this ban (unban the user).
3880
4780
  * Requires Ban Members permission.
3881
4781
  */
3882
4782
  async unban() {
3883
- await this.client.rest.delete(import_types29.Routes.guildBan(this.guildId, this.user.id), {
4783
+ await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
3884
4784
  auth: true
3885
4785
  });
3886
4786
  }
@@ -3889,57 +4789,70 @@ var GuildBan = class extends Base {
3889
4789
  // src/Domain/Guild/Moderation.ts
3890
4790
  async function ban(guild, userId, options) {
3891
4791
  const body = options ? toGuildBanBody(options) : {};
3892
- await guild.client.rest.put(import_types30.Routes.guildBan(guild.id, userId), {
4792
+ await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
3893
4793
  body: Object.keys(body).length ? body : void 0,
3894
4794
  auth: true
3895
4795
  });
3896
4796
  }
3897
4797
  async function fetchBans(guild) {
3898
- const data = await guild.client.rest.get(import_types30.Routes.guildBans(guild.id));
4798
+ const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
3899
4799
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
3900
4800
  }
3901
4801
  async function unban(guild, userId) {
3902
- await guild.client.rest.delete(import_types30.Routes.guildBan(guild.id, userId), { auth: true });
4802
+ await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), { auth: true });
3903
4803
  }
3904
4804
  async function kick(guild, userId) {
3905
- await guild.client.rest.delete(import_types30.Routes.guildMember(guild.id, userId), { auth: true });
4805
+ await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), { auth: true });
3906
4806
  }
3907
4807
 
4808
+ // src/Domain/Guild/GuildRoleManager.ts
4809
+ var import_collection11 = require("@fluxerjs/collection");
4810
+ var GuildRoleManager = class extends import_collection11.LimitedCollection {
4811
+ constructor(guildId, options) {
4812
+ super(options);
4813
+ this.guildId = guildId;
4814
+ }
4815
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4816
+ get everyone() {
4817
+ return this.get(this.guildId);
4818
+ }
4819
+ };
4820
+
3908
4821
  // src/Domain/Guild/Roles.ts
3909
- var import_types31 = require("@fluxerjs/types");
3910
- var import_util16 = require("@fluxerjs/util");
4822
+ var import_types32 = require("@fluxerjs/types");
4823
+ var import_util21 = require("@fluxerjs/util");
3911
4824
  async function createRole(guild, options = {}) {
3912
- const body = toRoleRequestBody(options);
3913
- const data = await guild.client.rest.post(import_types31.Routes.guildRoles(guild.id), {
4825
+ const body = toRoleCreateBody(options);
4826
+ const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
3914
4827
  body: Object.keys(body).length ? body : void 0,
3915
4828
  auth: true
3916
4829
  });
3917
4830
  return cacheRole(guild, data);
3918
4831
  }
3919
4832
  async function fetchRoles(guild) {
3920
- const data = await guild.client.rest.get(import_types31.Routes.guildRoles(guild.id));
4833
+ const data = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
3921
4834
  return data.map((r) => cacheRole(guild, r));
3922
4835
  }
3923
4836
  async function fetchRole(guild, roleId2) {
3924
4837
  try {
3925
- const data = await guild.client.rest.get(import_types31.Routes.guildRole(guild.id, roleId2));
4838
+ const data = await guild.client.rest.get(import_types32.Routes.guildRole(guild.id, roleId2));
3926
4839
  return cacheRole(guild, data);
3927
4840
  } catch (err) {
3928
4841
  rethrowMapped(err, {
3929
- notFound: { code: import_util2.ErrorCodes.RoleNotFound, message: `Role ${roleId2} not found in guild` },
4842
+ notFound: { code: import_util3.ErrorCodes.RoleNotFound, message: `Role ${roleId2} not found in guild` },
3930
4843
  fallback: "Failed to fetch guild role"
3931
4844
  });
3932
4845
  }
3933
4846
  }
3934
4847
  async function resolveRoleId(guild, arg) {
3935
- const parsed = (0, import_util16.parseRoleMention)(arg);
4848
+ const parsed = (0, import_util21.parseRoleMention)(arg);
3936
4849
  if (parsed) return parsed;
3937
4850
  const trimmed = arg.trim();
3938
4851
  if (/^\d{17,19}$/.test(trimmed)) return trimmed;
3939
4852
  const needle = trimmed.toLowerCase();
3940
4853
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
3941
4854
  if (cached) return cached.id;
3942
- const roles = await guild.client.rest.get(import_types31.Routes.guildRoles(guild.id));
4855
+ const roles = await guild.client.rest.get(import_types32.Routes.guildRoles(guild.id));
3943
4856
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
3944
4857
  if (!role) return null;
3945
4858
  cacheRole(guild, role);
@@ -3948,7 +4861,7 @@ async function resolveRoleId(guild, arg) {
3948
4861
  async function setRolePositions(guild, updates) {
3949
4862
  return replaceRoles(
3950
4863
  guild,
3951
- await guild.client.rest.patch(import_types31.Routes.guildRoles(guild.id), {
4864
+ await guild.client.rest.patch(import_types32.Routes.guildRoles(guild.id), {
3952
4865
  body: updates,
3953
4866
  auth: true
3954
4867
  })
@@ -3957,7 +4870,7 @@ async function setRolePositions(guild, updates) {
3957
4870
  async function setRoleHoistPositions(guild, updates) {
3958
4871
  return replaceRoles(
3959
4872
  guild,
3960
- await guild.client.rest.patch(import_types31.Routes.guildRolesHoistPositions(guild.id), {
4873
+ await guild.client.rest.patch(import_types32.Routes.guildRolesHoistPositions(guild.id), {
3961
4874
  body: updates.map((u) => ({
3962
4875
  id: u.id,
3963
4876
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -3969,23 +4882,23 @@ async function setRoleHoistPositions(guild, updates) {
3969
4882
  async function resetRoleHoistPositions(guild) {
3970
4883
  return replaceRoles(
3971
4884
  guild,
3972
- await guild.client.rest.delete(import_types31.Routes.guildRolesHoistPositions(guild.id), {
4885
+ await guild.client.rest.delete(import_types32.Routes.guildRolesHoistPositions(guild.id), {
3973
4886
  auth: true
3974
4887
  })
3975
4888
  );
3976
4889
  }
3977
4890
 
3978
4891
  // src/Domain/Guild/Stickers.ts
3979
- var import_types32 = require("@fluxerjs/types");
4892
+ var import_types33 = require("@fluxerjs/types");
3980
4893
  async function createSticker(guild, options) {
3981
- const data = await guild.client.rest.post(import_types32.Routes.guildStickers(guild.id), {
4894
+ const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
3982
4895
  body: options,
3983
4896
  auth: true
3984
4897
  });
3985
4898
  return cacheSticker(guild, data);
3986
4899
  }
3987
4900
  async function cloneSticker(guild, sourceStickerId) {
3988
- const data = await guild.client.rest.post(import_types32.Routes.guildStickersClone(guild.id), {
4901
+ const data = await guild.client.rest.post(import_types33.Routes.guildStickersClone(guild.id), {
3989
4902
  body: { source_sticker_id: sourceStickerId },
3990
4903
  auth: true
3991
4904
  });
@@ -3993,17 +4906,17 @@ async function cloneSticker(guild, sourceStickerId) {
3993
4906
  }
3994
4907
  async function createStickersBulk(guild, stickers) {
3995
4908
  const data = await guild.client.rest.post(
3996
- import_types32.Routes.guildStickersBulk(guild.id),
4909
+ import_types33.Routes.guildStickersBulk(guild.id),
3997
4910
  { body: { stickers }, auth: true }
3998
4911
  );
3999
4912
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
4000
4913
  }
4001
4914
  async function fetchStickers(guild) {
4002
- const data = await guild.client.rest.get(import_types32.Routes.guildStickers(guild.id));
4915
+ const data = await guild.client.rest.get(import_types33.Routes.guildStickers(guild.id));
4003
4916
  return data.map((s) => cacheSticker(guild, s));
4004
4917
  }
4005
4918
  async function fetchSticker(guild, stickerId) {
4006
- const data = await guild.client.rest.get(import_types32.Routes.guildSticker(guild.id, stickerId));
4919
+ const data = await guild.client.rest.get(import_types33.Routes.guildSticker(guild.id, stickerId));
4007
4920
  return cacheSticker(guild, data);
4008
4921
  }
4009
4922
 
@@ -4043,8 +4956,26 @@ var Guild = class extends Base {
4043
4956
  systemChannelId;
4044
4957
  /** Rules channel ID (for Community guilds), or null if none. */
4045
4958
  rulesChannelId;
4959
+ /** {@link SystemChannelFlags} bitfield. */
4960
+ systemChannelFlags;
4961
+ /** Splash card alignment. */
4962
+ splashCardAlignment;
4963
+ /** Embed splash hash. */
4964
+ embedSplash;
4046
4965
  /** NSFW level for this guild. */
4047
4966
  nsfwLevel;
4967
+ /** Whether the guild is marked as adult (18+) content. */
4968
+ nsfw;
4969
+ /** Content warning level. */
4970
+ contentWarningLevel;
4971
+ /** Custom guild-wide content warning text. */
4972
+ contentWarningText;
4973
+ /** {@link GuildOperations} bitfield of disabled operations. */
4974
+ disabledOperations;
4975
+ /** ISO-8601 timestamp before which message history is not available. */
4976
+ messageHistoryCutoff;
4977
+ /** Permissions for the current member in this guild (bitfield string). */
4978
+ permissions;
4048
4979
  /** MFA level required for moderation actions. */
4049
4980
  mfaLevel;
4050
4981
  /** Banner width in pixels. */
@@ -4078,13 +5009,13 @@ var Guild = class extends Base {
4078
5009
  this.client = client;
4079
5010
  this.id = data.id;
4080
5011
  this.members = new GuildMemberManager(this);
4081
- this.channels = new import_collection9.LimitedCollection({
5012
+ this.channels = new import_collection12.LimitedCollection({
4082
5013
  maxSize: Number.POSITIVE_INFINITY,
4083
5014
  onEvict: (_id, channel) => client.cache.cascadeChannel(channel, "guild")
4084
5015
  });
4085
- this.roles = new import_collection9.LimitedCollection({ maxSize: client.cache.limits.roles });
4086
- this.emojis = new import_collection9.LimitedCollection({ maxSize: client.cache.limits.emojis });
4087
- this.stickers = new import_collection9.LimitedCollection({ maxSize: client.cache.limits.stickers });
5016
+ this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
5017
+ this.emojis = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.emojis });
5018
+ this.stickers = new import_collection12.LimitedCollection({ maxSize: client.cache.limits.stickers });
4088
5019
  this.name = data.name ?? "";
4089
5020
  this.icon = data.icon ?? null;
4090
5021
  this.banner = data.banner ?? null;
@@ -4099,7 +5030,16 @@ var Guild = class extends Base {
4099
5030
  this.afkTimeout = data.afk_timeout ?? 0;
4100
5031
  this.systemChannelId = data.system_channel_id ?? null;
4101
5032
  this.rulesChannelId = data.rules_channel_id ?? null;
4102
- this.nsfwLevel = data.nsfw_level ?? import_types33.GuildNSFWLevel.Safe;
5033
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5034
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5035
+ this.embedSplash = data.embed_splash ?? null;
5036
+ this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
5037
+ this.nsfw = data.nsfw ?? false;
5038
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5039
+ this.contentWarningText = data.content_warning_text ?? null;
5040
+ this.disabledOperations = data.disabled_operations ?? 0;
5041
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5042
+ this.permissions = data.permissions ?? null;
4103
5043
  this.mfaLevel = data.mfa_level ?? 0;
4104
5044
  this.bannerWidth = data.banner_width ?? null;
4105
5045
  this.bannerHeight = data.banner_height ?? null;
@@ -4134,7 +5074,28 @@ var Guild = class extends Base {
4134
5074
  if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
4135
5075
  if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
4136
5076
  if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
4137
- if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types33.GuildNSFWLevel.Safe;
5077
+ if (data.system_channel_flags !== void 0) {
5078
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5079
+ }
5080
+ if (data.splash_card_alignment !== void 0) {
5081
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5082
+ }
5083
+ if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
5084
+ if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? import_types34.GuildNSFWLevel.Safe;
5085
+ if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
5086
+ if (data.content_warning_level !== void 0) {
5087
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5088
+ }
5089
+ if (data.content_warning_text !== void 0) {
5090
+ this.contentWarningText = data.content_warning_text ?? null;
5091
+ }
5092
+ if (data.disabled_operations !== void 0) {
5093
+ this.disabledOperations = data.disabled_operations ?? 0;
5094
+ }
5095
+ if (data.message_history_cutoff !== void 0) {
5096
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5097
+ }
5098
+ if (data.permissions !== void 0) this.permissions = data.permissions ?? null;
4138
5099
  if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
4139
5100
  if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
4140
5101
  if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
@@ -4155,11 +5116,11 @@ var Guild = class extends Base {
4155
5116
  }
4156
5117
  /** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
4157
5118
  get createdTimestamp() {
4158
- return import_util17.SnowflakeUtil.timestampFromSnowflake(this.id);
5119
+ return import_util22.SnowflakeUtil.timestampFromSnowflake(this.id);
4159
5120
  }
4160
5121
  /** Date when this guild was created, derived from its snowflake ID. */
4161
5122
  get createdAt() {
4162
- return import_util17.SnowflakeUtil.dateFromSnowflake(this.id);
5123
+ return import_util22.SnowflakeUtil.dateFromSnowflake(this.id);
4163
5124
  }
4164
5125
  /** The guild's name. */
4165
5126
  toString() {
@@ -4187,11 +5148,11 @@ var Guild = class extends Base {
4187
5148
  });
4188
5149
  }
4189
5150
  /**
4190
- * Create a channel. `data.type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
5151
+ * Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
4191
5152
  * Requires Manage Channels.
4192
5153
  */
4193
- createChannel(data) {
4194
- return createChannel(this, data);
5154
+ createChannel(options) {
5155
+ return createChannel(this, options);
4195
5156
  }
4196
5157
  /** Fetch all channels in this guild from the API. */
4197
5158
  fetchChannels() {
@@ -4253,7 +5214,7 @@ var Guild = class extends Base {
4253
5214
  resetRoleHoistPositions() {
4254
5215
  return resetRoleHoistPositions(this);
4255
5216
  }
4256
- /** Ban a user from the guild. Requires Ban Members. `ban_duration_seconds`: 0 = permanent. */
5217
+ /** Ban a user from the guild. Requires Ban Members. `banDurationSeconds`: 0 = permanent. */
4257
5218
  ban(userId, options) {
4258
5219
  return ban(this, userId, options);
4259
5220
  }
@@ -4352,7 +5313,7 @@ var Guild = class extends Base {
4352
5313
  };
4353
5314
 
4354
5315
  // src/Domain/Guild/Payload.ts
4355
- var import_util18 = require("@fluxerjs/util");
5316
+ var import_util23 = require("@fluxerjs/util");
4356
5317
  var TOP_LEVEL_COUNT_KEYS = [
4357
5318
  "member_count",
4358
5319
  "online_count",
@@ -4392,10 +5353,10 @@ function mergeTopLevelSnapshotFields(properties, raw) {
4392
5353
  return out;
4393
5354
  }
4394
5355
  function normalizeGuildSnapshotPayload(raw) {
4395
- if (!(0, import_util18.isRecord)(raw)) return null;
5356
+ if (!(0, import_util23.isRecord)(raw)) return null;
4396
5357
  const flatPayload = isHydratableGuildPayload(raw) && (raw.roles === void 0 || Array.isArray(raw.roles)) ? raw : null;
4397
5358
  let nestedPayload = null;
4398
- if (Object.hasOwn(raw, "properties") && (0, import_util18.isRecord)(raw.properties)) {
5359
+ if (Object.hasOwn(raw, "properties") && (0, import_util23.isRecord)(raw.properties)) {
4399
5360
  const properties = raw.properties;
4400
5361
  const rolesValid = raw.roles === void 0 || Array.isArray(raw.roles);
4401
5362
  if (rolesValid && isHydratableGuildPayload(properties) && raw.id === properties.id) {
@@ -4407,7 +5368,7 @@ function normalizeGuildSnapshotPayload(raw) {
4407
5368
  return flatPayload ?? nestedPayload;
4408
5369
  }
4409
5370
  function normalizeGuildUpdatePayload(raw) {
4410
- if (!(0, import_util18.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
5371
+ if (!(0, import_util23.isRecord)(raw) || !isValidGuildPayload(raw)) return null;
4411
5372
  return raw;
4412
5373
  }
4413
5374
 
@@ -4453,23 +5414,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
4453
5414
  }
4454
5415
 
4455
5416
  // src/ClientCore/ClientUser.ts
4456
- var import_types34 = require("@fluxerjs/types");
5417
+ var import_types35 = require("@fluxerjs/types");
4457
5418
  var ClientUser = class extends User {
4458
5419
  /** Broadcast presence (gateway opcode 3) on all shards. */
4459
5420
  setPresence(presence) {
5421
+ this.client.options.presence = presence;
4460
5422
  const wire = toPresenceWire(presence);
4461
- this.client.options.presence = wire;
4462
- this.client._sendToAllShards({ op: import_types34.GatewayOpcodes.PresenceUpdate, d: wire });
5423
+ this.client._sendToAllShards({ op: import_types35.GatewayOpcodes.PresenceUpdate, d: wire });
4463
5424
  }
4464
5425
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
4465
5426
  async fetch() {
4466
- const data = await this.client.rest.get(import_types34.Routes.currentUser(), { auth: true });
5427
+ const data = await this.client.rest.get(import_types35.Routes.currentUser(), { auth: true });
4467
5428
  this._patch(data);
4468
5429
  return this;
4469
5430
  }
4470
5431
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
4471
5432
  async fetchGuilds(options) {
4472
- const path = import_types34.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
5433
+ const path = import_types35.Routes.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
4473
5434
  const data = await this.client.rest.get(path, { auth: true });
4474
5435
  return data.map((g) => ({
4475
5436
  id: g.id,
@@ -4482,10 +5443,18 @@ var ClientUser = class extends User {
4482
5443
  ...g.approximate_presence_count !== void 0 ? { approximatePresenceCount: g.approximate_presence_count } : {}
4483
5444
  }));
4484
5445
  }
4485
- /** DELETE /users/@me/guilds/{guild_id} */
5446
+ /**
5447
+ * Leave a guild (`client.user.leaveGuild`).
5448
+ * DELETE /users/@me/guilds/{guild_id}.
5449
+ *
5450
+ * @param guildId - Guild to leave
5451
+ * @param options - Optional sudo / MFA body for user accounts
5452
+ * @example
5453
+ * await client.user.leaveGuild(guildId);
5454
+ */
4486
5455
  async leaveGuild(guildId, options) {
4487
5456
  const body = options ? toSudoBody(options) : void 0;
4488
- await this.client.rest.delete(import_types34.Routes.leaveGuild(guildId), {
5457
+ await this.client.rest.delete(import_types35.Routes.leaveGuild(guildId), {
4489
5458
  body: body && Object.keys(body).length ? body : void 0,
4490
5459
  auth: true
4491
5460
  });
@@ -4493,7 +5462,7 @@ var ClientUser = class extends User {
4493
5462
  /** Delete every message authored by the caller across a guild (sudo). */
4494
5463
  async bulkDeleteMyMessagesInGuild(guildId, options) {
4495
5464
  const body = options ? toSudoBody(options) : void 0;
4496
- await this.client.rest.post(import_types34.Routes.guildBulkDeleteMine(guildId), {
5465
+ await this.client.rest.post(import_types35.Routes.guildBulkDeleteMine(guildId), {
4497
5466
  body: body && Object.keys(body).length ? body : void 0,
4498
5467
  auth: true
4499
5468
  });
@@ -4501,7 +5470,7 @@ var ClientUser = class extends User {
4501
5470
  };
4502
5471
 
4503
5472
  // src/ClientCore/EventHandlers/Helpers.ts
4504
- var import_util19 = require("@fluxerjs/util");
5473
+ var import_util24 = require("@fluxerjs/util");
4505
5474
  function unknownUser(id) {
4506
5475
  return {
4507
5476
  id,
@@ -4660,7 +5629,7 @@ var guildResourceHandlers = {
4660
5629
  role = new Role(client, data.role, data.guild_id);
4661
5630
  guild?.roles.set(role.id, role);
4662
5631
  }
4663
- client.emit(Events.GuildRoleUpdate, { role, oldRole });
5632
+ client.emit(Events.GuildRoleUpdate, oldRole, role);
4664
5633
  },
4665
5634
  GUILD_ROLE_UPDATE_BULK(client, d) {
4666
5635
  const data = d;
@@ -4676,11 +5645,7 @@ var guildResourceHandlers = {
4676
5645
  const guild = client.guilds.get(data.guild_id);
4677
5646
  const role = guild?.roles.get(data.role_id) ?? null;
4678
5647
  guild?.roles.delete(data.role_id);
4679
- client.emit(Events.GuildRoleDelete, {
4680
- roleId: data.role_id,
4681
- guildId: data.guild_id,
4682
- role
4683
- });
5648
+ client.emit(Events.GuildRoleDelete, role, data.guild_id, data.role_id);
4684
5649
  },
4685
5650
  GUILD_BAN_ADD(client, d) {
4686
5651
  const data = d;
@@ -4780,55 +5745,50 @@ var guildHandlers = {
4780
5745
  };
4781
5746
 
4782
5747
  // src/ClientCore/EventHandlers/Invites.ts
4783
- var import_types35 = require("@fluxerjs/types");
5748
+ var import_types36 = require("@fluxerjs/types");
4784
5749
  function normalizeInviteCreate(client, payload) {
4785
- const raw = (0, import_util19.asRecord)(payload);
4786
- const code = (0, import_util19.str)(raw?.code);
5750
+ const raw = (0, import_util24.asRecord)(payload);
5751
+ const code = (0, import_util24.str)(raw?.code);
4787
5752
  if (!raw || !code) return null;
4788
- const typeNum = (0, import_util19.num)(raw.type);
4789
- const type = typeNum === import_types35.InviteType.GroupDM || typeNum === import_types35.InviteType.EmojiPack || typeNum === import_types35.InviteType.StickerPack ? typeNum : import_types35.InviteType.Guild;
5753
+ const typeNum = (0, import_util24.num)(raw.type);
5754
+ const type = typeNum === import_types36.InviteType.GroupDM ? import_types36.InviteType.GroupDM : import_types36.InviteType.Guild;
4790
5755
  const shared = {
4791
5756
  code,
4792
5757
  inviter: raw.inviter ?? null,
4793
- member_count: (0, import_util19.num)(raw.member_count),
5758
+ member_count: (0, import_util24.num)(raw.member_count),
4794
5759
  expires_at: raw.expires_at ?? void 0,
4795
5760
  temporary: typeof raw.temporary === "boolean" ? raw.temporary : void 0,
4796
- created_at: (0, import_util19.str)(raw.created_at),
4797
- uses: (0, import_util19.num)(raw.uses),
4798
- max_uses: (0, import_util19.num)(raw.max_uses),
4799
- max_age: (0, import_util19.num)(raw.max_age)
5761
+ created_at: (0, import_util24.str)(raw.created_at),
5762
+ uses: (0, import_util24.num)(raw.uses),
5763
+ max_uses: (0, import_util24.num)(raw.max_uses),
5764
+ max_age: (0, import_util24.num)(raw.max_age)
4800
5765
  };
4801
- if (type === import_types35.InviteType.EmojiPack || type === import_types35.InviteType.StickerPack) {
4802
- const pack = (0, import_util19.asRecord)(raw.pack);
4803
- if (!pack || !(0, import_util19.str)(pack.id) || !(0, import_util19.str)(pack.name)) return null;
4804
- return { ...shared, type, pack };
4805
- }
4806
- const guildObj = (0, import_util19.asRecord)(raw.guild);
4807
- const channelObj = (0, import_util19.asRecord)(raw.channel);
4808
- const guildId = (0, import_util19.str)(guildObj?.id) ?? (0, import_util19.str)(raw.guild_id) ?? "0";
4809
- const channelId = (0, import_util19.str)(channelObj?.id) ?? (0, import_util19.str)(raw.channel_id) ?? "0";
5766
+ const guildObj = (0, import_util24.asRecord)(raw.guild);
5767
+ const channelObj = (0, import_util24.asRecord)(raw.channel);
5768
+ const guildId = (0, import_util24.str)(guildObj?.id) ?? (0, import_util24.str)(raw.guild_id) ?? "0";
5769
+ const channelId = (0, import_util24.str)(channelObj?.id) ?? (0, import_util24.str)(raw.channel_id) ?? "0";
4810
5770
  const cachedGuild = guildId !== "0" ? client.guilds.get(guildId) : null;
4811
5771
  const cachedChannel = channelId !== "0" ? client.channels.get(channelId) : null;
4812
5772
  const channel = {
4813
5773
  id: channelId,
4814
- type: (0, import_util19.num)(channelObj?.type) ?? cachedChannel?.type ?? import_types35.ChannelType.GuildText,
4815
- name: (0, import_util19.str)(channelObj?.name) ?? cachedChannel?.name ?? null,
5774
+ type: (0, import_util24.num)(channelObj?.type) ?? cachedChannel?.type ?? import_types36.ChannelType.GuildText,
5775
+ name: (0, import_util24.str)(channelObj?.name) ?? cachedChannel?.name ?? null,
4816
5776
  icon: channelObj?.icon ?? null
4817
5777
  };
4818
- if (type === import_types35.InviteType.GroupDM) return { ...shared, type, channel };
5778
+ if (type === import_types36.InviteType.GroupDM) return { ...shared, type, channel };
4819
5779
  return {
4820
5780
  ...shared,
4821
- type: import_types35.InviteType.Guild,
5781
+ type: import_types36.InviteType.Guild,
4822
5782
  guild: {
4823
5783
  id: guildId,
4824
- name: (0, import_util19.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
5784
+ name: (0, import_util24.str)(guildObj?.name) ?? cachedGuild?.name ?? "Unknown Guild",
4825
5785
  icon: guildObj?.icon ?? null,
4826
5786
  banner: guildObj?.banner ?? null,
4827
5787
  splash: guildObj?.splash ?? null,
4828
5788
  features: Array.isArray(guildObj?.features) ? guildObj.features : void 0
4829
5789
  },
4830
5790
  channel,
4831
- presence_count: (0, import_util19.num)(raw.presence_count)
5791
+ presence_count: (0, import_util24.num)(raw.presence_count)
4832
5792
  };
4833
5793
  }
4834
5794
  var inviteHandlers = {
@@ -4854,6 +5814,30 @@ var inviteHandlers = {
4854
5814
  }
4855
5815
  };
4856
5816
 
5817
+ // src/Domain/Guild/PartialGuildMember.ts
5818
+ var PartialGuildMember = class {
5819
+ partial = true;
5820
+ client;
5821
+ id;
5822
+ user;
5823
+ guildId;
5824
+ guild;
5825
+ constructor(data) {
5826
+ this.client = data.client;
5827
+ this.id = data.id;
5828
+ this.user = data.user;
5829
+ this.guild = data.guild;
5830
+ this.guildId = data.guild.id;
5831
+ }
5832
+ /**
5833
+ * Fetch the full {@link GuildMember} from the API (cache-aware via `guild.members.fetch`).
5834
+ * @throws FluxerError with MEMBER_NOT_FOUND if the user is not in the guild
5835
+ */
5836
+ async fetch() {
5837
+ return this.guild.members.fetch(this.id);
5838
+ }
5839
+ };
5840
+
4857
5841
  // src/ClientCore/EventHandlers/Members.ts
4858
5842
  var memberHandlers = {
4859
5843
  GUILD_MEMBER_ADD(client, d) {
@@ -4880,28 +5864,15 @@ var memberHandlers = {
4880
5864
  const data = d;
4881
5865
  const guild = client.guilds.get(data.guild_id);
4882
5866
  if (!guild || !data.user?.id) return;
4883
- let member = guild.members.get(data.user.id);
4884
- if (member) {
4885
- guild.members.delete(data.user.id);
4886
- } else {
4887
- member = new GuildMember(
4888
- client,
4889
- {
4890
- user: {
4891
- ...unknownUser(data.user.id),
4892
- ...data.user,
4893
- username: data.user.username ?? "Unknown",
4894
- discriminator: data.user.discriminator ?? "0"
4895
- },
4896
- roles: [],
4897
- joined_at: (/* @__PURE__ */ new Date(0)).toISOString(),
4898
- nick: null,
4899
- mute: false,
4900
- deaf: false
4901
- },
4902
- guild
4903
- );
4904
- }
5867
+ const cached = guild.members.get(data.user.id);
5868
+ if (cached) guild.members.delete(data.user.id);
5869
+ const user = client.getOrCreateUser(data.user);
5870
+ const member = cached ?? new PartialGuildMember({
5871
+ client,
5872
+ id: data.user.id,
5873
+ user,
5874
+ guild
5875
+ });
4905
5876
  guild.adjustMemberCount(-1);
4906
5877
  client.emit(Events.GuildMemberRemove, member);
4907
5878
  },
@@ -4920,7 +5891,7 @@ var memberHandlers = {
4920
5891
  members,
4921
5892
  chunkIndex: data.chunk_index,
4922
5893
  chunkCount: data.chunk_count,
4923
- notFound: [],
5894
+ notFound: data.not_found ?? [],
4924
5895
  nonce: data.nonce ?? null
4925
5896
  };
4926
5897
  client.emit(Events.GuildMembersChunk, payload);
@@ -4928,7 +5899,35 @@ var memberHandlers = {
4928
5899
  };
4929
5900
 
4930
5901
  // src/ClientCore/EventHandlers/Messages.ts
4931
- function toReactionEmoji2(emoji) {
5902
+ var import_util25 = require("@fluxerjs/util");
5903
+ function cachedTextChannel(client, channelId) {
5904
+ const channel = client.channels.get(channelId);
5905
+ return channel?.isTextBased() ? channel : null;
5906
+ }
5907
+ function cachedMessage(client, channelId, messageId) {
5908
+ const data = client._getMessageCache(channelId)?.get(messageId);
5909
+ return data ? new Message(client, data) : null;
5910
+ }
5911
+ function isHydratableMessage(data) {
5912
+ return Boolean(data.author?.id && data.timestamp);
5913
+ }
5914
+ function toPartialMessage(client, args) {
5915
+ const cached = args.cached;
5916
+ const authorId = args.authorId ?? cached?.author?.id ?? null;
5917
+ const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
5918
+ const createdAt = cached?.timestamp ? new Date(cached.timestamp) : import_util25.SnowflakeUtil.isValid(args.id) ? import_util25.SnowflakeUtil.dateFromSnowflake(args.id) : null;
5919
+ return new PartialMessage(client, {
5920
+ id: args.id,
5921
+ channelId: args.channelId,
5922
+ guildId: args.guildId ?? cached?.guild_id ?? null,
5923
+ channel: cachedTextChannel(client, args.channelId),
5924
+ content: args.content ?? cached?.content ?? null,
5925
+ authorId,
5926
+ author,
5927
+ createdAt
5928
+ });
5929
+ }
5930
+ function toReactionEmoji(emoji) {
4932
5931
  return {
4933
5932
  name: emoji.name,
4934
5933
  ...emoji.id !== void 0 ? { id: emoji.id } : {},
@@ -4945,9 +5944,12 @@ function emitReaction(event) {
4945
5944
  const payload = {
4946
5945
  reaction,
4947
5946
  user,
5947
+ message: cachedMessage(client, data.channel_id, data.message_id),
5948
+ channel: cachedTextChannel(client, data.channel_id),
5949
+ member,
4948
5950
  messageId: data.message_id,
4949
5951
  channelId: data.channel_id,
4950
- emoji: toReactionEmoji2(data.emoji),
5952
+ emoji: toReactionEmoji(data.emoji),
4951
5953
  userId: data.user_id
4952
5954
  };
4953
5955
  client.emit(event, payload);
@@ -4967,37 +5969,60 @@ var messageHandlers = {
4967
5969
  },
4968
5970
  MESSAGE_UPDATE(client, d) {
4969
5971
  const partial = d;
4970
- const cache = client._getMessageCache(partial.channel_id);
4971
- let oldMessage = null;
4972
- let mergedData = partial;
4973
- if (cache) {
4974
- const oldData = cache.get(partial.id);
4975
- if (oldData) {
4976
- oldMessage = new Message(client, oldData);
4977
- mergedData = { ...oldData, ...partial };
4978
- }
5972
+ const oldData = client._getMessageCache(partial.channel_id)?.get(partial.id);
5973
+ const oldMessage = oldData ? new Message(client, oldData) : null;
5974
+ const mergedData = oldData ? { ...oldData, ...partial } : partial;
5975
+ if (isHydratableMessage(mergedData)) {
5976
+ client._addMessageToCache(partial.channel_id, mergedData);
5977
+ client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
5978
+ return;
4979
5979
  }
4980
- client._addMessageToCache(partial.channel_id, mergedData);
4981
- client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
5980
+ client.emit(
5981
+ Events.MessageUpdate,
5982
+ oldMessage,
5983
+ toPartialMessage(client, {
5984
+ id: partial.id,
5985
+ channelId: partial.channel_id,
5986
+ guildId: partial.guild_id ?? oldData?.guild_id ?? null,
5987
+ content: partial.content ?? oldData?.content ?? null,
5988
+ authorId: partial.author?.id ?? oldData?.author?.id ?? null,
5989
+ cached: oldData
5990
+ })
5991
+ );
4982
5992
  },
4983
5993
  MESSAGE_DELETE(client, d) {
4984
5994
  const data = d;
4985
- client._removeMessageFromCache(data.channel_id, data.id);
4986
- client.emit(Events.MessageDelete, {
5995
+ const cached = client._getMessageCache(data.channel_id)?.get(data.id);
5996
+ const payload = toPartialMessage(client, {
4987
5997
  id: data.id,
4988
5998
  channelId: data.channel_id,
4989
- channel: client.channels.get(data.channel_id) ?? null,
4990
- content: data.content ?? null,
4991
- authorId: data.author_id ?? null
5999
+ guildId: data.guild_id ?? cached?.guild_id ?? null,
6000
+ content: data.content ?? cached?.content ?? null,
6001
+ authorId: data.author_id ?? cached?.author?.id ?? null,
6002
+ cached
4992
6003
  });
6004
+ client._removeMessageFromCache(data.channel_id, data.id);
6005
+ client.emit(Events.MessageDelete, payload);
4993
6006
  },
4994
6007
  MESSAGE_DELETE_BULK(client, d) {
4995
6008
  const data = d;
4996
- for (const id of data.ids ?? []) client._removeMessageFromCache(data.channel_id, id);
6009
+ const ids = data.ids ?? [];
6010
+ const cache = client._getMessageCache(data.channel_id);
6011
+ const messages = ids.map(
6012
+ (id) => toPartialMessage(client, {
6013
+ id,
6014
+ channelId: data.channel_id,
6015
+ guildId: data.guild_id ?? cache?.get(id)?.guild_id ?? null,
6016
+ cached: cache?.get(id)
6017
+ })
6018
+ );
6019
+ for (const id of ids) client._removeMessageFromCache(data.channel_id, id);
4997
6020
  client.emit(Events.MessageDeleteBulk, {
4998
- ids: data.ids ?? [],
6021
+ ids,
4999
6022
  channelId: data.channel_id,
5000
- guildId: data.guild_id ?? null
6023
+ guildId: data.guild_id ?? null,
6024
+ channel: cachedTextChannel(client, data.channel_id),
6025
+ messages
5001
6026
  });
5002
6027
  },
5003
6028
  MESSAGE_REACTION_ADD: emitReaction(Events.MessageReactionAdd),
@@ -5007,7 +6032,9 @@ var messageHandlers = {
5007
6032
  const payload = {
5008
6033
  messageId: data.message_id,
5009
6034
  channelId: data.channel_id,
5010
- guildId: data.guild_id ?? null
6035
+ guildId: data.guild_id ?? null,
6036
+ message: cachedMessage(client, data.channel_id, data.message_id),
6037
+ channel: cachedTextChannel(client, data.channel_id)
5011
6038
  };
5012
6039
  client.emit(Events.MessageReactionRemoveAll, payload);
5013
6040
  },
@@ -5017,7 +6044,9 @@ var messageHandlers = {
5017
6044
  messageId: data.message_id,
5018
6045
  channelId: data.channel_id,
5019
6046
  guildId: data.guild_id ?? null,
5020
- emoji: toReactionEmoji2(data.emoji)
6047
+ emoji: toReactionEmoji(data.emoji),
6048
+ message: cachedMessage(client, data.channel_id, data.message_id),
6049
+ channel: cachedTextChannel(client, data.channel_id)
5021
6050
  };
5022
6051
  client.emit(Events.MessageReactionRemoveEmoji, payload);
5023
6052
  },
@@ -5036,7 +6065,7 @@ var messageHandlers = {
5036
6065
  }
5037
6066
  reactions.push({
5038
6067
  userId: entry.user_id,
5039
- emoji: toReactionEmoji2(entry.emoji),
6068
+ emoji: toReactionEmoji(entry.emoji),
5040
6069
  member
5041
6070
  });
5042
6071
  }
@@ -5044,6 +6073,8 @@ var messageHandlers = {
5044
6073
  channelId: data.channel_id,
5045
6074
  messageId: data.message_id,
5046
6075
  guildId: data.guild_id ?? null,
6076
+ message: cachedMessage(client, data.channel_id, data.message_id),
6077
+ channel: cachedTextChannel(client, data.channel_id),
5047
6078
  reactions
5048
6079
  };
5049
6080
  client.emit(Events.MessageReactionAddMany, payload);
@@ -5254,27 +6285,39 @@ function handleReadyPayload(client, data) {
5254
6285
  const waitForGuilds = client.options.waitForGuilds === true;
5255
6286
  const guilds = data.guilds ?? [];
5256
6287
  const pending = hydrateReadyGuilds(client, guilds, waitForGuilds);
6288
+ if (client.readyAt !== null) {
6289
+ if (pending !== null && pending.size > 0) {
6290
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6291
+ for (const id of pending) existing.add(id);
6292
+ client._pendingGuildIds = existing;
6293
+ }
6294
+ return;
6295
+ }
5257
6296
  if (pending !== null && pending.size > 0) {
5258
- client._pendingGuildIds = pending;
6297
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6298
+ for (const id of pending) existing.add(id);
6299
+ client._pendingGuildIds = existing;
5259
6300
  return;
5260
6301
  }
5261
6302
  if (waitForGuilds && guilds.length === 0) {
5262
- client._guildStreamSettleTimeout = setTimeout(() => {
5263
- client._guildStreamSettleTimeout = null;
5264
- finalizeClientReady(client);
5265
- }, GUILD_STREAM_SETTLE_MS);
6303
+ if (client._guildStreamSettleTimeout === null) {
6304
+ client._guildStreamSettleTimeout = setTimeout(() => {
6305
+ client._guildStreamSettleTimeout = null;
6306
+ if (client.readyAt === null) finalizeClientReady(client);
6307
+ }, GUILD_STREAM_SETTLE_MS);
6308
+ }
5266
6309
  return;
5267
6310
  }
5268
6311
  finalizeClientReady(client);
5269
6312
  }
5270
6313
  async function connectClientGateway(client, token, signal) {
5271
6314
  if (signal?.aborted) {
5272
- throw new import_util3.FluxerError("Connection aborted", { code: import_util2.ErrorCodes.GatewayConnectionAborted });
6315
+ throw new import_util4.FluxerError("Connection aborted", { code: import_util3.ErrorCodes.GatewayConnectionAborted });
5273
6316
  }
5274
6317
  const ws = new import_ws.WebSocketManager({
5275
6318
  token,
5276
6319
  intents: client.options.intents ?? 0,
5277
- presence: client.options.presence,
6320
+ presence: client.options.presence ? toPresenceWire(client.options.presence) : void 0,
5278
6321
  flags: client.options.identifyFlags,
5279
6322
  ignoredEvents: client.options.ignoredEvents,
5280
6323
  initialGuildId: client.options.initialGuildId,
@@ -5283,24 +6326,57 @@ async function connectClientGateway(client, token, signal) {
5283
6326
  },
5284
6327
  version: client.options.rest?.version ?? "1",
5285
6328
  debug: client.options.gatewayDebug !== false,
5286
- WebSocket: client.options.WebSocket
6329
+ WebSocket: client.options.WebSocket,
6330
+ shardCount: client.options.shardCount ?? client.options.totalShards,
6331
+ shardIds: client.options.shardIds ?? client.options.shardList,
6332
+ guildsPerShard: client.options.guildsPerShard,
6333
+ buildStrategy: client.options.buildStrategy,
6334
+ sessionStore: client.options.sessionStore,
6335
+ identifyThrottler: client.options.identifyThrottler
5287
6336
  });
5288
6337
  ws.on("dispatch", ({ payload }) => {
5289
6338
  handleGatewayDispatch(client, payload, client._deferredGatewayDispatches).catch(
5290
6339
  (err) => emitClientError(client, err)
5291
6340
  );
5292
6341
  });
5293
- ws.on("ready", ({ data }) => {
5294
- handleReadyPayload(client, data);
6342
+ ws.on("ready", ({ shardId, data }) => {
6343
+ client.emit(Events.ShardReady, shardId);
6344
+ try {
6345
+ handleReadyPayload(client, data);
6346
+ } catch (err) {
6347
+ emitClientError(client, err);
6348
+ }
6349
+ });
6350
+ ws.on("resumed", (shardId) => {
6351
+ client.emit(Events.ShardResumed, shardId);
5295
6352
  });
5296
- ws.on("error", ({ error }) => {
5297
- client.logger.error("gateway error", { error: error.message, name: error.name });
6353
+ ws.on("close", ({ shardId, code }) => {
6354
+ client.emit(Events.ShardDisconnect, shardId, code);
6355
+ if (code === import_ws.GatewayCloseCodes.AuthenticationFailed) {
6356
+ emitClientError(
6357
+ client,
6358
+ new import_util4.FluxerError("Gateway authentication failed (4004). Check the bot token.", {
6359
+ code: import_util3.ErrorCodes.InvalidToken
6360
+ })
6361
+ );
6362
+ }
6363
+ });
6364
+ ws.on("error", ({ shardId, error }) => {
6365
+ if (shardId >= 0) client.emit(Events.ShardError, shardId, error);
6366
+ client.logger.error("gateway error", {
6367
+ error: error.message,
6368
+ name: error.name,
6369
+ shardId
6370
+ });
5298
6371
  client.emit(Events.Error, error);
5299
6372
  });
5300
6373
  ws.on("debug", (msg) => {
5301
6374
  client.logger.debug(msg);
5302
6375
  client.emit(Events.Debug, msg);
5303
6376
  });
6377
+ ws.on("shardingRequired", (payload) => {
6378
+ client.emit(Events.ShardingRequired, payload);
6379
+ });
5304
6380
  client._ws = ws;
5305
6381
  const onAbort = () => {
5306
6382
  ws.destroy();
@@ -5308,12 +6384,12 @@ async function connectClientGateway(client, token, signal) {
5308
6384
  signal?.addEventListener("abort", onAbort, { once: true });
5309
6385
  try {
5310
6386
  if (signal?.aborted) {
5311
- throw new import_util3.FluxerError("Connection aborted", { code: import_util2.ErrorCodes.GatewayConnectionAborted });
6387
+ throw new import_util4.FluxerError("Connection aborted", { code: import_util3.ErrorCodes.GatewayConnectionAborted });
5312
6388
  }
5313
6389
  await ws.connect();
5314
6390
  if (signal?.aborted) {
5315
6391
  ws.destroy();
5316
- throw new import_util3.FluxerError("Connection aborted", { code: import_util2.ErrorCodes.GatewayConnectionAborted });
6392
+ throw new import_util4.FluxerError("Connection aborted", { code: import_util3.ErrorCodes.GatewayConnectionAborted });
5317
6393
  }
5318
6394
  return ws;
5319
6395
  } catch (err) {
@@ -5326,9 +6402,9 @@ async function connectClientGateway(client, token, signal) {
5326
6402
  }
5327
6403
 
5328
6404
  // src/ClientCore/GuildManager.ts
5329
- var import_collection10 = require("@fluxerjs/collection");
5330
- var import_types36 = require("@fluxerjs/types");
5331
- var GuildManager = class extends import_collection10.LimitedCollection {
6405
+ var import_collection13 = require("@fluxerjs/collection");
6406
+ var import_types37 = require("@fluxerjs/types");
6407
+ var GuildManager = class extends import_collection13.LimitedCollection {
5332
6408
  constructor(client) {
5333
6409
  super({
5334
6410
  maxSize: client.cache.limits.guilds,
@@ -5337,8 +6413,8 @@ var GuildManager = class extends import_collection10.LimitedCollection {
5337
6413
  this.client = client;
5338
6414
  }
5339
6415
  /**
5340
- * Remove a guild and cascade its channels / message caches.
5341
- * FIFO eviction uses `onEvict` instead (via `super.delete` in LimitedCollection).
6416
+ * Remove a guild from cache and cascade its channels / message caches.
6417
+ * Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
5342
6418
  */
5343
6419
  delete(key) {
5344
6420
  const guild = this.get(key);
@@ -5366,7 +6442,7 @@ var GuildManager = class extends import_collection10.LimitedCollection {
5366
6442
  const cached = this.get(guildId);
5367
6443
  if (cached && !options?.force) return cached;
5368
6444
  try {
5369
- const data = await this.client.rest.get(import_types36.Routes.guild(guildId));
6445
+ const data = await this.client.rest.get(import_types37.Routes.guild(guildId));
5370
6446
  if (cached) {
5371
6447
  cached._patch(data);
5372
6448
  return cached;
@@ -5376,7 +6452,7 @@ var GuildManager = class extends import_collection10.LimitedCollection {
5376
6452
  return guild;
5377
6453
  } catch (err) {
5378
6454
  rethrowMapped(err, {
5379
- notFound: { code: import_util2.ErrorCodes.GuildNotFound, message: `Guild ${guildId} not found` },
6455
+ notFound: { code: import_util3.ErrorCodes.GuildNotFound, message: `Guild ${guildId} not found` },
5380
6456
  fallback: `Failed to fetch guild ${guildId}`
5381
6457
  });
5382
6458
  }
@@ -5451,180 +6527,11 @@ var MessageCache = class {
5451
6527
  }
5452
6528
  };
5453
6529
 
5454
- // src/ClientCore/PackManager.ts
5455
- var import_types37 = require("@fluxerjs/types");
5456
- function toPackSummaryPayload(data) {
5457
- return {
5458
- id: data.id,
5459
- name: data.name,
5460
- description: data.description,
5461
- type: data.type,
5462
- creatorId: data.creator_id,
5463
- createdAt: data.created_at,
5464
- updatedAt: data.updated_at,
5465
- ...data.installed_at !== void 0 ? { installedAt: data.installed_at } : {}
5466
- };
5467
- }
5468
- function toEmojiPayload(data) {
5469
- return {
5470
- id: data.id,
5471
- name: data.name,
5472
- animated: data.animated
5473
- };
5474
- }
5475
- function toStickerPayload(data) {
5476
- return {
5477
- id: data.id,
5478
- name: data.name,
5479
- description: data.description,
5480
- tags: data.tags,
5481
- animated: data.animated,
5482
- nsfw: data.nsfw
5483
- };
5484
- }
5485
- function toInvitePayload(data) {
5486
- return {
5487
- code: data.code,
5488
- ...data.max_uses !== void 0 ? { maxUses: data.max_uses } : {},
5489
- ...data.max_age !== void 0 ? { maxAge: data.max_age } : {},
5490
- ...data.uses !== void 0 ? { uses: data.uses } : {},
5491
- ...data.temporary !== void 0 ? { temporary: data.temporary } : {},
5492
- ...data.created_at !== void 0 ? { createdAt: data.created_at } : {},
5493
- ...data.expires_at !== void 0 ? { expiresAt: data.expires_at } : {}
5494
- };
5495
- }
5496
- function mapDashboardSection(section) {
5497
- return {
5498
- installedLimit: section.installed_limit,
5499
- createdLimit: section.created_limit,
5500
- installed: section.installed.map(toPackSummaryPayload),
5501
- created: section.created.map(toPackSummaryPayload)
5502
- };
5503
- }
5504
- var PackManager = class {
5505
- constructor(client) {
5506
- this.client = client;
5507
- }
5508
- /** Fetch the current user's pack dashboard (camelCase summaries). */
5509
- async fetchDashboard() {
5510
- const data = await this.client.rest.get(import_types37.Routes.packs());
5511
- return {
5512
- emoji: mapDashboardSection(data.emoji),
5513
- sticker: mapDashboardSection(data.sticker)
5514
- };
5515
- }
5516
- /** Create a pack. */
5517
- async create(packType, body) {
5518
- const data = await this.client.rest.post(import_types37.Routes.packsByType(packType), {
5519
- body
5520
- });
5521
- return toPackSummaryPayload(data);
5522
- }
5523
- /** Edit a pack. */
5524
- async edit(packId, body) {
5525
- const data = await this.client.rest.patch(import_types37.Routes.pack(packId), { body });
5526
- return toPackSummaryPayload(data);
5527
- }
5528
- /** Delete a pack. */
5529
- async delete(packId) {
5530
- await this.client.rest.delete(import_types37.Routes.pack(packId));
5531
- }
5532
- /** Install a pack for the current user. */
5533
- async install(packId) {
5534
- await this.client.rest.post(import_types37.Routes.packInstall(packId));
5535
- }
5536
- /** Uninstall a pack for the current user. */
5537
- async uninstall(packId) {
5538
- await this.client.rest.delete(import_types37.Routes.packInstall(packId));
5539
- }
5540
- /** List invites for a pack. */
5541
- async listInvites(packId) {
5542
- const data = await this.client.rest.get(import_types37.Routes.packInvites(packId));
5543
- return data.map(toInvitePayload);
5544
- }
5545
- /** Create an invite for a pack. */
5546
- async createInvite(packId, options = {}) {
5547
- const body = toPackInviteBody(options);
5548
- const data = await this.client.rest.post(import_types37.Routes.packInvites(packId), {
5549
- body: Object.keys(body).length ? body : void 0
5550
- });
5551
- return toInvitePayload(data);
5552
- }
5553
- /** List emojis in a pack. */
5554
- async listEmojis(packId) {
5555
- const data = await this.client.rest.get(import_types37.Routes.packEmojis(packId));
5556
- return data.map(toEmojiPayload);
5557
- }
5558
- /** Create an emoji in a pack. */
5559
- async createEmoji(packId, options) {
5560
- const data = await this.client.rest.post(import_types37.Routes.packEmojis(packId), {
5561
- body: toEmojiCreateBody(options)
5562
- });
5563
- return toEmojiPayload(data);
5564
- }
5565
- /** Bulk-create emojis in a pack. */
5566
- async createEmojisBulk(packId, emojis) {
5567
- const data = await this.client.rest.post(
5568
- import_types37.Routes.packEmojisBulk(packId),
5569
- { body: { emojis: emojis.map(toEmojiCreateBody) } }
5570
- );
5571
- return {
5572
- success: data.success.map(toEmojiPayload),
5573
- failed: data.failed
5574
- };
5575
- }
5576
- /** Edit an emoji in a pack. */
5577
- async editEmoji(packId, emojiId, options) {
5578
- const data = await this.client.rest.patch(import_types37.Routes.packEmoji(packId, emojiId), {
5579
- body: toEmojiEditBody(options)
5580
- });
5581
- return toEmojiPayload(data);
5582
- }
5583
- /** Delete an emoji from a pack. */
5584
- async deleteEmoji(packId, emojiId) {
5585
- await this.client.rest.delete(import_types37.Routes.packEmoji(packId, emojiId));
5586
- }
5587
- /** List stickers in a pack. */
5588
- async listStickers(packId) {
5589
- const data = await this.client.rest.get(import_types37.Routes.packStickers(packId));
5590
- return data.map(toStickerPayload);
5591
- }
5592
- /** Create a sticker in a pack. */
5593
- async createSticker(packId, options) {
5594
- const data = await this.client.rest.post(import_types37.Routes.packStickers(packId), {
5595
- body: toStickerCreateBody(options)
5596
- });
5597
- return toStickerPayload(data);
5598
- }
5599
- /** Bulk-create stickers in a pack. */
5600
- async createStickersBulk(packId, stickers) {
5601
- const data = await this.client.rest.post(
5602
- import_types37.Routes.packStickersBulk(packId),
5603
- { body: { stickers: stickers.map(toStickerCreateBody) } }
5604
- );
5605
- return {
5606
- success: data.success.map(toStickerPayload),
5607
- failed: data.failed
5608
- };
5609
- }
5610
- /** Edit a sticker in a pack. */
5611
- async editSticker(packId, stickerId, options) {
5612
- const data = await this.client.rest.patch(import_types37.Routes.packSticker(packId, stickerId), {
5613
- body: toStickerEditBody(options)
5614
- });
5615
- return toStickerPayload(data);
5616
- }
5617
- /** Delete a sticker from a pack. */
5618
- async deleteSticker(packId, stickerId) {
5619
- await this.client.rest.delete(import_types37.Routes.packSticker(packId, stickerId));
5620
- }
5621
- };
5622
-
5623
6530
  // src/ClientCore/UserManager.ts
5624
- var import_collection11 = require("@fluxerjs/collection");
6531
+ var import_collection14 = require("@fluxerjs/collection");
5625
6532
  var import_types38 = require("@fluxerjs/types");
5626
6533
  var soft = (p) => p.catch(() => null);
5627
- var UserManager = class extends import_collection11.LimitedCollection {
6534
+ var UserManager = class extends import_collection14.LimitedCollection {
5628
6535
  constructor(client) {
5629
6536
  super({ maxSize: client.cache.limits.users });
5630
6537
  this.client = client;
@@ -5642,11 +6549,17 @@ var UserManager = class extends import_collection11.LimitedCollection {
5642
6549
  }
5643
6550
  return removed;
5644
6551
  }
5645
- /** Fetch a user by ID and update cache. */
5646
- async fetch(userId) {
6552
+ /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
6553
+ async fetch(userId, options) {
6554
+ const cached = this.get(userId);
6555
+ if (cached && !options?.force) return cached;
5647
6556
  const data = await this.client.rest.get(import_types38.Routes.user(userId));
5648
6557
  return this.client.getOrCreateUser(data);
5649
6558
  }
6559
+ /** Return a cached user, otherwise {@link fetch}. */
6560
+ async resolve(userId) {
6561
+ return this.get(userId) ?? this.fetch(userId);
6562
+ }
5650
6563
  /**
5651
6564
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
5652
6565
  * @example
@@ -5706,14 +6619,22 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5706
6619
  users;
5707
6620
  /** Cache limits, stats, sweeps, and cascade entry points. */
5708
6621
  cache;
5709
- /** Emoji/sticker pack REST wrappers (`/packs/*`). */
5710
- packs = new PackManager(this);
5711
- /** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
6622
+ /** Typed event handlers. Prefer `client.on(Events.*, ...)`. */
5712
6623
  events;
5713
6624
  /** The authenticated bot user. Null until READY is received. */
5714
6625
  user = null;
5715
6626
  /** Timestamp when the client became ready. Null until READY is received. */
5716
6627
  readyAt = null;
6628
+ /**
6629
+ * Milliseconds since {@link readyAt}, or `null` if the client is not ready.
6630
+ * @example
6631
+ * client.on(Events.Ready, () => {
6632
+ * console.log(client.uptime);
6633
+ * });
6634
+ */
6635
+ get uptime() {
6636
+ return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
6637
+ }
5717
6638
  /** @internal WebSocket manager. */
5718
6639
  _ws = null;
5719
6640
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
@@ -5735,7 +6656,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5735
6656
  cache: resolved.cache,
5736
6657
  defaultReplyPing: options.defaultReplyPing ?? true
5737
6658
  };
5738
- this.logger = options.logger ?? (0, import_util20.createLogger)({
6659
+ this.logger = options.logger ?? (0, import_util26.createLogger)({
5739
6660
  level: options.logLevel ?? "warn"
5740
6661
  });
5741
6662
  this.cache = new CacheController(this, resolved.limits);
@@ -5854,33 +6775,23 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5854
6775
  return fetchApplication(this);
5855
6776
  }
5856
6777
  /**
5857
- * Fetch OAuth2 applications owned by this bot.
5858
- * @returns Array of OAuth application objects
6778
+ * Fetch OAuth2 applications (`GET /oauth2/applications/@me`).
6779
+ * A bot token returns the bot application object (normalized to a one-element array).
6780
+ * A user token returns the owner's application list.
5859
6781
  */
5860
6782
  fetchOAuthApplications() {
5861
6783
  return fetchOAuthApplications(this);
5862
6784
  }
5863
- /**
5864
- * Check username#discriminator availability.
5865
- * @param username - Username to check
5866
- * @param discriminator - Discriminator to check
5867
- * @returns Availability result
5868
- */
5869
- checkUsernameTag(username, discriminator) {
5870
- return checkUsernameTag(this, username, discriminator);
5871
- }
5872
6785
  /**
5873
6786
  * Preload recent messages for multiple channels (batch endpoint).
5874
- * @param channelIds - Array of channel IDs to preload
5875
- * @returns Preload response with message counts/timestamps
6787
+ * Prefer this over {@link bulkFetchMessages} for bots (`bulkFetchMessages` is user-account only).
5876
6788
  */
5877
6789
  preloadMessages(channelIds) {
5878
6790
  return preloadMessages(this, channelIds);
5879
6791
  }
5880
6792
  /**
5881
6793
  * Preload recent messages (alternate endpoint).
5882
- * @param channelIds - Array of channel IDs to preload
5883
- * @returns Preload response with message counts/timestamps
6794
+ * Prefer this over {@link bulkFetchMessages} for bots.
5884
6795
  */
5885
6796
  preloadMessagesAlt(channelIds) {
5886
6797
  return preloadMessagesAlt(this, channelIds);
@@ -5888,6 +6799,14 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5888
6799
  bulkFetchMessages(requests, options = {}) {
5889
6800
  return bulkFetchMessages(this, requests, options);
5890
6801
  }
6802
+ /**
6803
+ * Search messages in the current bot scope (`POST /search/messages`, `scope: current`).
6804
+ * Other scopes are denied for bots (`BOT_SEARCH_SCOPE_UNAVAILABLE`).
6805
+ * Returns camelCase results (`hitsPerPage`) or `{ indexing: true }` while channels are indexed.
6806
+ */
6807
+ searchMessages(options) {
6808
+ return searchMessages(this, options);
6809
+ }
5891
6810
  /** @internal */
5892
6811
  _getMessageCache(channelId) {
5893
6812
  return this._messageCache.get(channelId);
@@ -5911,12 +6830,16 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5911
6830
  /**
5912
6831
  * Sweep cached messages (remove entries matching filter).
5913
6832
  * Prefer {@link CacheController.sweepMessages} (`client.cache.sweepMessages`).
6833
+ * The filter receives a hydrated {@link Message} (`createdAt`), not the stored wire payload.
5914
6834
  * @param filter - Predicate to test each message (return true to remove)
5915
6835
  * @param channelId - Optional channel ID to scope sweep
5916
6836
  * @returns Count of messages removed
5917
6837
  */
5918
6838
  sweepMessages(filter, channelId) {
5919
- return this._messageCache.sweep(filter, channelId);
6839
+ return this._messageCache.sweep(
6840
+ filter ? (data, chId) => filter(new Message(this, data), chId) : void 0,
6841
+ channelId
6842
+ );
5920
6843
  }
5921
6844
  /**
5922
6845
  * Sweep cached members across all guilds (remove entries matching filter).
@@ -5949,12 +6872,15 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5949
6872
  }
5950
6873
  /**
5951
6874
  * The underlying {@link WebSocketManager} (throws if not logged in).
6875
+ * Gateway heartbeat ACK latency: `client.ws.ping` (ms, or `-1` before the first ACK).
6876
+ * @example
6877
+ * console.log(client.ws.ping);
5952
6878
  * @throws {@link FluxerError} with {@link ErrorCodes.NotLoggedIn}
5953
6879
  */
5954
6880
  get ws() {
5955
6881
  if (!this._ws) {
5956
- throw new import_util3.FluxerError("Client is not logged in. Call login() first.", {
5957
- code: import_util2.ErrorCodes.NotLoggedIn
6882
+ throw new import_util4.FluxerError("Client is not logged in. Call login() first.", {
6883
+ code: import_util3.ErrorCodes.NotLoggedIn
5958
6884
  });
5959
6885
  }
5960
6886
  return this._ws;
@@ -5976,8 +6902,8 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5976
6902
  if (options.guildIds?.length) data.guild_ids = [...new Set(options.guildIds.filter(Boolean))];
5977
6903
  else if (options.guildId) data.guild_id = options.guildId;
5978
6904
  if (!data.guild_id && !data.guild_ids?.length) {
5979
- throw new import_util3.FluxerError("requestGuildMembers requires guildId or guildIds", {
5980
- code: import_util2.ErrorCodes.InvalidGatewayRequest
6905
+ throw new import_util4.FluxerError("requestGuildMembers requires guildId or guildIds", {
6906
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
5981
6907
  });
5982
6908
  }
5983
6909
  if (options.query !== void 0) data.query = options.query;
@@ -5987,6 +6913,37 @@ var Client = class _Client extends import_node_events3.EventEmitter {
5987
6913
  if (options.nonce !== void 0) data.nonce = options.nonce;
5988
6914
  this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildMembers, d: data });
5989
6915
  }
6916
+ /**
6917
+ * Request guild member/online counts via gateway opcode 15.
6918
+ * Listen for `guildCountsUpdate`. Cached `guild.memberCount` / `guild.onlineCount` update when that event arrives.
6919
+ */
6920
+ requestGuildCounts(options) {
6921
+ const guildIds = [...new Set(options.guildIds.filter(Boolean))];
6922
+ if (!guildIds.length) {
6923
+ throw new import_util4.FluxerError("requestGuildCounts requires at least one guildId", {
6924
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
6925
+ });
6926
+ }
6927
+ const data = { guild_ids: guildIds };
6928
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6929
+ this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestGuildCounts, d: data });
6930
+ }
6931
+ /**
6932
+ * Request per-channel member counts via gateway opcode 16.
6933
+ * Event-only: listen for `channelMemberCountsUpdate`. There is no `channel.memberCount` field.
6934
+ */
6935
+ requestChannelMemberCounts(options) {
6936
+ if (!options.guildId) {
6937
+ throw new import_util4.FluxerError("requestChannelMemberCounts requires guildId", {
6938
+ code: import_util3.ErrorCodes.InvalidGatewayRequest
6939
+ });
6940
+ }
6941
+ const data = { guild_id: options.guildId };
6942
+ if (options.channelId !== void 0) data.channel_id = options.channelId;
6943
+ if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
6944
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6945
+ this._sendToAllShards({ op: import_types39.GatewayOpcodes.RequestChannelMemberCounts, d: data });
6946
+ }
5990
6947
  /**
5991
6948
  * Broadcast a gateway payload to all shards.
5992
6949
  * @param payload - Gateway send payload
@@ -6000,24 +6957,28 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6000
6957
  }
6001
6958
  /**
6002
6959
  * Connect to the gateway with a bot token.
6960
+ * @example
6961
+ * const client = new Client();
6962
+ * client.on(Events.Ready, () => console.log('Ready!'));
6963
+ * await client.login(process.env.FLUXER_BOT_TOKEN);
6003
6964
  * @param token - Bot token from the developer portal
6004
6965
  * @param options - Optional abort signal for cancellation
6005
- * @returns The token that was used (echo)
6966
+ * @returns This client (for chaining)
6006
6967
  * @throws {@link FluxerError} if already logged in or token is invalid
6007
6968
  */
6008
6969
  async login(token, options) {
6009
6970
  if (this._ws) {
6010
- throw new import_util3.FluxerError("Client is already logged in. Call destroy() first.", {
6011
- code: import_util2.ErrorCodes.AlreadyLoggedIn
6971
+ throw new import_util4.FluxerError("Client is already logged in. Call destroy() first.", {
6972
+ code: import_util3.ErrorCodes.AlreadyLoggedIn
6012
6973
  });
6013
6974
  }
6014
6975
  if (typeof token !== "string" || token.trim().length === 0) {
6015
- throw new import_util3.FluxerError("Bot token is required.", { code: import_util2.ErrorCodes.InvalidToken });
6976
+ throw new import_util4.FluxerError("Bot token is required.", { code: import_util3.ErrorCodes.InvalidToken });
6016
6977
  }
6017
6978
  this.rest.setToken(token);
6018
6979
  try {
6019
6980
  this._ws = await connectClientGateway(this, token, options?.signal);
6020
- return token;
6981
+ return this;
6021
6982
  } catch (err) {
6022
6983
  this._ws?.destroy();
6023
6984
  this._ws = null;
@@ -6064,12 +7025,26 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6064
7025
  */
6065
7026
  assertReady() {
6066
7027
  if (!this.isReady()) {
6067
- throw new import_util3.FluxerError(
7028
+ throw new import_util4.FluxerError(
6068
7029
  "Client is not ready yet. Wait for the Ready event before accessing client.user.",
6069
- { code: import_util2.ErrorCodes.ClientNotReady }
7030
+ { code: import_util3.ErrorCodes.ClientNotReady }
6070
7031
  );
6071
7032
  }
6072
7033
  }
7034
+ /**
7035
+ * REST path helpers ({@link Routes}). Pass the path to {@link REST client.rest}.
7036
+ * Prefer high-level helpers (`channel.send()`, `guild.members.fetch()`) when they exist.
7037
+ *
7038
+ * @example
7039
+ * const channel = await client.rest.get(Client.Routes.channel(channelId));
7040
+ *
7041
+ * @example
7042
+ * await client.rest.post(Client.Routes.channelMessages(channelId), {
7043
+ * body: { content: 'hello' },
7044
+ * });
7045
+ *
7046
+ * @see {@link Routes}
7047
+ */
6073
7048
  static get Routes() {
6074
7049
  return import_types39.Routes;
6075
7050
  }