@fluxerjs/core 2.2.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cluster.mjs CHANGED
@@ -54,7 +54,13 @@ var Events = {
54
54
  WebhooksUpdate: "webhooksUpdate",
55
55
  Resumed: "resumed",
56
56
  Error: "error",
57
- Debug: "debug"
57
+ Debug: "debug",
58
+ ShardReady: "shardReady",
59
+ ShardResumed: "shardResumed",
60
+ ShardDisconnect: "shardDisconnect",
61
+ ShardReconnecting: "shardReconnecting",
62
+ ShardError: "shardError",
63
+ ShardingRequired: "shardingRequired"
58
64
  };
59
65
 
60
66
  // src/LibErrors/ErrorCodes.ts
@@ -69,91 +75,14 @@ import { REST } from "@fluxerjs/rest";
69
75
  import { GatewayOpcodes as GatewayOpcodes2, Routes as Routes34 } from "@fluxerjs/types";
70
76
  import { createLogger } from "@fluxerjs/util";
71
77
 
72
- // src/Domain/User.ts
73
- import { Routes as Routes13 } from "@fluxerjs/types";
74
- import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
75
-
76
- // src/Helpers/Constants.ts
77
- import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
78
- var CDN_URL = "https://fluxerusercontent.com";
79
- var STATIC_CDN_URL = "https://fluxerstatic.com";
80
-
81
- // src/Helpers/Cdn.ts
82
- function mediaBase(options) {
83
- return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
84
- }
85
- function staticBase(options) {
86
- return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
87
- }
88
- function getExtension(hash, options) {
89
- const ext = options?.extension ?? "png";
90
- if (hash?.startsWith("a_")) return "gif";
91
- return ext;
92
- }
93
- function appendSize(options) {
94
- return options?.size ? `?size=${options.size}` : "";
95
- }
96
- function cdnAvatarURL(userId, avatarHash, options) {
97
- if (!avatarHash) return null;
98
- const ext = getExtension(avatarHash, options);
99
- const size = appendSize(options);
100
- return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
101
- }
102
- function cdnBannerURL(resourceId, bannerHash, options) {
103
- if (!bannerHash) return null;
104
- const ext = getExtension(bannerHash, options);
105
- const size = appendSize(options);
106
- return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
107
- }
108
- function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
109
- if (!avatarHash) return null;
110
- const ext = getExtension(avatarHash, options);
111
- const size = appendSize(options);
112
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
113
- }
114
- function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
115
- if (!bannerHash) return null;
116
- const ext = getExtension(bannerHash, options);
117
- const size = appendSize(options);
118
- return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
119
- }
120
- function cdnDefaultAvatarURL(userIdOrIndex, options) {
121
- const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
122
- return `${staticBase(options)}/avatars/${index}.png`;
123
- }
124
- function cdnGuildAssetURL(kind, id, hash, options) {
125
- if (!hash) return null;
126
- const size = options?.size ? `?size=${options.size}` : "";
127
- return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
128
- }
129
- function cdnEmojiURL(emojiId, animated, options) {
130
- const ext = animated ? "gif" : "png";
131
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
132
- }
133
- function cdnStickerURL(stickerId, animated, options) {
134
- const ext = animated ? "gif" : "png";
135
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
136
- }
137
-
138
- // src/Domain/Base.ts
139
- var Base = class {
140
- };
141
-
142
- // src/Domain/Channel/Base.ts
143
- import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
144
- import { SnowflakeUtil } from "@fluxerjs/util";
145
-
146
- // src/ClientCore/MessageManager.ts
147
- import { Collection as Collection3 } from "@fluxerjs/collection";
148
- import { Routes as Routes5 } from "@fluxerjs/types";
149
-
150
78
  // src/Domain/Message/Message.ts
151
79
  import { EmbedBuilder as EmbedBuilder2 } from "@fluxerjs/builders";
152
- import { Collection as Collection2 } from "@fluxerjs/collection";
80
+ import { Collection as Collection3 } from "@fluxerjs/collection";
153
81
  import {
154
82
  MessageType,
155
83
  Routes as Routes4
156
84
  } from "@fluxerjs/types";
85
+ import { MessageFlagsBitField } from "@fluxerjs/util";
157
86
 
158
87
  // src/ClientCore/SdkOptions/Attachments.ts
159
88
  function toMessageAttachmentEditWire(attachments) {
@@ -220,23 +149,68 @@ function toAttachmentUploadPlanResponse(data) {
220
149
  }
221
150
 
222
151
  // src/ClientCore/SdkOptions/Channels.ts
152
+ import { resolvePermissionsToBitfield } from "@fluxerjs/util";
153
+ function toOverwriteWire(overwrite) {
154
+ return {
155
+ id: overwrite.id,
156
+ type: overwrite.type,
157
+ allow: overwrite.allow !== void 0 ? resolvePermissionsToBitfield(overwrite.allow) : "0",
158
+ deny: overwrite.deny !== void 0 ? resolvePermissionsToBitfield(overwrite.deny) : "0"
159
+ };
160
+ }
223
161
  function toChannelEditBody(options) {
224
162
  const body = {};
225
163
  if (options.name !== void 0) body.name = options.name;
226
164
  if (options.topic !== void 0) body.topic = options.topic;
165
+ if (options.url !== void 0) body.url = options.url;
227
166
  if (options.parentId !== void 0) body.parent_id = options.parentId;
228
167
  if (options.bitrate !== void 0) body.bitrate = options.bitrate;
229
168
  if (options.userLimit !== void 0) body.user_limit = options.userLimit;
169
+ if (options.voiceConnectionLimit !== void 0) {
170
+ body.voice_connection_limit = options.voiceConnectionLimit;
171
+ }
230
172
  if (options.nsfw !== void 0) body.nsfw = options.nsfw;
173
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
174
+ if (options.contentWarningLevel !== void 0) {
175
+ body.content_warning_level = options.contentWarningLevel;
176
+ }
177
+ if (options.contentWarningText !== void 0) {
178
+ body.content_warning_text = options.contentWarningText;
179
+ }
231
180
  if (options.rateLimitPerUser !== void 0) {
232
181
  body.rate_limit_per_user = options.rateLimitPerUser;
233
182
  }
234
183
  if (options.rtcRegion !== void 0) body.rtc_region = options.rtcRegion;
184
+ if (options.icon !== void 0) body.icon = options.icon;
235
185
  if (options.permissionOverwrites !== void 0) {
236
- body.permission_overwrites = options.permissionOverwrites;
186
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
237
187
  }
238
188
  return body;
239
189
  }
190
+ function toChannelCreateBody(options) {
191
+ const body = { name: options.name, type: options.type };
192
+ if (options.topic !== void 0) body.topic = options.topic;
193
+ if (options.url !== void 0) body.url = options.url;
194
+ if (options.parentId !== void 0) body.parent_id = options.parentId;
195
+ if (options.bitrate !== void 0) body.bitrate = options.bitrate;
196
+ if (options.userLimit !== void 0) body.user_limit = options.userLimit;
197
+ if (options.voiceConnectionLimit !== void 0) {
198
+ body.voice_connection_limit = options.voiceConnectionLimit;
199
+ }
200
+ if (options.permissionOverwrites !== void 0) {
201
+ body.permission_overwrites = options.permissionOverwrites.map(toOverwriteWire);
202
+ }
203
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
204
+ if (options.nsfwOverride !== void 0) body.nsfw_override = options.nsfwOverride;
205
+ if (options.contentWarningLevel !== void 0) {
206
+ body.content_warning_level = options.contentWarningLevel;
207
+ }
208
+ if (options.contentWarningText !== void 0) {
209
+ body.content_warning_text = options.contentWarningText;
210
+ }
211
+ if (options.rateLimitPerUser !== void 0) body.rate_limit_per_user = options.rateLimitPerUser;
212
+ return body;
213
+ }
240
214
  function toChannelInviteBody(options) {
241
215
  const body = {};
242
216
  if (options.maxUses !== void 0) body.max_uses = options.maxUses;
@@ -245,6 +219,13 @@ function toChannelInviteBody(options) {
245
219
  if (options.temporary !== void 0) body.temporary = options.temporary;
246
220
  return body;
247
221
  }
222
+ function toGroupDmEditBody(options) {
223
+ const body = { type: 3 };
224
+ if (options.name !== void 0) body.name = options.name;
225
+ if (options.icon !== void 0) body.icon = options.icon;
226
+ if (options.nicks !== void 0) body.nicks = options.nicks;
227
+ return body;
228
+ }
248
229
 
249
230
  // src/ClientCore/SdkOptions/Discovery.ts
250
231
  function toDiscoveryBody(options) {
@@ -280,32 +261,8 @@ function toDiscoveryStatusPayload(data) {
280
261
  };
281
262
  }
282
263
 
283
- // src/ClientCore/SdkOptions/Expressions.ts
284
- function toEmojiCreateBody(options) {
285
- return { name: options.name, image: options.image };
286
- }
287
- function toEmojiEditBody(options) {
288
- return { name: options.name };
289
- }
290
- function toStickerCreateBody(options) {
291
- const body = {
292
- name: options.name,
293
- image: options.file
294
- };
295
- if (options.description !== void 0) body.description = options.description;
296
- if (options.tags !== void 0) body.tags = options.tags;
297
- return body;
298
- }
299
- function toStickerEditBody(options) {
300
- const body = {};
301
- if (options.name !== void 0) body.name = options.name;
302
- if (options.description !== void 0) body.description = options.description;
303
- if (options.tags !== void 0) body.tags = options.tags;
304
- return body;
305
- }
306
-
307
264
  // src/ClientCore/SdkOptions/Guild.ts
308
- import { resolvePermissionsToBitfield } from "@fluxerjs/util";
265
+ import { resolvePermissionsToBitfield as resolvePermissionsToBitfield2 } from "@fluxerjs/util";
309
266
  function toGuildEditBody(options) {
310
267
  const body = {};
311
268
  if (options.name !== void 0) body.name = options.name;
@@ -333,6 +290,16 @@ function toGuildEditBody(options) {
333
290
  body.splash_card_alignment = options.splashCardAlignment;
334
291
  }
335
292
  if (options.nsfwLevel !== void 0) body.nsfw_level = options.nsfwLevel;
293
+ if (options.nsfw !== void 0) body.nsfw = options.nsfw;
294
+ if (options.contentWarningLevel !== void 0) {
295
+ body.content_warning_level = options.contentWarningLevel;
296
+ }
297
+ if (options.contentWarningText !== void 0) {
298
+ body.content_warning_text = options.contentWarningText;
299
+ }
300
+ if (options.messageHistoryCutoff !== void 0) {
301
+ body.message_history_cutoff = options.messageHistoryCutoff;
302
+ }
336
303
  if (options.features !== void 0) body.features = options.features;
337
304
  return body;
338
305
  }
@@ -342,6 +309,9 @@ function toGuildBanBody(options) {
342
309
  if (options.deleteMessageDays !== void 0) {
343
310
  body.delete_message_days = options.deleteMessageDays;
344
311
  }
312
+ if (options.deleteMessageSeconds !== void 0) {
313
+ body.delete_message_seconds = options.deleteMessageSeconds;
314
+ }
345
315
  if (options.banDurationSeconds !== void 0) {
346
316
  body.ban_duration_seconds = options.banDurationSeconds;
347
317
  }
@@ -356,18 +326,26 @@ function toChannelPositionBody(updates) {
356
326
  return row;
357
327
  });
358
328
  }
359
- function toRoleRequestBody(options) {
329
+ function toRolePermissionsBody(options) {
360
330
  const body = {};
331
+ if (options.permissions !== void 0) {
332
+ body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield2(options.permissions);
333
+ }
334
+ return body;
335
+ }
336
+ function toRoleCreateBody(options) {
337
+ const body = { ...toRolePermissionsBody(options) };
338
+ if (options.name !== void 0) body.name = options.name;
339
+ if (options.color !== void 0) body.color = options.color;
340
+ return body;
341
+ }
342
+ function toRoleEditBody(options) {
343
+ const body = { ...toRolePermissionsBody(options) };
361
344
  if (options.name !== void 0) body.name = options.name;
362
345
  if (options.color !== void 0) body.color = options.color;
363
346
  if (options.hoist !== void 0) body.hoist = options.hoist;
364
347
  if (options.mentionable !== void 0) body.mentionable = options.mentionable;
365
- if (options.unicodeEmoji !== void 0) body.unicode_emoji = options.unicodeEmoji;
366
- if (options.position !== void 0) body.position = options.position;
367
348
  if (options.hoistPosition !== void 0) body.hoist_position = options.hoistPosition;
368
- if (options.permissions !== void 0) {
369
- body.permissions = typeof options.permissions === "string" ? options.permissions : resolvePermissionsToBitfield(options.permissions);
370
- }
371
349
  return body;
372
350
  }
373
351
 
@@ -385,6 +363,8 @@ function toMemberSearchBody(options) {
385
363
  if (options.userCreatedAtLte !== void 0) body.user_created_at_lte = options.userCreatedAtLte;
386
364
  if (options.sortBy !== void 0) body.sort_by = options.sortBy;
387
365
  if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
366
+ if (options.joinSourceType !== void 0) body.join_source_type = options.joinSourceType;
367
+ if (options.sourceInviteCode !== void 0) body.source_invite_code = options.sourceInviteCode;
388
368
  return body;
389
369
  }
390
370
  function toMemberEditBody(options) {
@@ -397,6 +377,7 @@ function toMemberEditBody(options) {
397
377
  if (options.pronouns !== void 0) body.pronouns = options.pronouns;
398
378
  if (options.accentColor !== void 0) body.accent_color = options.accentColor;
399
379
  if (options.profileFlags !== void 0) body.profile_flags = options.profileFlags;
380
+ if (options.mentionFlags !== void 0) body.mention_flags = options.mentionFlags;
400
381
  if (options.mute !== void 0) body.mute = options.mute;
401
382
  if (options.deaf !== void 0) body.deaf = options.deaf;
402
383
  if (options.communicationDisabledUntil !== void 0) {
@@ -418,15 +399,54 @@ function toBulkFetchWire(requests) {
418
399
  ...r.around !== void 0 ? { around: r.around } : {}
419
400
  }));
420
401
  }
421
-
422
- // src/ClientCore/SdkOptions/Packs.ts
423
- function toPackInviteBody(options) {
424
- const body = {};
425
- if (options.maxUses !== void 0) body.max_uses = options.maxUses;
426
- if (options.maxAge !== void 0) body.max_age = options.maxAge;
427
- if (options.unique !== void 0) body.unique = options.unique;
402
+ function toMessageSearchBody(options = {}) {
403
+ const body = { scope: "current" };
404
+ if (options.content !== void 0) body.content = options.content;
405
+ if (options.contents !== void 0) body.contents = options.contents;
406
+ if (options.exactPhrases !== void 0) body.exact_phrases = options.exactPhrases;
407
+ if (options.channelIds !== void 0) {
408
+ body.channel_id = options.channelIds;
409
+ body.channel_ids = options.channelIds;
410
+ }
411
+ if (options.excludeChannelIds !== void 0) body.exclude_channel_id = options.excludeChannelIds;
412
+ if (options.contextGuildId !== void 0) body.context_guild_id = options.contextGuildId;
413
+ if (options.contextChannelId !== void 0) body.context_channel_id = options.contextChannelId;
414
+ if (options.hitsPerPage !== void 0) body.hits_per_page = options.hitsPerPage;
415
+ if (options.page !== void 0) body.page = options.page;
416
+ if (options.cursor !== void 0) body.cursor = options.cursor;
417
+ if (options.minId !== void 0) body.min_id = options.minId;
418
+ if (options.maxId !== void 0) body.max_id = options.maxId;
419
+ if (options.authorIds !== void 0) body.author_id = options.authorIds;
420
+ if (options.excludeAuthorIds !== void 0) body.exclude_author_id = options.excludeAuthorIds;
421
+ if (options.authorType !== void 0) body.author_type = options.authorType;
422
+ if (options.excludeAuthorType !== void 0) body.exclude_author_type = options.excludeAuthorType;
423
+ if (options.mentions !== void 0) body.mentions = options.mentions;
424
+ if (options.excludeMentions !== void 0) body.exclude_mentions = options.excludeMentions;
425
+ if (options.mentionEveryone !== void 0) body.mention_everyone = options.mentionEveryone;
426
+ if (options.pinned !== void 0) body.pinned = options.pinned;
427
+ if (options.includeNsfw !== void 0) body.include_nsfw = options.includeNsfw;
428
+ if (options.has !== void 0) body.has = options.has;
429
+ if (options.excludeHas !== void 0) body.exclude_has = options.excludeHas;
430
+ if (options.sortBy !== void 0) body.sort_by = options.sortBy;
431
+ if (options.sortOrder !== void 0) body.sort_order = options.sortOrder;
428
432
  return body;
429
433
  }
434
+ function isMessageSearchIndexing(data) {
435
+ return "indexing" in data && data.indexing === true;
436
+ }
437
+ function toMessageSearchResponse(data) {
438
+ if (isMessageSearchIndexing(data)) {
439
+ return { indexing: true };
440
+ }
441
+ return {
442
+ messages: data.messages,
443
+ channels: data.channels,
444
+ total: data.total,
445
+ hitsPerPage: data.hits_per_page,
446
+ page: data.page,
447
+ ...data.cursor !== void 0 ? { cursor: data.cursor } : {}
448
+ };
449
+ }
430
450
 
431
451
  // src/ClientCore/SdkOptions/Presence.ts
432
452
  function toPresenceWire(options) {
@@ -476,8 +496,8 @@ function toSudoBody(options) {
476
496
  }
477
497
 
478
498
  // src/Helpers/MessageUtils/Body.ts
479
- import { EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
480
- import { MessageReferenceType } from "@fluxerjs/types";
499
+ import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
500
+ import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
481
501
 
482
502
  // src/Helpers/MessageUtils/Files.ts
483
503
  var FILE_FETCH_TIMEOUT_MS = 3e4;
@@ -540,6 +560,37 @@ function applyReplyPingSuppression(body) {
540
560
  function assignIfDefined(target, key, value) {
541
561
  if (value !== void 0) target[key] = value;
542
562
  }
563
+ function normalizeSendFiles(files) {
564
+ if (!files?.length) return void 0;
565
+ const normalized = [];
566
+ const metaFromBuilders = [];
567
+ let anyBuilderMeta = false;
568
+ for (let i = 0; i < files.length; i++) {
569
+ const file = files[i];
570
+ if (!file) continue;
571
+ if (file instanceof AttachmentBuilder) {
572
+ normalized.push(file.toFileData());
573
+ const meta = {
574
+ id: i,
575
+ filename: file.filename,
576
+ ...file.description != null ? { description: file.description } : {},
577
+ ...file.spoiler ? { flags: MessageAttachmentFlags.IS_SPOILER } : {}
578
+ };
579
+ if (file.description != null || file.spoiler) anyBuilderMeta = true;
580
+ metaFromBuilders.push(meta);
581
+ } else {
582
+ normalized.push(file);
583
+ metaFromBuilders.push({
584
+ id: i,
585
+ filename: file.filename ?? file.name
586
+ });
587
+ }
588
+ }
589
+ return {
590
+ files: normalized,
591
+ metaFromBuilders: anyBuilderMeta ? metaFromBuilders : []
592
+ };
593
+ }
543
594
  function buildSendBody(options) {
544
595
  const body = typeof options === "string" ? { content: options } : options;
545
596
  const result = {};
@@ -547,16 +598,17 @@ function buildSendBody(options) {
547
598
  if (body.embeds?.length) {
548
599
  result.embeds = body.embeds.map((e) => e instanceof EmbedBuilder ? e.toJSON() : e);
549
600
  }
601
+ const normalizedFiles = normalizeSendFiles(body.files);
550
602
  if (body.uploadedAttachments?.length) {
551
603
  result.attachments = body.uploadedAttachments;
552
- } else if (body.files?.length) {
604
+ } else if (normalizedFiles?.files.length) {
553
605
  result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
554
606
  id: a.id,
555
607
  filename: a.filename,
556
608
  ...a.title != null && { title: a.title },
557
609
  ...a.description != null && { description: a.description },
558
610
  ...a.flags != null && { flags: a.flags }
559
- })) : body.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
611
+ })) : normalizedFiles.metaFromBuilders.length ? normalizedFiles.metaFromBuilders : normalizedFiles.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
560
612
  }
561
613
  if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
562
614
  if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
@@ -650,9 +702,10 @@ async function prepareMessagePostPayload(options, defaults) {
650
702
  } else if (allowedMentions?.repliedUser === false) {
651
703
  applyReplyPingSuppression(body);
652
704
  }
705
+ const resolvedFiles = normalizeSendFiles(files);
653
706
  return {
654
707
  body,
655
- files: !uploadedAttachments?.length && files?.length ? await resolveMessageFiles(files) : void 0
708
+ files: !uploadedAttachments?.length && resolvedFiles?.files.length ? await resolveMessageFiles(resolvedFiles.files) : void 0
656
709
  };
657
710
  }
658
711
 
@@ -701,14 +754,22 @@ function qs(params) {
701
754
  return out ? `?${out}` : "";
702
755
  }
703
756
 
757
+ // src/Domain/Base.ts
758
+ var Base = class {
759
+ };
760
+
704
761
  // src/Domain/Message/MessageReaction.ts
705
- var MessageReaction = class extends Base {
762
+ var MessageReaction = class _MessageReaction extends Base {
706
763
  client;
707
764
  messageId;
708
765
  channelId;
709
766
  guildId;
710
767
  emoji;
711
- /** Raw gateway payload for low-level access. */
768
+ /** Total count when hydrated from a message payload; `1` for gateway add events. */
769
+ count;
770
+ /** Whether the current user reacted (message payload); false for gateway remove. */
771
+ me;
772
+ /** Raw gateway payload for low-level access (null when built from a message aggregate). */
712
773
  _data;
713
774
  constructor(client, data) {
714
775
  super();
@@ -722,6 +783,26 @@ var MessageReaction = class extends Base {
722
783
  ...data.emoji.id !== void 0 ? { id: data.emoji.id } : {},
723
784
  ...data.emoji.animated !== void 0 ? { animated: data.emoji.animated } : {}
724
785
  };
786
+ this.count = 1;
787
+ this.me = false;
788
+ }
789
+ /** Build a reaction aggregate from a message's `reactions` array entry. */
790
+ static fromMessage(message, data) {
791
+ const reaction = new _MessageReaction(message.client, {
792
+ user_id: message.client.user?.id ?? "0",
793
+ message_id: message.id,
794
+ channel_id: message.channelId,
795
+ guild_id: message.guildId ?? void 0,
796
+ emoji: {
797
+ name: data.emoji.name,
798
+ id: data.emoji.id ?? void 0,
799
+ animated: data.emoji.animated ?? void 0
800
+ }
801
+ });
802
+ Object.defineProperty(reaction, "_data", { value: null });
803
+ reaction.count = data.count;
804
+ reaction.me = data.me ?? false;
805
+ return reaction;
725
806
  }
726
807
  /** Emoji as a string for reaction routes: unicode or `name:id` (`a:name:id` when animated). */
727
808
  get emojiIdentifier() {
@@ -731,12 +812,23 @@ var MessageReaction = class extends Base {
731
812
  get guild() {
732
813
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
733
814
  }
815
+ /** Cached message this reaction belongs to, or null if the message was not cached. */
816
+ get message() {
817
+ const cached = this.client._getMessageCache(this.channelId)?.get(this.messageId);
818
+ return cached ? new Message(this.client, cached) : null;
819
+ }
820
+ /** Cached text-capable channel, or null if uncached / not text-based. */
821
+ get channel() {
822
+ const channel = this.client.channels.get(this.channelId);
823
+ return channel?.isTextBased() ? channel : null;
824
+ }
734
825
  /**
735
- * Fetch the message this reaction belongs to.
736
- * Use when you need to edit, delete, or otherwise interact with the message.
826
+ * Fetch the message this reaction belongs to (cache first, then REST).
737
827
  * @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
738
828
  */
739
829
  async fetchMessage() {
830
+ const cached = this.message;
831
+ if (cached) return cached;
740
832
  try {
741
833
  const data = await this.client.rest.get(
742
834
  Routes.channelMessage(this.channelId, this.messageId)
@@ -755,7 +847,7 @@ var MessageReaction = class extends Base {
755
847
  };
756
848
 
757
849
  // src/Helpers/ReactionCollector.ts
758
- var ReactionCollector = class extends EventEmitter {
850
+ var ReactionCollector = class _ReactionCollector extends EventEmitter {
759
851
  client;
760
852
  messageId;
761
853
  channelId;
@@ -798,15 +890,17 @@ var ReactionCollector = class extends EventEmitter {
798
890
  ...entry.emoji.animated !== void 0 ? { animated: entry.emoji.animated } : {}
799
891
  }
800
892
  });
801
- const user = entry.member?.user ?? this.client.users.get(entry.userId) ?? this.client.getOrCreateUser({
893
+ const cached = this.client.users.get(entry.userId);
894
+ const user = entry.member?.user ?? cached ?? // Ephemeral stub only; do not cache fake "Unknown" users as real Users.
895
+ {
802
896
  id: entry.userId,
803
897
  username: "Unknown",
804
898
  discriminator: "0",
805
- global_name: null,
899
+ globalName: null,
806
900
  avatar: null,
807
- avatar_color: null,
808
- flags: 0
809
- });
901
+ bot: false,
902
+ system: false
903
+ };
810
904
  this._collect(reaction, user, entry.userId);
811
905
  }
812
906
  };
@@ -838,6 +932,21 @@ var ReactionCollector = class extends EventEmitter {
838
932
  }
839
933
  this.emit("end", this.collected, reason);
840
934
  }
935
+ /**
936
+ * One-shot helper used by {@link Message.awaitReactions}.
937
+ * Resolves with the collected reactions when the collector ends.
938
+ * Rejects if `options.errors` includes the end reason.
939
+ */
940
+ static awaitReactions(client, messageId, channelId, options) {
941
+ const errors = options?.errors ?? [];
942
+ return new Promise((resolve, reject) => {
943
+ const collector = new _ReactionCollector(client, messageId, channelId, options);
944
+ collector.on("end", (collected, reason) => {
945
+ if (errors.includes(reason)) reject(collected);
946
+ else resolve(collected);
947
+ });
948
+ });
949
+ }
841
950
  on(event, listener) {
842
951
  return super.on(event, listener);
843
952
  }
@@ -846,70 +955,224 @@ var ReactionCollector = class extends EventEmitter {
846
955
  }
847
956
  };
848
957
 
849
- // src/Domain/Message/Reactions.ts
850
- import { Routes as Routes2 } from "@fluxerjs/types";
851
- import { parseEmoji } from "@fluxerjs/util";
852
- async function emojiPath(message, emoji) {
853
- return message.client.resolveEmoji(emoji, message.guildId);
958
+ // src/Domain/Message/Attachment.ts
959
+ function toMessageAttachment(data) {
960
+ return {
961
+ id: data.id,
962
+ filename: data.filename,
963
+ title: data.title ?? null,
964
+ description: data.description ?? null,
965
+ contentType: data.content_type ?? null,
966
+ contentHash: data.content_hash ?? null,
967
+ size: data.size,
968
+ url: data.url ?? null,
969
+ proxyUrl: data.proxy_url ?? null,
970
+ width: data.width ?? null,
971
+ height: data.height ?? null,
972
+ placeholder: data.placeholder ?? null,
973
+ flags: data.flags ?? 0,
974
+ nsfw: data.nsfw ?? false,
975
+ duration: data.duration ?? null,
976
+ waveform: data.waveform ?? null,
977
+ expiresAt: data.expires_at ? new Date(data.expires_at) : null,
978
+ expired: data.expired ?? false
979
+ };
854
980
  }
855
- function toReactionEmoji(emoji) {
856
- if (typeof emoji !== "string") {
857
- return {
858
- name: emoji.name,
859
- ...emoji.id !== void 0 ? { id: emoji.id } : {},
860
- ...emoji.animated !== void 0 ? { animated: emoji.animated } : {}
861
- };
981
+
982
+ // src/Domain/Message/Embed.ts
983
+ function toMessageEmbedAuthor(data) {
984
+ return {
985
+ name: data.name ?? null,
986
+ url: data.url ?? null,
987
+ iconUrl: data.icon_url ?? null,
988
+ proxyIconUrl: data.proxy_icon_url ?? null
989
+ };
990
+ }
991
+ function toMessageEmbedFooter(data) {
992
+ return {
993
+ text: data.text,
994
+ iconUrl: data.icon_url ?? null,
995
+ proxyIconUrl: data.proxy_icon_url ?? null
996
+ };
997
+ }
998
+ function toMessageEmbedMedia(data) {
999
+ return {
1000
+ url: data.url,
1001
+ proxyUrl: data.proxy_url ?? null,
1002
+ contentType: data.content_type ?? null,
1003
+ contentHash: data.content_hash ?? null,
1004
+ width: data.width ?? null,
1005
+ height: data.height ?? null,
1006
+ description: data.description ?? null,
1007
+ placeholder: data.placeholder ?? null,
1008
+ duration: data.duration ?? null,
1009
+ flags: data.flags ?? null
1010
+ };
1011
+ }
1012
+ function toMessageEmbed(data) {
1013
+ const full = data;
1014
+ return {
1015
+ type: data.type ?? "rich",
1016
+ url: data.url ?? null,
1017
+ title: data.title ?? null,
1018
+ color: data.color ?? null,
1019
+ timestamp: data.timestamp ? new Date(data.timestamp) : null,
1020
+ description: data.description ?? null,
1021
+ author: data.author ? toMessageEmbedAuthor(data.author) : null,
1022
+ image: data.image ? toMessageEmbedMedia(data.image) : null,
1023
+ thumbnail: data.thumbnail ? toMessageEmbedMedia(data.thumbnail) : null,
1024
+ footer: data.footer ? toMessageEmbedFooter(data.footer) : null,
1025
+ fields: (data.fields ?? []).map((f) => ({
1026
+ name: f.name,
1027
+ value: f.value,
1028
+ inline: f.inline ?? false
1029
+ })),
1030
+ provider: data.provider ? toMessageEmbedAuthor(data.provider) : null,
1031
+ video: data.video ? toMessageEmbedMedia(data.video) : null,
1032
+ audio: data.audio ? toMessageEmbedMedia(data.audio) : null,
1033
+ nsfw: data.nsfw ?? false,
1034
+ children: (full.children ?? []).map(toMessageEmbed),
1035
+ html: full.html ?? null,
1036
+ htmlWidth: full.html_width ?? null,
1037
+ htmlHeight: full.html_height ?? null
1038
+ };
1039
+ }
1040
+
1041
+ // src/Domain/Message/MessageReactionManager.ts
1042
+ import { Collection as Collection2 } from "@fluxerjs/collection";
1043
+ var MessageReactionManager = class {
1044
+ constructor(message) {
1045
+ this.message = message;
862
1046
  }
863
- const animatedWire = /^a:(\w+):(\d+)$/.exec(emoji);
864
- if (animatedWire) {
865
- return { name: animatedWire[1], id: animatedWire[2], animated: true };
1047
+ _cache = new Collection2();
1048
+ /** Reactions keyed by unicode name or `name:id`. */
1049
+ get cache() {
1050
+ return this._cache;
866
1051
  }
867
- const parsed = parseEmoji(emoji);
868
- if (parsed?.id) {
869
- return {
870
- name: parsed.name,
871
- id: parsed.id,
872
- ...parsed.animated ? { animated: true } : {}
873
- };
1052
+ get size() {
1053
+ return this._cache.size;
874
1054
  }
875
- let name = emoji;
876
- try {
877
- name = decodeURIComponent(emoji);
878
- } catch {
879
- }
880
- return { name: parsed?.name ?? name };
881
- }
882
- function emitOwnReactionAdd(message, wireOrInput) {
883
- const user = message.client.user;
884
- if (!user) return;
885
- const emojiPayload = toReactionEmoji(wireOrInput);
886
- const reaction = new MessageReaction(message.client, {
887
- user_id: user.id,
888
- channel_id: message.channelId,
889
- message_id: message.id,
890
- guild_id: message.guildId ?? void 0,
891
- emoji: {
892
- name: emojiPayload.name,
893
- ...emojiPayload.id !== void 0 ? { id: emojiPayload.id } : {},
894
- ...emojiPayload.animated !== void 0 ? { animated: emojiPayload.animated } : {}
1055
+ [Symbol.iterator]() {
1056
+ return this._cache.values();
1057
+ }
1058
+ /** @internal Sync from an API message payload. */
1059
+ _patch(reactions) {
1060
+ this._cache.clear();
1061
+ for (const data of reactions ?? []) {
1062
+ const reaction = MessageReaction.fromMessage(this.message, data);
1063
+ this._cache.set(reaction.emojiIdentifier, reaction);
895
1064
  }
896
- });
897
- const payload = {
898
- reaction,
899
- user,
900
- messageId: message.id,
901
- channelId: message.channelId,
902
- emoji: emojiPayload,
903
- userId: user.id
904
- };
905
- message.client.emit(Events.MessageReactionAdd, payload);
1065
+ }
1066
+ };
1067
+
1068
+ // src/Domain/Message/MessageSticker.ts
1069
+ import { SnowflakeUtil } from "@fluxerjs/util";
1070
+
1071
+ // src/Helpers/Constants.ts
1072
+ import { DEFAULT_USER_AGENT } from "@fluxerjs/rest";
1073
+ var CDN_URL = "https://fluxerusercontent.com";
1074
+ var STATIC_CDN_URL = "https://fluxerstatic.com";
1075
+
1076
+ // src/Helpers/Cdn.ts
1077
+ function mediaBase(options) {
1078
+ return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1079
+ }
1080
+ function staticBase(options) {
1081
+ return (options?.staticCdnBase ?? STATIC_CDN_URL).replace(/\/+$/, "");
1082
+ }
1083
+ function getExtension(hash, options) {
1084
+ const ext = options?.extension ?? "png";
1085
+ if (hash?.startsWith("a_")) return "gif";
1086
+ return ext;
1087
+ }
1088
+ function appendSize(options) {
1089
+ return options?.size ? `?size=${options.size}` : "";
1090
+ }
1091
+ function cdnAvatarURL(userId, avatarHash, options) {
1092
+ if (!avatarHash) return null;
1093
+ const ext = getExtension(avatarHash, options);
1094
+ const size = appendSize(options);
1095
+ return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1096
+ }
1097
+ function cdnBannerURL(resourceId, bannerHash, options) {
1098
+ if (!bannerHash) return null;
1099
+ const ext = getExtension(bannerHash, options);
1100
+ const size = appendSize(options);
1101
+ return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1102
+ }
1103
+ function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1104
+ if (!avatarHash) return null;
1105
+ const ext = getExtension(avatarHash, options);
1106
+ const size = appendSize(options);
1107
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1108
+ }
1109
+ function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1110
+ if (!bannerHash) return null;
1111
+ const ext = getExtension(bannerHash, options);
1112
+ const size = appendSize(options);
1113
+ return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1114
+ }
1115
+ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1116
+ const index = typeof userIdOrIndex === "string" ? Number(BigInt(userIdOrIndex) % 6n) : Math.abs(Math.floor(userIdOrIndex) % 6);
1117
+ return `${staticBase(options)}/avatars/${index}.png`;
1118
+ }
1119
+ function cdnGuildAssetURL(kind, id, hash, options) {
1120
+ if (!hash) return null;
1121
+ const size = options?.size ? `?size=${options.size}` : "";
1122
+ return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1123
+ }
1124
+ function cdnEmojiURL(emojiId, animated, options) {
1125
+ const ext = animated ? "gif" : "png";
1126
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1127
+ }
1128
+ function cdnStickerURL(stickerId, animated, options) {
1129
+ const ext = animated ? "gif" : "png";
1130
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1131
+ }
1132
+
1133
+ // src/Domain/Message/MessageSticker.ts
1134
+ var MessageSticker = class extends Base {
1135
+ client;
1136
+ id;
1137
+ name;
1138
+ description;
1139
+ tags;
1140
+ animated;
1141
+ constructor(client, data) {
1142
+ super();
1143
+ this.client = client;
1144
+ this.id = data.id;
1145
+ this.name = data.name;
1146
+ this.description = data.description ?? "";
1147
+ this.tags = data.tags ?? [];
1148
+ this.animated = data.animated ?? false;
1149
+ }
1150
+ /** CDN URL for this sticker image. */
1151
+ get url() {
1152
+ return cdnStickerURL(this.id, this.animated, {
1153
+ mediaBase: this.client.instance.endpoints.media
1154
+ });
1155
+ }
1156
+ /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
1157
+ get createdTimestamp() {
1158
+ return SnowflakeUtil.timestampFromSnowflake(this.id);
1159
+ }
1160
+ /** Date when this sticker was created, derived from its snowflake ID. */
1161
+ get createdAt() {
1162
+ return SnowflakeUtil.dateFromSnowflake(this.id);
1163
+ }
1164
+ };
1165
+
1166
+ // src/Domain/Message/Reactions.ts
1167
+ import { Routes as Routes2 } from "@fluxerjs/types";
1168
+ async function emojiPath(message, emoji) {
1169
+ return message.client.resolveEmoji(emoji, message.guildId);
906
1170
  }
907
1171
  async function reactToMessage(message, emoji) {
908
1172
  const wire = await emojiPath(message, emoji);
909
1173
  await message.client.rest.put(
910
1174
  Routes2.channelMessageReactionMe(message.channelId, message.id, wire)
911
1175
  );
912
- emitOwnReactionAdd(message, wire);
913
1176
  }
914
1177
  async function removeMessageReaction(message, emoji, userId) {
915
1178
  const e = await emojiPath(message, emoji);
@@ -1015,7 +1278,33 @@ async function replyToMessage(message, options, replyOptions) {
1015
1278
  }
1016
1279
 
1017
1280
  // src/Domain/Message/Message.ts
1281
+ function toMessageCall(data) {
1282
+ return {
1283
+ participants: data.participants,
1284
+ endedAt: data.ended_timestamp ? new Date(data.ended_timestamp) : null
1285
+ };
1286
+ }
1287
+ function toMessageSnapshot(client, data) {
1288
+ return {
1289
+ content: data.content ?? null,
1290
+ createdAt: new Date(data.timestamp),
1291
+ editedAt: data.edited_timestamp ? new Date(data.edited_timestamp) : null,
1292
+ mentionUserIds: data.mentions ?? [],
1293
+ mentionRoles: data.mention_roles ?? [],
1294
+ embeds: (data.embeds ?? []).map(toMessageEmbed),
1295
+ attachments: (data.attachments ?? []).map(toMessageAttachment),
1296
+ stickers: (data.stickers ?? []).map((s) => new MessageSticker(client, s)),
1297
+ ...data.type !== void 0 ? { type: data.type } : {}
1298
+ };
1299
+ }
1300
+ function resolveMessageFlags(flags) {
1301
+ if (flags === void 0) return void 0;
1302
+ if (typeof flags === "number") return flags;
1303
+ return Number(MessageFlagsBitField.resolve(flags));
1304
+ }
1018
1305
  var Message = class _Message extends Base {
1306
+ /** Discriminant vs {@link PartialMessage}: always `false` on a hydrated Message. */
1307
+ partial = false;
1019
1308
  /** The {@link Client} that instantiated this message. */
1020
1309
  client;
1021
1310
  /** Snowflake ID of this message. */
@@ -1044,7 +1333,7 @@ var Message = class _Message extends Base {
1044
1333
  mentionEveryone;
1045
1334
  /** Whether this is a text-to-speech message. */
1046
1335
  tts;
1047
- /** Embedded content (rich previews, etc.). */
1336
+ /** Embedded content (camelCase read view; send with {@link EmbedBuilder}). */
1048
1337
  embeds;
1049
1338
  /** Stickers sent with the message. */
1050
1339
  stickers;
@@ -1066,26 +1355,41 @@ var Message = class _Message extends Base {
1066
1355
  mentionRoles;
1067
1356
  /** Client-side nonce for deduplication. */
1068
1357
  nonce;
1069
- /** Cached text/DM/guild channel, or null if uncached. */
1358
+ /**
1359
+ * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1360
+ * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
1361
+ */
1070
1362
  get channel() {
1071
- return this.client.channels.get(this.channelId) ?? null;
1363
+ const channel = this.client.channels.get(this.channelId) ?? null;
1364
+ return channel?.isTextBased() ? channel : null;
1072
1365
  }
1073
1366
  /** Cached guild, or null for DMs / uncached. */
1074
1367
  get guild() {
1075
1368
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
1076
1369
  }
1077
- /** Fetch and resolve the channel this message is in. */
1370
+ /** Cached guild member for the author, or null in DMs / if uncached. */
1371
+ get member() {
1372
+ return this.guild?.members.get(this.author.id) ?? null;
1373
+ }
1374
+ /**
1375
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1376
+ * has {@link Channel.delete} and {@link Channel.send}.
1377
+ * @example
1378
+ * const channel = await message.resolveChannel();
1379
+ * await channel.delete();
1380
+ */
1078
1381
  async resolveChannel() {
1079
1382
  return this.client.channels.resolve(this.channelId);
1080
1383
  }
1081
- /** Fetch and resolve the guild, or null if a DM. */
1384
+ /**
1385
+ * Fetch and resolve the guild, or null if a DM.
1386
+ * Propagates network/auth errors; only returns null when there is no guildId.
1387
+ * @example
1388
+ * const guild = await message.resolveGuild();
1389
+ */
1082
1390
  async resolveGuild() {
1083
1391
  if (!this.guildId) return null;
1084
- try {
1085
- return await this.client.guilds.resolve(this.guildId);
1086
- } catch {
1087
- return null;
1088
- }
1392
+ return this.client.guilds.resolve(this.guildId);
1089
1393
  }
1090
1394
  /**
1091
1395
  * Construct a message from API data.
@@ -1102,29 +1406,73 @@ var Message = class _Message extends Base {
1102
1406
  this.createdAt = new Date(data.timestamp);
1103
1407
  this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1104
1408
  this.pinned = data.pinned;
1105
- this.attachments = new Collection2();
1106
- for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
1409
+ this.attachments = new Collection3();
1410
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1107
1411
  this.type = data.type ?? MessageType.Default;
1108
- this.flags = data.flags ?? 0;
1412
+ this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
1109
1413
  this.mentionEveryone = data.mention_everyone ?? false;
1110
1414
  this.tts = data.tts ?? false;
1111
- this.embeds = data.embeds ?? [];
1112
- this.stickers = data.stickers ?? [];
1113
- this.reactions = data.reactions ?? [];
1114
- this.messageReference = data.message_reference ?? null;
1115
- this.messageSnapshots = data.message_snapshots ?? [];
1116
- this.call = data.call ?? null;
1415
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1416
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(client, s));
1417
+ this.reactions = new MessageReactionManager(this);
1418
+ this.reactions._patch(data.reactions);
1419
+ this.messageReference = data.message_reference ? {
1420
+ channelId: data.message_reference.channel_id,
1421
+ messageId: data.message_reference.message_id,
1422
+ guildId: data.message_reference.guild_id ?? null,
1423
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1424
+ } : null;
1425
+ this.messageSnapshots = (data.message_snapshots ?? []).map((s) => toMessageSnapshot(client, s));
1426
+ this.call = data.call ? toMessageCall(data.call) : null;
1117
1427
  this.referencedMessage = data.referenced_message ? new _Message(client, data.referenced_message) : null;
1118
1428
  this.webhookId = data.webhook_id ?? null;
1119
1429
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1120
1430
  this.mentionRoles = data.mention_roles ?? [];
1121
1431
  this.nonce = data.nonce ?? null;
1122
1432
  }
1123
- /** Send a message in this channel without replying. */
1433
+ /**
1434
+ * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
1435
+ * @internal
1436
+ */
1437
+ _patch(data) {
1438
+ this.content = data.content;
1439
+ this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
1440
+ this.pinned = data.pinned;
1441
+ this.attachments.clear();
1442
+ for (const a of data.attachments ?? []) this.attachments.set(a.id, toMessageAttachment(a));
1443
+ this.flags = new MessageFlagsBitField(BigInt(data.flags ?? 0));
1444
+ this.mentionEveryone = data.mention_everyone ?? false;
1445
+ this.tts = data.tts ?? false;
1446
+ this.embeds = (data.embeds ?? []).map(toMessageEmbed);
1447
+ this.stickers = (data.stickers ?? []).map((s) => new MessageSticker(this.client, s));
1448
+ this.reactions._patch(data.reactions);
1449
+ this.messageReference = data.message_reference ? {
1450
+ channelId: data.message_reference.channel_id,
1451
+ messageId: data.message_reference.message_id,
1452
+ guildId: data.message_reference.guild_id ?? null,
1453
+ ...data.message_reference.type !== void 0 ? { type: data.message_reference.type } : {}
1454
+ } : null;
1455
+ this.messageSnapshots = (data.message_snapshots ?? []).map(
1456
+ (s) => toMessageSnapshot(this.client, s)
1457
+ );
1458
+ this.call = data.call ? toMessageCall(data.call) : null;
1459
+ this.referencedMessage = data.referenced_message ? new _Message(this.client, data.referenced_message) : null;
1460
+ this.webhookId = data.webhook_id ?? null;
1461
+ this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1462
+ this.mentionRoles = data.mention_roles ?? [];
1463
+ this.nonce = data.nonce ?? null;
1464
+ }
1465
+ /**
1466
+ * Send a standalone message in this channel (not a reply).
1467
+ * Prefer {@link Channel.send} or {@link reply} when you already have the channel or are answering.
1468
+ */
1124
1469
  async send(options) {
1125
1470
  return sendMessage(this, options);
1126
1471
  }
1127
- /** Send a message to another channel by ID. */
1472
+ /**
1473
+ * Send a message to another channel by ID.
1474
+ * Prefer `client.channels.fetch(channelId)` then {@link Channel.send}.
1475
+ */
1128
1476
  async sendTo(channelId, options) {
1129
1477
  return sendMessageTo(this, channelId, options);
1130
1478
  }
@@ -1138,6 +1486,16 @@ var Message = class _Message extends Base {
1138
1486
  async reply(options, replyOptions) {
1139
1487
  return replyToMessage(this, options, replyOptions);
1140
1488
  }
1489
+ /**
1490
+ * Hydrate a partial message, or return the message as-is.
1491
+ * @example
1492
+ * client.on(Events.MessageUpdate, async (_old, msg) => {
1493
+ * const message = await Message.resolve(msg);
1494
+ * });
1495
+ */
1496
+ static async resolve(message) {
1497
+ return message.partial ? message.fetch() : message;
1498
+ }
1141
1499
  /** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
1142
1500
  static async _createMessageBody(content, referenced_message, ping) {
1143
1501
  return createMessageBody(content, referenced_message, ping);
@@ -1150,7 +1508,7 @@ var Message = class _Message extends Base {
1150
1508
  async edit(options) {
1151
1509
  const body = {};
1152
1510
  if (options.content !== void 0) body.content = options.content;
1153
- if (options.embeds?.length) {
1511
+ if (options.embeds !== void 0) {
1154
1512
  body.embeds = options.embeds.map(
1155
1513
  (e) => e instanceof EmbedBuilder2 ? e.toJSON() : e
1156
1514
  );
@@ -1158,7 +1516,8 @@ var Message = class _Message extends Base {
1158
1516
  if (options.allowedMentions) {
1159
1517
  body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
1160
1518
  }
1161
- if (options.flags !== void 0) body.flags = options.flags;
1519
+ const flags = resolveMessageFlags(options.flags);
1520
+ if (flags !== void 0) body.flags = flags;
1162
1521
  if (options.attachments !== void 0) {
1163
1522
  body.attachments = toMessageAttachmentEditWire(options.attachments);
1164
1523
  }
@@ -1173,6 +1532,13 @@ var Message = class _Message extends Base {
1173
1532
  createReactionCollector(options) {
1174
1533
  return new ReactionCollector(this.client, this.id, this.channelId, options);
1175
1534
  }
1535
+ /**
1536
+ * Wait for reactions matching the filter, then resolve the collected set.
1537
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
1538
+ */
1539
+ awaitReactions(options) {
1540
+ return ReactionCollector.awaitReactions(this.client, this.id, this.channelId, options);
1541
+ }
1176
1542
  /** Fetch the latest version of this message from the API. */
1177
1543
  async fetch() {
1178
1544
  return this.client.channels.fetchMessage(this.channelId, this.id);
@@ -1226,7 +1592,68 @@ var Message = class _Message extends Base {
1226
1592
  }
1227
1593
  };
1228
1594
 
1595
+ // src/Domain/Message/PartialMessage.ts
1596
+ import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
1597
+ var PartialMessage = class {
1598
+ partial = true;
1599
+ client;
1600
+ id;
1601
+ channelId;
1602
+ guildId;
1603
+ content;
1604
+ authorId;
1605
+ author;
1606
+ createdAt;
1607
+ constructor(client, data) {
1608
+ this.client = client;
1609
+ this.id = data.id;
1610
+ this.channelId = data.channelId;
1611
+ this.guildId = data.guildId ?? null;
1612
+ this.content = data.content ?? null;
1613
+ this.authorId = data.authorId ?? null;
1614
+ this.author = data.author ?? null;
1615
+ this.createdAt = data.createdAt ?? (SnowflakeUtil2.isValid(data.id) ? SnowflakeUtil2.dateFromSnowflake(data.id) : null);
1616
+ }
1617
+ /**
1618
+ * Live text-capable channel from cache, or null if uncached / not text-based.
1619
+ * Same contract as {@link Message.channel}.
1620
+ */
1621
+ get channel() {
1622
+ const channel = this.client.channels.get(this.channelId) ?? null;
1623
+ return channel?.isTextBased() ? channel : null;
1624
+ }
1625
+ /**
1626
+ * Fetch this message's channel (cache first). The returned {@link Channel}
1627
+ * has {@link Channel.delete} and {@link Channel.send}.
1628
+ * @example
1629
+ * const channel = await message.resolveChannel();
1630
+ * await channel.delete();
1631
+ */
1632
+ async resolveChannel() {
1633
+ return this.client.channels.resolve(this.channelId);
1634
+ }
1635
+ /**
1636
+ * Fetch the full message from the API.
1637
+ * @example
1638
+ * const message = await partial.fetch();
1639
+ * await message.reply('Pong!');
1640
+ */
1641
+ async fetch() {
1642
+ return this.client.channels.fetchMessage(this.channelId, this.id);
1643
+ }
1644
+ };
1645
+
1646
+ // src/Domain/User.ts
1647
+ import { Routes as Routes14 } from "@fluxerjs/types";
1648
+ import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
1649
+
1650
+ // src/Domain/Channel/Base.ts
1651
+ import { ChannelType, Routes as Routes7 } from "@fluxerjs/types";
1652
+ import { SnowflakeUtil as SnowflakeUtil3 } from "@fluxerjs/util";
1653
+
1229
1654
  // src/ClientCore/MessageManager.ts
1655
+ import { Collection as Collection4 } from "@fluxerjs/collection";
1656
+ import { Routes as Routes5 } from "@fluxerjs/types";
1230
1657
  var BULK = {
1231
1658
  requests: { min: 1, max: 25 },
1232
1659
  limit: { min: 1, max: 25 },
@@ -1260,19 +1687,40 @@ var MessageManager = class {
1260
1687
  this.client = client;
1261
1688
  this.channelId = channelId;
1262
1689
  }
1690
+ /** Structure cache keyed by message id (identity for {@link get}). */
1691
+ _structures = new Collection4();
1263
1692
  /** Retrieve a cached message by ID, or `undefined` if missing / caching disabled. */
1264
1693
  get(messageId) {
1265
1694
  const data = this.client._getMessageCache(this.channelId)?.get(messageId);
1266
- return data ? new Message(this.client, data) : void 0;
1695
+ if (!data) {
1696
+ this._structures.delete(messageId);
1697
+ return void 0;
1698
+ }
1699
+ const existing = this._structures.get(messageId);
1700
+ if (existing) return existing;
1701
+ const message = new Message(this.client, data);
1702
+ this._structures.set(messageId, message);
1703
+ return message;
1704
+ }
1705
+ /** Retrieve from cache, otherwise {@link fetch}. */
1706
+ async resolve(messageId) {
1707
+ return this.get(messageId) ?? this.fetch(messageId);
1267
1708
  }
1268
1709
  async fetch(idOrOptions) {
1269
1710
  return typeof idOrOptions === "string" ? this.fetchOne(idOrOptions) : this.fetchMany(idOrOptions);
1270
1711
  }
1271
- /** Cache API data and return a {@link Message} built from the cached entry when present. */
1712
+ /** Cache API data and return a {@link Message} (reusing identity when present). */
1272
1713
  wrap(data) {
1273
1714
  this.client._addMessageToCache(this.channelId, data);
1274
1715
  const cached = this.client._getMessageCache(this.channelId)?.get(data.id) ?? data;
1275
- return new Message(this.client, cached);
1716
+ const existing = this._structures.get(data.id);
1717
+ if (existing) {
1718
+ existing._patch(cached);
1719
+ return existing;
1720
+ }
1721
+ const message = new Message(this.client, cached);
1722
+ this._structures.set(data.id, message);
1723
+ return message;
1276
1724
  }
1277
1725
  /** Fetch a single message from the API. */
1278
1726
  async fetchOne(messageId) {
@@ -1305,12 +1753,110 @@ var MessageManager = class {
1305
1753
  }
1306
1754
  const base = Routes5.channelMessages(this.channelId);
1307
1755
  const data = await this.client.rest.get(qs2.size > 0 ? `${base}?${qs2}` : base);
1308
- const collection = new Collection3();
1756
+ const collection = new Collection4();
1309
1757
  for (const msg of data) collection.set(msg.id, this.wrap(msg));
1310
1758
  return collection;
1311
1759
  }
1312
1760
  };
1313
1761
 
1762
+ // src/Helpers/MessageCollector.ts
1763
+ import { EventEmitter as EventEmitter2 } from "events";
1764
+ import { Collection as Collection5 } from "@fluxerjs/collection";
1765
+ function requireCollectorBounds(options) {
1766
+ const time = options.time ?? 0;
1767
+ const max = options.max ?? 0;
1768
+ if (time <= 0 && max <= 0) {
1769
+ throw new FluxerError("MessageCollector requires `time` and/or `max`", {
1770
+ code: ErrorCodes.CollectorOptionsRequired
1771
+ });
1772
+ }
1773
+ }
1774
+ var MessageCollector = class _MessageCollector extends EventEmitter2 {
1775
+ client;
1776
+ channelId;
1777
+ options;
1778
+ collected = new Collection5();
1779
+ _timeout = null;
1780
+ _ended = false;
1781
+ _listener;
1782
+ constructor(client, channelId, options = {}) {
1783
+ super();
1784
+ requireCollectorBounds(options);
1785
+ this.client = client;
1786
+ this.channelId = channelId;
1787
+ this.options = {
1788
+ filter: options.filter ?? (() => true),
1789
+ time: options.time ?? 0,
1790
+ max: options.max ?? 0
1791
+ };
1792
+ this._listener = (message) => {
1793
+ if (this._ended || message.channelId !== this.channelId) return;
1794
+ if (!this.options.filter(message)) return;
1795
+ this.collected.set(message.id, message);
1796
+ this.emit("collect", message);
1797
+ if (this.options.max > 0 && this.collected.size >= this.options.max) {
1798
+ this.stop("limit");
1799
+ }
1800
+ };
1801
+ this.client.on(Events.MessageCreate, this._listener);
1802
+ if (this.options.time > 0) {
1803
+ this._timeout = setTimeout(() => this.stop("time"), this.options.time);
1804
+ }
1805
+ }
1806
+ stop(reason = "user") {
1807
+ if (this._ended) return;
1808
+ this._ended = true;
1809
+ this.client.off(Events.MessageCreate, this._listener);
1810
+ if (this._timeout) {
1811
+ clearTimeout(this._timeout);
1812
+ this._timeout = null;
1813
+ }
1814
+ this.emit("end", this.collected, reason);
1815
+ }
1816
+ /**
1817
+ * One-shot helper used by {@link Channel.awaitMessages}.
1818
+ * Resolves with the collected messages when the collector ends for `user` (or when
1819
+ * the end reason is not listed in `errors`).
1820
+ * By default, `time` and `limit` reject with {@link FluxerError}
1821
+ * (`CollectorIdle` / `CollectorMax`).
1822
+ */
1823
+ static awaitMessages(client, channelId, options) {
1824
+ const errors = options?.errors ?? ["time", "limit"];
1825
+ return new Promise((resolve, reject) => {
1826
+ const collector = new _MessageCollector(client, channelId, options);
1827
+ collector.on("end", (collected, reason) => {
1828
+ if (!errors.includes(reason)) {
1829
+ resolve(collected);
1830
+ return;
1831
+ }
1832
+ if (reason === "time") {
1833
+ reject(
1834
+ new FluxerError("Message collector timed out", {
1835
+ code: ErrorCodes.CollectorIdle
1836
+ })
1837
+ );
1838
+ return;
1839
+ }
1840
+ if (reason === "limit") {
1841
+ reject(
1842
+ new FluxerError("Message collector reached max", {
1843
+ code: ErrorCodes.CollectorMax
1844
+ })
1845
+ );
1846
+ return;
1847
+ }
1848
+ reject(collected);
1849
+ });
1850
+ });
1851
+ }
1852
+ on(event, listener) {
1853
+ return super.on(event, listener);
1854
+ }
1855
+ emit(event, ...args) {
1856
+ return super.emit(event, ...args);
1857
+ }
1858
+ };
1859
+
1314
1860
  // src/Domain/Channel/Attachments.ts
1315
1861
  import { Routes as Routes6 } from "@fluxerjs/types";
1316
1862
  function asBytes(data) {
@@ -1389,6 +1935,7 @@ async function uploadAttachmentsForSend(client, channelId, files) {
1389
1935
 
1390
1936
  // src/Domain/Channel/Base.ts
1391
1937
  var Channel = class extends Base {
1938
+ #messages;
1392
1939
  /** The {@link Client} that instantiated this channel. */
1393
1940
  client;
1394
1941
  /** Snowflake ID of this channel. */
@@ -1412,11 +1959,11 @@ var Channel = class extends Base {
1412
1959
  }
1413
1960
  /** Unix timestamp (ms) when this channel was created, derived from its snowflake ID. */
1414
1961
  get createdTimestamp() {
1415
- return SnowflakeUtil.timestampFromSnowflake(this.id);
1962
+ return SnowflakeUtil3.timestampFromSnowflake(this.id);
1416
1963
  }
1417
1964
  /** Date when this channel was created, derived from its snowflake ID. */
1418
1965
  get createdAt() {
1419
- return SnowflakeUtil.dateFromSnowflake(this.id);
1966
+ return SnowflakeUtil3.dateFromSnowflake(this.id);
1420
1967
  }
1421
1968
  /**
1422
1969
  * Apply shared channel fields in place (gateway CHANNEL_UPDATE when type is unchanged).
@@ -1430,19 +1977,36 @@ var Channel = class extends Base {
1430
1977
  this.lastPinTimestamp = data.last_pin_timestamp ?? null;
1431
1978
  }
1432
1979
  }
1433
- /** Wired in `structures/channel/index.ts` after subclasses load. */
1980
+ /** @internal Factory wired after subclasses load. */
1434
1981
  static from(_c, _d) {
1435
1982
  throw new Error("Channel.from not initialized");
1436
1983
  }
1984
+ /** @internal Factory wired after subclasses load. */
1437
1985
  static fromOrCreate(_c, _d) {
1438
1986
  throw new Error("Channel.fromOrCreate not initialized");
1439
1987
  }
1440
- static createDM(_c, _d) {
1441
- throw new Error("Channel.createDM not initialized");
1988
+ /** @internal Factory wired after subclasses load. */
1989
+ static createDM(_c, _d) {
1990
+ throw new Error("Channel.createDM not initialized");
1991
+ }
1992
+ /**
1993
+ * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
1994
+ * Checks {@link ChannelType}, not whether `send` exists on the instance.
1995
+ */
1996
+ isTextBased() {
1997
+ return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
1998
+ }
1999
+ /** Check if this is a guild channel (text, voice, category, or link). */
2000
+ isGuild() {
2001
+ return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
1442
2002
  }
1443
- /** Check if this channel supports sending messages (text/DM). */
1444
- isTextBased() {
1445
- return "send" in this;
2003
+ /** Check if this is a guild text channel. */
2004
+ isText() {
2005
+ return this.type === ChannelType.GuildText;
2006
+ }
2007
+ /** Check if this is a category channel. */
2008
+ isCategory() {
2009
+ return this.type === ChannelType.GuildCategory;
1446
2010
  }
1447
2011
  /** Check if this is a DM, group DM, or personal notes channel. */
1448
2012
  isDM() {
@@ -1454,11 +2018,11 @@ var Channel = class extends Base {
1454
2018
  }
1455
2019
  /** Check if this is a voice channel. */
1456
2020
  isVoice() {
1457
- return "bitrate" in this;
2021
+ return this.type === ChannelType.GuildVoice;
1458
2022
  }
1459
2023
  /** Check if this is a link channel. */
1460
2024
  isLink() {
1461
- return "url" in this;
2025
+ return this.type === ChannelType.GuildLink;
1462
2026
  }
1463
2027
  /**
1464
2028
  * Delete recent messages or an explicit ID list.
@@ -1497,7 +2061,7 @@ var Channel = class extends Base {
1497
2061
  for (const id of ids) this.client._removeMessageFromCache(this.id, id);
1498
2062
  return ids;
1499
2063
  }
1500
- /** Delete all messages sent by the bot in this channel (user account feature). */
2064
+ /** Delete all messages sent by the bot in this channel. Sudo auto-passes for bots. */
1501
2065
  async bulkDeleteMyMessages(options) {
1502
2066
  const body = options ? toSudoBody(options) : void 0;
1503
2067
  await this.client.rest.post(Routes7.channelBulkDeleteMine(this.id), {
@@ -1505,11 +2069,17 @@ var Channel = class extends Base {
1505
2069
  auth: true
1506
2070
  });
1507
2071
  }
1508
- /** Mark all pinned messages as read in this channel. */
2072
+ /**
2073
+ * Mark all pinned messages as read in this channel.
2074
+ * Session-token helper; bots usually skip this.
2075
+ */
1509
2076
  async acknowledgePins() {
1510
2077
  await this.client.rest.post(Routes7.channelPinsAck(this.id), { auth: true });
1511
2078
  }
1512
- /** Clear the read state for this channel. */
2079
+ /**
2080
+ * Clear the read state for this channel.
2081
+ * Session-token helper; bots usually skip this.
2082
+ */
1513
2083
  async clearReadState() {
1514
2084
  await this.client.rest.delete(Routes7.channelMessagesAck(this.id), { auth: true });
1515
2085
  }
@@ -1545,7 +2115,11 @@ var Channel = class extends Base {
1545
2115
  async sendTyping() {
1546
2116
  await this.client.rest.post(Routes7.channelTyping(this.id), { auth: true });
1547
2117
  }
1548
- /** Fetch available RTC regions for voice channels. */
2118
+ /**
2119
+ * Fetch available RTC regions for voice channels.
2120
+ * User-account only (`DefaultUserOnly`); bots receive `AccessDeniedError`.
2121
+ * Bots should skip this and join voice with `@fluxerjs/voice` instead.
2122
+ */
1549
2123
  async fetchRtcRegions() {
1550
2124
  const data = await this.client.rest.get(Routes7.channelRtcRegions(this.id), {
1551
2125
  auth: true
@@ -1564,71 +2138,65 @@ var Channel = class extends Base {
1564
2138
  nextSendAllowedAt: data.next_send_allowed_at
1565
2139
  };
1566
2140
  }
1567
- /** Check if the bot can send messages in this channel. */
2141
+ /** Whether this channel type can carry messages (does not check permissions). */
1568
2142
  canSendMessage() {
1569
- return this.isDM();
2143
+ return this.isTextBased();
1570
2144
  }
1571
- };
1572
-
1573
- // src/Domain/Channel/Dm.ts
1574
- import { ChannelType as ChannelType2, Routes as Routes9 } from "@fluxerjs/types";
1575
-
1576
- // src/Domain/Channel/TextCapable.ts
1577
- import { Routes as Routes8 } from "@fluxerjs/types";
1578
-
1579
- // src/Helpers/MessageCollector.ts
1580
- import { EventEmitter as EventEmitter2 } from "events";
1581
- import { Collection as Collection4 } from "@fluxerjs/collection";
1582
- var MessageCollector = class extends EventEmitter2 {
1583
- client;
1584
- channelId;
1585
- options;
1586
- collected = new Collection4();
1587
- _timeout = null;
1588
- _ended = false;
1589
- _listener;
1590
- constructor(client, channelId, options = {}) {
1591
- super();
1592
- this.client = client;
1593
- this.channelId = channelId;
1594
- this.options = {
1595
- filter: options.filter ?? (() => true),
1596
- time: options.time ?? 0,
1597
- max: options.max ?? 0
1598
- };
1599
- this._listener = (message) => {
1600
- if (this._ended || message.channelId !== this.channelId) return;
1601
- if (!this.options.filter(message)) return;
1602
- this.collected.set(message.id, message);
1603
- this.emit("collect", message);
1604
- if (this.options.max > 0 && this.collected.size >= this.options.max) {
1605
- this.stop("limit");
1606
- }
1607
- };
1608
- this.client.on(Events.MessageCreate, this._listener);
1609
- if (this.options.time > 0) {
1610
- this._timeout = setTimeout(() => this.stop("time"), this.options.time);
2145
+ /** Per-channel message cache + fetch. */
2146
+ get messages() {
2147
+ if (!this.#messages) {
2148
+ this.#messages = new MessageManager(this.client, this.id);
1611
2149
  }
2150
+ return this.#messages;
1612
2151
  }
1613
- stop(reason = "user") {
1614
- if (this._ended) return;
1615
- this._ended = true;
1616
- this.client.off(Events.MessageCreate, this._listener);
1617
- if (this._timeout) {
1618
- clearTimeout(this._timeout);
1619
- this._timeout = null;
1620
- }
1621
- this.emit("end", this.collected, reason);
2152
+ /** Collect messages in this channel until time/max/stop. */
2153
+ createMessageCollector(options) {
2154
+ return new MessageCollector(this.client, this.id, options);
1622
2155
  }
1623
- on(event, listener) {
1624
- return super.on(event, listener);
2156
+ /**
2157
+ * Wait for messages matching the filter, then resolve the collected set.
2158
+ * Pass `errors: ['time']` to reject when the timer fires instead of resolving.
2159
+ * @example
2160
+ * const collected = await channel.awaitMessages({ max: 1, time: 15_000 });
2161
+ */
2162
+ awaitMessages(options) {
2163
+ return MessageCollector.awaitMessages(this.client, this.id, options);
1625
2164
  }
1626
- emit(event, ...args) {
1627
- return super.emit(event, ...args);
2165
+ /**
2166
+ * Delete this channel (or close it if it is a DM).
2167
+ * Guild channels require Manage Channels. `silent` / `deleteMessages` are Fluxer query params.
2168
+ * @example
2169
+ * const channel = await client.channels.fetch(channelId);
2170
+ * await channel.delete();
2171
+ */
2172
+ async delete(options) {
2173
+ const params = new URLSearchParams();
2174
+ if (options?.silent) params.set("silent", "true");
2175
+ if (options?.deleteMessages) params.set("delete_messages", "true");
2176
+ const qs2 = params.toString();
2177
+ const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2178
+ const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2179
+ await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2180
+ body,
2181
+ auth: true
2182
+ });
2183
+ this.client.channels.delete(this.id);
2184
+ this.client._clearMessageCache(this.id);
2185
+ if (this.isGuild() && this.guildId) {
2186
+ this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2187
+ }
2188
+ }
2189
+ /** Channel mention (`<#id>`). */
2190
+ toString() {
2191
+ return `<#${this.id}>`;
1628
2192
  }
1629
2193
  };
1630
2194
 
2195
+ // src/Domain/Channel/Dm.ts
2196
+ import { ChannelType as ChannelType2, Routes as Routes9 } from "@fluxerjs/types";
2197
+
1631
2198
  // src/Domain/Channel/TextCapable.ts
2199
+ import { Routes as Routes8 } from "@fluxerjs/types";
1632
2200
  async function fetchPinnedMessagesPageFor(client, channelId, options) {
1633
2201
  const params = new URLSearchParams();
1634
2202
  if (options?.limit != null) params.set("limit", String(options.limit));
@@ -1646,27 +2214,19 @@ async function fetchPinnedMessagesPageFor(client, channelId, options) {
1646
2214
  }
1647
2215
  function TextCapable(Base2) {
1648
2216
  class TextCapableChannel extends Base2 {
1649
- #messages;
2217
+ /**
2218
+ * Send a message in this channel.
2219
+ * @example
2220
+ * await channel.send('hi');
2221
+ */
1650
2222
  async send(options) {
1651
- const payload = await prepareMessagePostPayload(options, {
1652
- defaultAllowedMentions: this.client.options.defaultAllowedMentions
1653
- });
1654
- const data = await this.client.rest.post(Routes8.channelMessages(this.id), payload);
1655
- this.client._addMessageToCache(this.id, data);
1656
- return new Message(this.client, data);
1657
- }
1658
- get messages() {
1659
- if (!this.#messages) {
1660
- this.#messages = new MessageManager(this.client, this.id);
1661
- }
1662
- return this.#messages;
1663
- }
1664
- createMessageCollector(options) {
1665
- return new MessageCollector(this.client, this.id, options);
2223
+ return this.client.channels.send(this.id, options);
1666
2224
  }
2225
+ /** Fetch pinned messages in this channel. */
1667
2226
  async fetchPinnedMessages(options) {
1668
2227
  return (await this.fetchPinnedMessagesPage(options)).messages;
1669
2228
  }
2229
+ /** Fetch a page of pinned messages plus pagination metadata. */
1670
2230
  async fetchPinnedMessagesPage(options) {
1671
2231
  return fetchPinnedMessagesPageFor(this.client, this.id, options);
1672
2232
  }
@@ -1692,7 +2252,38 @@ var DMChannel = class extends TextCapable(Channel) {
1692
2252
  this.recipients = (full.recipients ?? []).map((u) => client.getOrCreateUser(u));
1693
2253
  this.nicks = full.nicks ?? {};
1694
2254
  }
1695
- /** Purge all messages from personal notes. Only works on personal notes channels. */
2255
+ /**
2256
+ * Apply DM/group-DM fields in place.
2257
+ * @internal
2258
+ */
2259
+ _patch(data) {
2260
+ super._patch(data);
2261
+ const full = data;
2262
+ if ("last_message_id" in full && full.last_message_id !== void 0) {
2263
+ this.lastMessageId = full.last_message_id ?? null;
2264
+ }
2265
+ if ("owner_id" in full && full.owner_id !== void 0) this.ownerId = full.owner_id ?? null;
2266
+ if ("recipients" in full && full.recipients !== void 0) {
2267
+ this.recipients = (full.recipients ?? []).map((u) => this.client.getOrCreateUser(u));
2268
+ }
2269
+ if ("nicks" in full && full.nicks !== void 0) this.nicks = full.nicks ?? {};
2270
+ }
2271
+ /**
2272
+ * Edit this group DM (name, icon, nicks).
2273
+ * Transferring ownership to a bot fails (`CannotTransferOwnershipToBotError`).
2274
+ */
2275
+ async edit(options) {
2276
+ const data = await this.client.rest.patch(Routes9.channel(this.id), {
2277
+ body: toGroupDmEditBody(options),
2278
+ auth: true
2279
+ });
2280
+ this._patch(data);
2281
+ return this;
2282
+ }
2283
+ /**
2284
+ * Purge all messages from personal notes. Only works on personal notes channels.
2285
+ * Notes-only; bots usually skip this.
2286
+ */
1696
2287
  async purgeMessages() {
1697
2288
  if (this.type !== ChannelType2.DMPersonalNotes) {
1698
2289
  throw new FluxerError("purgeMessages is only available on personal notes channels", {
@@ -1705,15 +2296,24 @@ var DMChannel = class extends TextCapable(Channel) {
1705
2296
  );
1706
2297
  return data.deleted_count;
1707
2298
  }
1708
- /** Pin this DM channel to the top of the DM list. */
2299
+ /**
2300
+ * Pin this DM channel to the top of the DM list.
2301
+ * Session-token helper; bots usually skip this.
2302
+ */
1709
2303
  async pinInList() {
1710
2304
  await this.client.rest.put(Routes9.userMeChannelPin(this.id), { auth: true });
1711
2305
  }
1712
- /** Unpin this DM channel from the DM list. */
2306
+ /**
2307
+ * Unpin this DM channel from the DM list.
2308
+ * Session-token helper; bots usually skip this.
2309
+ */
1713
2310
  async unpinFromList() {
1714
2311
  await this.client.rest.delete(Routes9.userMeChannelPin(this.id), { auth: true });
1715
2312
  }
1716
- /** Add a user to this group DM. */
2313
+ /**
2314
+ * Add a user to this group DM.
2315
+ * Captcha-gated when captcha is enabled; bots are not exempt (`CaptchaRequiredError`).
2316
+ */
1717
2317
  async addRecipient(userId) {
1718
2318
  await this.client.rest.put(Routes9.channelRecipient(this.id, userId), { auth: true });
1719
2319
  const user = this.client.users.get(userId) ?? await this.client.users.fetch(userId);
@@ -1729,7 +2329,7 @@ var DMChannel = class extends TextCapable(Channel) {
1729
2329
  };
1730
2330
 
1731
2331
  // src/Domain/Channel/Guild.ts
1732
- import { Routes as Routes12 } from "@fluxerjs/types";
2332
+ import { Routes as Routes13 } from "@fluxerjs/types";
1733
2333
  import { PermissionFlags } from "@fluxerjs/util";
1734
2334
 
1735
2335
  // src/Domain/Invite.ts
@@ -1737,7 +2337,6 @@ import {
1737
2337
  InviteType,
1738
2338
  isGroupDmInvite,
1739
2339
  isGuildInvite,
1740
- isPackInvite,
1741
2340
  Routes as Routes10
1742
2341
  } from "@fluxerjs/types";
1743
2342
 
@@ -1933,13 +2532,36 @@ function parseInviteCode(codeOrUrl) {
1933
2532
  }
1934
2533
  return code;
1935
2534
  }
2535
+ function parseOptionalDate(value) {
2536
+ if (value == null || value === "") return null;
2537
+ const date = new Date(value);
2538
+ return Number.isNaN(date.getTime()) ? null : date;
2539
+ }
2540
+ function toInviteGuild(data) {
2541
+ return {
2542
+ id: data.id,
2543
+ name: data.name,
2544
+ icon: data.icon ?? null,
2545
+ banner: data.banner ?? null,
2546
+ splash: data.splash ?? null,
2547
+ features: data.features ?? []
2548
+ };
2549
+ }
2550
+ function toInviteChannel(data) {
2551
+ return {
2552
+ id: data.id,
2553
+ name: data.name ?? null,
2554
+ type: data.type,
2555
+ icon: data.icon ?? null,
2556
+ parentId: data.parent_id ?? null
2557
+ };
2558
+ }
1936
2559
  var Invite = class _Invite extends Base {
1937
2560
  client;
1938
2561
  code;
1939
2562
  type;
1940
- guild;
1941
- channel;
1942
- pack;
2563
+ guildSnapshot;
2564
+ channelSnapshot;
1943
2565
  inviter;
1944
2566
  memberCount;
1945
2567
  presenceCount;
@@ -1954,15 +2576,14 @@ var Invite = class _Invite extends Base {
1954
2576
  this.client = client;
1955
2577
  this.code = data.code;
1956
2578
  this.type = data.type;
1957
- this.guild = isGuildInvite(data) ? data.guild : null;
1958
- this.channel = isGuildInvite(data) || isGroupDmInvite(data) ? data.channel : null;
1959
- this.pack = isPackInvite(data) ? data.pack : null;
2579
+ this.guildSnapshot = isGuildInvite(data) ? toInviteGuild(data.guild) : null;
2580
+ this.channelSnapshot = isGuildInvite(data) || isGroupDmInvite(data) ? toInviteChannel(data.channel) : null;
1960
2581
  this.inviter = data.inviter ? client.getOrCreateUser(data.inviter) : null;
1961
- this.memberCount = isPackInvite(data) ? null : data.member_count ?? null;
2582
+ this.memberCount = data.member_count ?? null;
1962
2583
  this.presenceCount = isGuildInvite(data) ? data.presence_count ?? null : null;
1963
- this.expiresAt = data.expires_at ?? null;
2584
+ this.expiresAt = parseOptionalDate(data.expires_at);
1964
2585
  this.temporary = data.temporary ?? null;
1965
- this.createdAt = data.created_at ?? null;
2586
+ this.createdAt = parseOptionalDate(data.created_at);
1966
2587
  this.uses = data.uses ?? null;
1967
2588
  this.maxUses = data.max_uses ?? null;
1968
2589
  this.maxAge = data.max_age ?? null;
@@ -1973,16 +2594,25 @@ var Invite = class _Invite extends Base {
1973
2594
  isGroupDM() {
1974
2595
  return this.type === InviteType.GroupDM;
1975
2596
  }
1976
- isPack() {
1977
- return this.type === InviteType.EmojiPack || this.type === InviteType.StickerPack;
1978
- }
1979
2597
  /** Full invite URL (uses this client's instance invite base). */
1980
2598
  get url() {
1981
2599
  return inviteUrl(this.client.instance.endpoints.invite, this.code);
1982
2600
  }
1983
- /** Cached guild for guild invites, else null. */
1984
- getGuild() {
1985
- return this.guild?.id ? this.client.guilds.get(this.guild.id) ?? null : null;
2601
+ /**
2602
+ * Resolve the cached/fetched {@link Guild} for this invite, or null.
2603
+ * `guildSnapshot` is metadata only.
2604
+ */
2605
+ async resolveGuild() {
2606
+ if (!this.guildSnapshot?.id) return null;
2607
+ return this.client.guilds.resolve(this.guildSnapshot.id);
2608
+ }
2609
+ /**
2610
+ * Resolve the cached/fetched {@link Channel} for this invite, or null.
2611
+ * `channelSnapshot` is metadata only.
2612
+ */
2613
+ async resolveChannel() {
2614
+ if (!this.channelSnapshot?.id) return null;
2615
+ return this.client.channels.resolve(this.channelSnapshot.id);
1986
2616
  }
1987
2617
  /** Fetch invite metadata by code or URL (does not join). */
1988
2618
  static async fetch(client, codeOrUrl) {
@@ -2000,7 +2630,7 @@ import { EmbedBuilder as EmbedBuilder3 } from "@fluxerjs/builders";
2000
2630
  import {
2001
2631
  Routes as Routes11
2002
2632
  } from "@fluxerjs/types";
2003
- import { SnowflakeUtil as SnowflakeUtil2 } from "@fluxerjs/util";
2633
+ import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
2004
2634
  var Webhook = class _Webhook extends Base {
2005
2635
  /** Parent client instance. */
2006
2636
  client;
@@ -2037,11 +2667,11 @@ var Webhook = class _Webhook extends Base {
2037
2667
  }
2038
2668
  /** Unix timestamp (ms) when this webhook was created, derived from its snowflake ID. */
2039
2669
  get createdTimestamp() {
2040
- return SnowflakeUtil2.timestampFromSnowflake(this.id);
2670
+ return SnowflakeUtil4.timestampFromSnowflake(this.id);
2041
2671
  }
2042
2672
  /** Date when this webhook was created, derived from its snowflake ID. */
2043
2673
  get createdAt() {
2044
- return SnowflakeUtil2.dateFromSnowflake(this.id);
2674
+ return SnowflakeUtil4.dateFromSnowflake(this.id);
2045
2675
  }
2046
2676
  /** Delete this webhook (token auth when available, otherwise bot auth). */
2047
2677
  async delete() {
@@ -2163,9 +2793,103 @@ var Webhook = class _Webhook extends Base {
2163
2793
  }
2164
2794
  };
2165
2795
 
2796
+ // src/Domain/Channel/PermissionOverwriteManager.ts
2797
+ import { Collection as Collection6 } from "@fluxerjs/collection";
2798
+ import { Routes as Routes12 } from "@fluxerjs/types";
2799
+ import { resolvePermissionsToBitfield as resolvePermissionsToBitfield3 } from "@fluxerjs/util";
2800
+
2801
+ // src/Domain/Channel/PermissionOverwrite.ts
2802
+ import { PermissionsBitField } from "@fluxerjs/util";
2803
+ var PermissionOverwrite = class {
2804
+ id;
2805
+ type;
2806
+ /** @internal Raw allow bitfield string. */
2807
+ _allow;
2808
+ /** @internal Raw deny bitfield string. */
2809
+ _deny;
2810
+ constructor(data) {
2811
+ this.id = data.id;
2812
+ this.type = data.type;
2813
+ this._allow = data.allow ?? "0";
2814
+ this._deny = data.deny ?? "0";
2815
+ }
2816
+ /** Allowed permissions for this overwrite. */
2817
+ get allow() {
2818
+ return new PermissionsBitField(BigInt(this._allow || "0"));
2819
+ }
2820
+ /** Denied permissions for this overwrite. */
2821
+ get deny() {
2822
+ return new PermissionsBitField(BigInt(this._deny || "0"));
2823
+ }
2824
+ /** Wire shape for permission computation / REST. */
2825
+ toJSON() {
2826
+ return {
2827
+ id: this.id,
2828
+ type: this.type,
2829
+ allow: this._allow,
2830
+ deny: this._deny
2831
+ };
2832
+ }
2833
+ };
2834
+
2835
+ // src/Domain/Channel/PermissionOverwriteManager.ts
2836
+ var PermissionOverwriteManager = class {
2837
+ constructor(channel, initial = []) {
2838
+ this.channel = channel;
2839
+ this._patch(initial);
2840
+ }
2841
+ _cache = new Collection6();
2842
+ /** Cached overwrites keyed by role/member ID. */
2843
+ get cache() {
2844
+ return this._cache;
2845
+ }
2846
+ get size() {
2847
+ return this._cache.size;
2848
+ }
2849
+ [Symbol.iterator]() {
2850
+ return this._cache.values();
2851
+ }
2852
+ /** Wire-shaped overwrites for permission computation. */
2853
+ toJSON() {
2854
+ return [...this._cache.values()].map((o) => o.toJSON());
2855
+ }
2856
+ /** Edit or create a permission overwrite. */
2857
+ async edit(overwriteId, options) {
2858
+ const allow = options.allow !== void 0 ? resolvePermissionsToBitfield3(options.allow) : "0";
2859
+ const deny = options.deny !== void 0 ? resolvePermissionsToBitfield3(options.deny) : "0";
2860
+ await this.channel.client.rest.put(Routes12.channelPermission(this.channel.id, overwriteId), {
2861
+ body: { type: options.type, allow, deny },
2862
+ auth: true
2863
+ });
2864
+ this._cache.set(
2865
+ overwriteId,
2866
+ new PermissionOverwrite({
2867
+ id: overwriteId,
2868
+ type: options.type,
2869
+ allow,
2870
+ deny
2871
+ })
2872
+ );
2873
+ }
2874
+ /** Delete a permission overwrite. */
2875
+ async delete(overwriteId) {
2876
+ await this.channel.client.rest.delete(Routes12.channelPermission(this.channel.id, overwriteId), {
2877
+ auth: true
2878
+ });
2879
+ this._cache.delete(overwriteId);
2880
+ }
2881
+ /** @internal Sync from an API channel payload. */
2882
+ _patch(overwrites) {
2883
+ this._cache.clear();
2884
+ for (const entry of overwrites ?? []) {
2885
+ this._cache.set(entry.id, new PermissionOverwrite(entry));
2886
+ }
2887
+ }
2888
+ };
2889
+
2166
2890
  // src/Domain/Channel/Guild.ts
2167
2891
  var GuildChannel = class extends Channel {
2168
- /** Guild ID this channel belongs to. */
2892
+ /** Guild ID this channel belongs to, or null if missing from the payload. */
2169
2893
  guildId;
2170
2894
  /** Position in the channel list. */
2171
2895
  position;
@@ -2175,11 +2899,14 @@ var GuildChannel = class extends Channel {
2175
2899
  permissionOverwrites;
2176
2900
  constructor(client, data) {
2177
2901
  super(client, data);
2178
- this.guildId = data.guild_id ?? "";
2902
+ this.guildId = data.guild_id ?? null;
2179
2903
  this.name = data.name ?? null;
2180
2904
  this.position = data.position;
2181
2905
  this.parentId = data.parent_id ?? null;
2182
- this.permissionOverwrites = data.permission_overwrites ?? [];
2906
+ this.permissionOverwrites = new PermissionOverwriteManager(
2907
+ this,
2908
+ data.permission_overwrites ?? []
2909
+ );
2183
2910
  }
2184
2911
  /**
2185
2912
  * Apply guild-channel fields in place.
@@ -2191,13 +2918,13 @@ var GuildChannel = class extends Channel {
2191
2918
  if (data.position !== void 0) this.position = data.position;
2192
2919
  if (data.parent_id !== void 0) this.parentId = data.parent_id ?? null;
2193
2920
  if (data.permission_overwrites !== void 0) {
2194
- this.permissionOverwrites = data.permission_overwrites ?? [];
2921
+ this.permissionOverwrites._patch(data.permission_overwrites ?? []);
2195
2922
  }
2196
2923
  this.applyEditPatch(data);
2197
2924
  }
2198
2925
  /** Create a webhook for this channel. Requires Manage Webhooks. */
2199
2926
  async createWebhook(options) {
2200
- const data = await this.client.rest.post(Routes12.channelWebhooks(this.id), {
2927
+ const data = await this.client.rest.post(Routes13.channelWebhooks(this.id), {
2201
2928
  body: options,
2202
2929
  auth: true
2203
2930
  });
@@ -2205,13 +2932,13 @@ var GuildChannel = class extends Channel {
2205
2932
  }
2206
2933
  /** Fetch all webhooks in this channel. Requires Manage Webhooks. */
2207
2934
  async fetchWebhooks() {
2208
- const data = await this.client.rest.get(Routes12.channelWebhooks(this.id));
2935
+ const data = await this.client.rest.get(Routes13.channelWebhooks(this.id));
2209
2936
  return data.map((w) => new Webhook(this.client, w));
2210
2937
  }
2211
2938
  /** Create an invite for this channel. Requires Create Instant Invite. */
2212
2939
  async createInvite(options) {
2213
2940
  const body = options ? toChannelInviteBody(options) : {};
2214
- const data = await this.client.rest.post(Routes12.channelInvites(this.id), {
2941
+ const data = await this.client.rest.post(Routes13.channelInvites(this.id), {
2215
2942
  body: Object.keys(body).length ? body : void 0,
2216
2943
  auth: true
2217
2944
  });
@@ -2219,109 +2946,160 @@ var GuildChannel = class extends Channel {
2219
2946
  }
2220
2947
  /** Fetch all invites for this channel. Requires Manage Channels. */
2221
2948
  async fetchInvites() {
2222
- const data = await this.client.rest.get(Routes12.channelInvites(this.id));
2949
+ const data = await this.client.rest.get(Routes13.channelInvites(this.id));
2223
2950
  return data.map((i) => new Invite(this.client, i));
2224
2951
  }
2225
- /** Edit or create a permission overwrite. Requires Manage Roles. */
2226
- async editPermission(overwriteId, options) {
2227
- await this.client.rest.put(Routes12.channelPermission(this.id, overwriteId), {
2228
- body: options,
2229
- auth: true
2230
- });
2231
- const entry = {
2232
- id: overwriteId,
2233
- type: options.type,
2234
- allow: options.allow ?? "0",
2235
- deny: options.deny ?? "0"
2236
- };
2237
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2238
- if (idx >= 0) this.permissionOverwrites[idx] = entry;
2239
- else this.permissionOverwrites.push(entry);
2240
- }
2241
- /** Delete a permission overwrite. Requires Manage Roles. */
2242
- async deletePermission(overwriteId) {
2243
- await this.client.rest.delete(Routes12.channelPermission(this.id, overwriteId), { auth: true });
2244
- const idx = this.permissionOverwrites.findIndex((o) => o.id === overwriteId);
2245
- if (idx >= 0) this.permissionOverwrites.splice(idx, 1);
2246
- }
2247
- /** Check if the bot can send messages in this channel (with permissions). */
2952
+ /** Check if the bot can send messages in this channel (cache-only; needs `members.me`). */
2248
2953
  canSendMessage() {
2954
+ if (!this.guildId) return false;
2249
2955
  const me = this.client.guilds.get(this.guildId)?.members.me;
2250
2956
  if (!me) return false;
2251
2957
  const perms = me.permissionsIn(this);
2252
2958
  return perms.has(PermissionFlags.ViewChannel) && perms.has(PermissionFlags.SendMessages);
2253
2959
  }
2960
+ /**
2961
+ * Like {@link canSendMessage}, but hydrates `members.me` via REST when missing.
2962
+ * Returns false when the channel has no guildId.
2963
+ */
2964
+ async canSend() {
2965
+ if (!this.guildId) return false;
2966
+ const guild = this.client.guilds.get(this.guildId);
2967
+ if (!guild) return false;
2968
+ if (!guild.members.me) {
2969
+ try {
2970
+ await guild.members.fetchMe();
2971
+ } catch {
2972
+ return false;
2973
+ }
2974
+ }
2975
+ return this.canSendMessage();
2976
+ }
2254
2977
  /** Edit this channel's settings. Requires Manage Channels. */
2255
2978
  async edit(options) {
2256
- const data = await this.client.rest.patch(Routes12.channel(this.id), {
2979
+ const data = await this.client.rest.patch(Routes13.channel(this.id), {
2257
2980
  body: toChannelEditBody(options),
2258
2981
  auth: true
2259
2982
  });
2260
2983
  this.name = data.name ?? this.name;
2261
2984
  this.parentId = data.parent_id ?? this.parentId;
2262
- this.permissionOverwrites = data.permission_overwrites ?? this.permissionOverwrites;
2985
+ if (data.permission_overwrites !== void 0) {
2986
+ this.permissionOverwrites._patch(data.permission_overwrites);
2987
+ }
2263
2988
  this.applyEditPatch(data);
2264
2989
  return this;
2265
2990
  }
2266
2991
  applyEditPatch(_data) {
2267
2992
  }
2268
- /** Delete this channel. Requires Manage Channels or channel ownership. */
2269
- async delete(options) {
2270
- const params = new URLSearchParams();
2271
- if (options?.silent) params.set("silent", "true");
2272
- if (options?.deleteMessages) params.set("delete_messages", "true");
2273
- const qs2 = params.toString();
2274
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2275
- const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2276
- await this.client.rest.delete(Routes12.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2277
- body,
2278
- auth: true
2279
- });
2280
- this.client.channels.delete(this.id);
2281
- this.client._clearMessageCache(this.id);
2282
- this.client.guilds.get(this.guildId)?.channels.delete(this.id);
2283
- }
2284
2993
  };
2285
2994
  var TextChannel = class extends TextCapable(GuildChannel) {
2286
2995
  /** Channel topic. */
2287
2996
  topic;
2288
2997
  /** Whether this channel is marked as NSFW. */
2289
2998
  nsfw;
2999
+ /** Per-channel NSFW override (`null` inherits). */
3000
+ nsfwOverride;
2290
3001
  /** Slowmode rate limit in seconds. */
2291
3002
  rateLimitPerUser;
2292
3003
  /** ID of the last message sent in this channel. */
2293
3004
  lastMessageId;
3005
+ /** Content warning level. */
3006
+ contentWarningLevel;
3007
+ /** Custom content warning text. */
3008
+ contentWarningText;
2294
3009
  constructor(client, data) {
2295
3010
  super(client, data);
2296
3011
  this.topic = data.topic ?? null;
2297
3012
  this.nsfw = data.nsfw ?? false;
3013
+ this.nsfwOverride = data.nsfw_override ?? null;
2298
3014
  this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
2299
3015
  this.lastMessageId = data.last_message_id ?? null;
3016
+ this.contentWarningLevel = data.content_warning_level ?? null;
3017
+ this.contentWarningText = data.content_warning_text ?? null;
3018
+ }
3019
+ /**
3020
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3021
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3022
+ */
3023
+ async setSlowmode(seconds) {
3024
+ return this.edit({ rateLimitPerUser: seconds });
2300
3025
  }
2301
3026
  applyEditPatch(data) {
2302
3027
  if ("topic" in data) this.topic = data.topic ?? null;
2303
3028
  if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3029
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
2304
3030
  if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3031
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3032
+ if ("content_warning_level" in data) {
3033
+ this.contentWarningLevel = data.content_warning_level ?? null;
3034
+ }
3035
+ if ("content_warning_text" in data) {
3036
+ this.contentWarningText = data.content_warning_text ?? null;
3037
+ }
2305
3038
  }
2306
3039
  };
2307
3040
  var CategoryChannel = class extends GuildChannel {
2308
3041
  };
2309
- var VoiceChannel = class extends GuildChannel {
3042
+ var VoiceChannel = class extends TextCapable(GuildChannel) {
3043
+ /** Channel topic. */
3044
+ topic;
3045
+ /** Whether this channel is marked as NSFW. */
3046
+ nsfw;
3047
+ /** Per-channel NSFW override (`null` inherits). */
3048
+ nsfwOverride;
3049
+ /** Slowmode rate limit in seconds. */
3050
+ rateLimitPerUser;
3051
+ /** ID of the last message sent in this channel. */
3052
+ lastMessageId;
3053
+ /** Content warning level. */
3054
+ contentWarningLevel;
3055
+ /** Custom content warning text. */
3056
+ contentWarningText;
2310
3057
  /** Voice bitrate. */
2311
3058
  bitrate;
2312
3059
  /** Maximum number of users allowed. */
2313
3060
  userLimit;
3061
+ /** Max active voice connections per user. */
3062
+ voiceConnectionLimit;
2314
3063
  /** RTC region override for this channel. */
2315
3064
  rtcRegion;
2316
3065
  constructor(client, data) {
2317
3066
  super(client, data);
3067
+ this.topic = data.topic ?? null;
3068
+ this.nsfw = data.nsfw ?? false;
3069
+ this.nsfwOverride = data.nsfw_override ?? null;
3070
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3071
+ this.lastMessageId = data.last_message_id ?? null;
3072
+ this.contentWarningLevel = data.content_warning_level ?? null;
3073
+ this.contentWarningText = data.content_warning_text ?? null;
2318
3074
  this.bitrate = data.bitrate ?? null;
2319
3075
  this.userLimit = data.user_limit ?? null;
3076
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
2320
3077
  this.rtcRegion = data.rtc_region ?? null;
2321
3078
  }
3079
+ /**
3080
+ * Set slowmode (seconds between messages). Pass `0` to disable.
3081
+ * Requires Manage Channels. Calls {@link GuildChannel.edit} with `rateLimitPerUser`.
3082
+ */
3083
+ async setSlowmode(seconds) {
3084
+ return this.edit({ rateLimitPerUser: seconds });
3085
+ }
2322
3086
  applyEditPatch(data) {
3087
+ if ("topic" in data) this.topic = data.topic ?? null;
3088
+ if ("nsfw" in data) this.nsfw = data.nsfw ?? false;
3089
+ if ("nsfw_override" in data) this.nsfwOverride = data.nsfw_override ?? null;
3090
+ if ("rate_limit_per_user" in data) this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
3091
+ if ("last_message_id" in data) this.lastMessageId = data.last_message_id ?? null;
3092
+ if ("content_warning_level" in data) {
3093
+ this.contentWarningLevel = data.content_warning_level ?? null;
3094
+ }
3095
+ if ("content_warning_text" in data) {
3096
+ this.contentWarningText = data.content_warning_text ?? null;
3097
+ }
2323
3098
  if ("bitrate" in data) this.bitrate = data.bitrate ?? null;
2324
3099
  if ("user_limit" in data) this.userLimit = data.user_limit ?? null;
3100
+ if ("voice_connection_limit" in data) {
3101
+ this.voiceConnectionLimit = data.voice_connection_limit ?? null;
3102
+ }
2325
3103
  if ("rtc_region" in data) this.rtcRegion = data.rtc_region ?? null;
2326
3104
  }
2327
3105
  };
@@ -2332,6 +3110,9 @@ var LinkChannel = class extends GuildChannel {
2332
3110
  super(client, data);
2333
3111
  this.url = data.url ?? null;
2334
3112
  }
3113
+ applyEditPatch(data) {
3114
+ if ("url" in data) this.url = data.url ?? null;
3115
+ }
2335
3116
  };
2336
3117
 
2337
3118
  // src/Domain/Channel/Factory.ts
@@ -2447,11 +3228,11 @@ var User = class extends Base {
2447
3228
  */
2448
3229
  /** Unix timestamp (ms) when this account was created, derived from its snowflake ID. */
2449
3230
  get createdTimestamp() {
2450
- return SnowflakeUtil3.timestampFromSnowflake(this.id);
3231
+ return SnowflakeUtil5.timestampFromSnowflake(this.id);
2451
3232
  }
2452
3233
  /** Date when this account was created, derived from its snowflake ID. */
2453
3234
  get createdAt() {
2454
- return SnowflakeUtil3.dateFromSnowflake(this.id);
3235
+ return SnowflakeUtil5.dateFromSnowflake(this.id);
2455
3236
  }
2456
3237
  toString() {
2457
3238
  return `<@${this.id}>`;
@@ -2461,7 +3242,7 @@ var User = class extends Base {
2461
3242
  * @returns DM channel instance (cached if already open)
2462
3243
  */
2463
3244
  async createDM() {
2464
- const data = await this.client.rest.post(Routes13.userMeChannels(), {
3245
+ const data = await this.client.rest.post(Routes14.userMeChannels(), {
2465
3246
  body: { recipient_id: this.id },
2466
3247
  auth: true
2467
3248
  });
@@ -2576,6 +3357,9 @@ var CacheController = class {
2576
3357
  stickers
2577
3358
  };
2578
3359
  }
3360
+ /**
3361
+ * Sweep cached messages. Filter receives a hydrated {@link Message} (`createdAt`).
3362
+ */
2579
3363
  sweepMessages(filter, channelId) {
2580
3364
  return this.client.sweepMessages(filter, channelId);
2581
3365
  }
@@ -2644,7 +3428,7 @@ var CacheController = class {
2644
3428
  * @internal
2645
3429
  */
2646
3430
  cascadeChannel(channel, from = "both") {
2647
- const guildId = "guildId" in channel && typeof channel.guildId === "string" ? channel.guildId : void 0;
3431
+ const guildId = typeof channel.isGuild === "function" && channel.isGuild() ? channel.guildId : void 0;
2648
3432
  const dropFromGuild = () => {
2649
3433
  if (!guildId) return;
2650
3434
  const guildChannels = this.client.guilds.get(guildId)?.channels;
@@ -2675,11 +3459,11 @@ var CacheController = class {
2675
3459
 
2676
3460
  // src/ClientCore/ChannelManager.ts
2677
3461
  import { LimitedCollection } from "@fluxerjs/collection";
2678
- import { Routes as Routes19 } from "@fluxerjs/types";
3462
+ import { Routes as Routes20 } from "@fluxerjs/types";
2679
3463
 
2680
3464
  // src/Domain/Guild/GuildEmoji.ts
2681
- import { Routes as Routes14 } from "@fluxerjs/types";
2682
- import { SnowflakeUtil as SnowflakeUtil4 } from "@fluxerjs/util";
3465
+ import { Routes as Routes15 } from "@fluxerjs/types";
3466
+ import { SnowflakeUtil as SnowflakeUtil6 } from "@fluxerjs/util";
2683
3467
  var GuildEmoji = class extends Base {
2684
3468
  client;
2685
3469
  id;
@@ -2715,11 +3499,11 @@ var GuildEmoji = class extends Base {
2715
3499
  }
2716
3500
  /** Unix timestamp (ms) when this emoji was created, derived from its snowflake ID. */
2717
3501
  get createdTimestamp() {
2718
- return SnowflakeUtil4.timestampFromSnowflake(this.id);
3502
+ return SnowflakeUtil6.timestampFromSnowflake(this.id);
2719
3503
  }
2720
3504
  /** Date when this emoji was created, derived from its snowflake ID. */
2721
3505
  get createdAt() {
2722
- return SnowflakeUtil4.dateFromSnowflake(this.id);
3506
+ return SnowflakeUtil6.dateFromSnowflake(this.id);
2723
3507
  }
2724
3508
  /** Renders this emoji for use in message content: `<:name:id>` (or `<a:name:id>` when animated). */
2725
3509
  toString() {
@@ -2727,7 +3511,7 @@ var GuildEmoji = class extends Base {
2727
3511
  }
2728
3512
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
2729
3513
  async delete() {
2730
- await this.client.rest.delete(Routes14.guildEmoji(this.guildId, this.id), {
3514
+ await this.client.rest.delete(Routes15.guildEmoji(this.guildId, this.id), {
2731
3515
  auth: true
2732
3516
  });
2733
3517
  const guild = this.client.guilds.get(this.guildId);
@@ -2738,7 +3522,7 @@ var GuildEmoji = class extends Base {
2738
3522
  * Requires Manage Emojis and Stickers permission.
2739
3523
  */
2740
3524
  async edit(options) {
2741
- const data = await this.client.rest.patch(Routes14.guildEmoji(this.guildId, this.id), {
3525
+ const data = await this.client.rest.patch(Routes15.guildEmoji(this.guildId, this.id), {
2742
3526
  body: options,
2743
3527
  auth: true
2744
3528
  });
@@ -2748,8 +3532,8 @@ var GuildEmoji = class extends Base {
2748
3532
  };
2749
3533
 
2750
3534
  // src/Domain/Guild/GuildMember.ts
2751
- import { Routes as Routes16 } from "@fluxerjs/types";
2752
- import { PermissionsBitField } from "@fluxerjs/util";
3535
+ import { Routes as Routes17 } from "@fluxerjs/types";
3536
+ import { PermissionFlags as PermissionFlags3, PermissionsBitField as PermissionsBitField2 } from "@fluxerjs/util";
2753
3537
 
2754
3538
  // src/Helpers/Permissions.ts
2755
3539
  import { OverwriteType } from "@fluxerjs/types";
@@ -2768,8 +3552,8 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
2768
3552
  }
2769
3553
 
2770
3554
  // src/Domain/Guild/GuildMemberRoleManager.ts
2771
- import { Collection as Collection5 } from "@fluxerjs/collection";
2772
- import { Routes as Routes15 } from "@fluxerjs/types";
3555
+ import { Collection as Collection7 } from "@fluxerjs/collection";
3556
+ import { Routes as Routes16 } from "@fluxerjs/types";
2773
3557
  function roleId(roleOrId) {
2774
3558
  return typeof roleOrId === "string" ? roleOrId : roleOrId.id;
2775
3559
  }
@@ -2787,7 +3571,7 @@ var GuildMemberRoleManager = class {
2787
3571
  }
2788
3572
  /** Live Role objects from `guild.roles` for this member's role IDs. */
2789
3573
  get cache() {
2790
- const out = new Collection5();
3574
+ const out = new Collection7();
2791
3575
  for (const id of this.ids) {
2792
3576
  const role = this.member.guild.roles.get(id);
2793
3577
  if (role) out.set(id, role);
@@ -2798,7 +3582,7 @@ var GuildMemberRoleManager = class {
2798
3582
  const id = roleId(roleOrId);
2799
3583
  if (this.ids.includes(id)) return;
2800
3584
  await this.member.client.rest.put(
2801
- Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
3585
+ Routes16.guildMemberRole(this.member.guild.id, this.member.id, id)
2802
3586
  );
2803
3587
  this.ids.push(id);
2804
3588
  }
@@ -2807,13 +3591,13 @@ var GuildMemberRoleManager = class {
2807
3591
  const idx = this.ids.indexOf(id);
2808
3592
  if (idx === -1) return;
2809
3593
  await this.member.client.rest.delete(
2810
- Routes15.guildMemberRole(this.member.guild.id, this.member.id, id)
3594
+ Routes16.guildMemberRole(this.member.guild.id, this.member.id, id)
2811
3595
  );
2812
3596
  this.ids.splice(idx, 1);
2813
3597
  }
2814
3598
  async set(roleIds) {
2815
3599
  const data = await this.member.client.rest.patch(
2816
- Routes15.guildMember(this.member.guild.id, this.member.id),
3600
+ Routes16.guildMember(this.member.guild.id, this.member.id),
2817
3601
  { body: { roles: roleIds }, auth: true }
2818
3602
  );
2819
3603
  this.ids = data.roles ? [...data.roles] : [];
@@ -2826,6 +3610,8 @@ var GuildMemberRoleManager = class {
2826
3610
 
2827
3611
  // src/Domain/Guild/GuildMember.ts
2828
3612
  var GuildMember = class _GuildMember extends Base {
3613
+ /** Discriminant vs {@link PartialGuildMember}: always `false` on a hydrated member. */
3614
+ partial = false;
2829
3615
  /** Parent client instance. */
2830
3616
  client;
2831
3617
  /** User ID (same as `user.id`). */
@@ -2854,6 +3640,12 @@ var GuildMember = class _GuildMember extends Base {
2854
3640
  accentColor;
2855
3641
  /** Guild-specific profile flags. */
2856
3642
  profileFlags;
3643
+ /** Per-guild reply mention preference override. */
3644
+ mentionFlags;
3645
+ /** Guild-specific bio (set from member edit; not always on GET member). */
3646
+ bio;
3647
+ /** Guild-specific pronouns (set from member edit; not always on GET member). */
3648
+ pronouns;
2857
3649
  constructor(client, data, guild) {
2858
3650
  super();
2859
3651
  this.client = client;
@@ -2870,6 +3662,9 @@ var GuildMember = class _GuildMember extends Base {
2870
3662
  this.banner = data.banner ?? null;
2871
3663
  this.accentColor = data.accent_color ?? null;
2872
3664
  this.profileFlags = data.profile_flags ?? null;
3665
+ this.mentionFlags = data.mention_flags ?? null;
3666
+ this.bio = data.bio ?? null;
3667
+ this.pronouns = data.pronouns ?? null;
2873
3668
  }
2874
3669
  /**
2875
3670
  * Apply an API member payload in place (gateway GUILD_MEMBER_UPDATE / REST edit).
@@ -2888,6 +3683,9 @@ var GuildMember = class _GuildMember extends Base {
2888
3683
  if (data.banner !== void 0) this.banner = data.banner ?? null;
2889
3684
  if (data.accent_color !== void 0) this.accentColor = data.accent_color ?? null;
2890
3685
  if (data.profile_flags !== void 0) this.profileFlags = data.profile_flags ?? null;
3686
+ if (data.mention_flags !== void 0) this.mentionFlags = data.mention_flags ?? null;
3687
+ if (data.bio !== void 0) this.bio = data.bio ?? null;
3688
+ if (data.pronouns !== void 0) this.pronouns = data.pronouns ?? null;
2891
3689
  }
2892
3690
  /**
2893
3691
  * Snapshot for `guildMemberUpdate` old-member arg (before in-place patch).
@@ -2916,7 +3714,10 @@ var GuildMember = class _GuildMember extends Base {
2916
3714
  avatar: this.avatar,
2917
3715
  banner: this.banner,
2918
3716
  accent_color: this.accentColor,
2919
- profile_flags: this.profileFlags ?? void 0
3717
+ profile_flags: this.profileFlags ?? void 0,
3718
+ mention_flags: this.mentionFlags,
3719
+ bio: this.bio,
3720
+ pronouns: this.pronouns
2920
3721
  },
2921
3722
  this.guild
2922
3723
  );
@@ -2943,15 +3744,22 @@ var GuildMember = class _GuildMember extends Base {
2943
3744
  mediaBase: this.client.instance.endpoints.media
2944
3745
  });
2945
3746
  }
2946
- /** PATCH member (`/members/@me` when editing the bot). */
3747
+ /**
3748
+ * PATCH member (`/members/@me` when editing the bot).
3749
+ * @example
3750
+ * await member.edit({ nick: 'Ada' });
3751
+ */
2947
3752
  async edit(options) {
2948
3753
  const isMe = this.client.user?.id === this.id;
2949
- const route = isMe ? Routes16.guildMemberMe(this.guild.id) : Routes16.guildMember(this.guild.id, this.id);
3754
+ const route = isMe ? Routes17.guildMemberMe(this.guild.id) : Routes17.guildMember(this.guild.id, this.id);
2950
3755
  const data = await this.client.rest.patch(route, {
2951
3756
  body: toMemberEditBody(options),
2952
3757
  auth: true
2953
3758
  });
2954
3759
  this._patch(data);
3760
+ if (options.bio !== void 0) this.bio = options.bio;
3761
+ if (options.pronouns !== void 0) this.pronouns = options.pronouns;
3762
+ if (options.mentionFlags !== void 0) this.mentionFlags = options.mentionFlags;
2955
3763
  return this;
2956
3764
  }
2957
3765
  /**
@@ -2959,7 +3767,7 @@ var GuildMember = class _GuildMember extends Base {
2959
3767
  * @see {@link permissionsIn} for channel-specific permissions
2960
3768
  */
2961
3769
  get permissions() {
2962
- return new PermissionsBitField(this._effectivePermissions([], []));
3770
+ return new PermissionsBitField2(this._effectivePermissions([], []));
2963
3771
  }
2964
3772
  /**
2965
3773
  * Effective permissions in a channel (roles + overwrites).
@@ -2967,8 +3775,8 @@ var GuildMember = class _GuildMember extends Base {
2967
3775
  * @returns Computed permissions bitfield
2968
3776
  */
2969
3777
  permissionsIn(channel) {
2970
- return new PermissionsBitField(
2971
- this._effectivePermissions(channel.permissionOverwrites, [...this.roles.roleIds])
3778
+ return new PermissionsBitField2(
3779
+ this._effectivePermissions(channel.permissionOverwrites.toJSON(), [...this.roles.roleIds])
2972
3780
  );
2973
3781
  }
2974
3782
  /**
@@ -2979,6 +3787,63 @@ var GuildMember = class _GuildMember extends Base {
2979
3787
  async move(channelId, connectionId) {
2980
3788
  await this.edit({ channelId, connectionId });
2981
3789
  }
3790
+ /** Kick this member. Requires Kick Members. */
3791
+ async kick() {
3792
+ await this.guild.kick(this.id);
3793
+ }
3794
+ /** Ban this member. Requires Ban Members. */
3795
+ async ban(options) {
3796
+ await this.guild.ban(this.id, options);
3797
+ }
3798
+ /**
3799
+ * Whether the bot can kick this member (cache-only; needs `members.me`).
3800
+ * False for the guild owner, self, or when the bot lacks Kick Members / role hierarchy.
3801
+ */
3802
+ get kickable() {
3803
+ return this._moderatableWith(PermissionFlags3.KickMembers);
3804
+ }
3805
+ /**
3806
+ * Whether the bot can ban this member (cache-only; needs `members.me`).
3807
+ */
3808
+ get bannable() {
3809
+ return this._moderatableWith(PermissionFlags3.BanMembers);
3810
+ }
3811
+ /**
3812
+ * Whether the bot can timeout this member (cache-only; needs `members.me`).
3813
+ */
3814
+ get moderatable() {
3815
+ return this._moderatableWith(PermissionFlags3.ModerateMembers);
3816
+ }
3817
+ _moderatableWith(flag) {
3818
+ const me = this.guild.members.me;
3819
+ if (!me) return false;
3820
+ if (this.id === me.id) return false;
3821
+ if (this.guild.ownerId != null && String(this.guild.ownerId) === String(this.id)) return false;
3822
+ if (!me.permissions.has(flag)) return false;
3823
+ return this._compareRolePosition(me) < 0;
3824
+ }
3825
+ /** Negative when this member's highest role is below `other`'s. */
3826
+ _compareRolePosition(other) {
3827
+ const highest = (m) => {
3828
+ let pos = -1;
3829
+ for (const role of m.roles.cache.values()) {
3830
+ if (role.position > pos) pos = role.position;
3831
+ }
3832
+ return pos;
3833
+ };
3834
+ return highest(this) - highest(other);
3835
+ }
3836
+ /**
3837
+ * Timeout this member for `durationMs` milliseconds, or pass `null` to clear.
3838
+ * Requires Moderate Members.
3839
+ */
3840
+ async timeout(durationMs, reason) {
3841
+ const communicationDisabledUntil = durationMs == null || durationMs <= 0 ? null : new Date(Date.now() + durationMs).toISOString();
3842
+ return this.edit({
3843
+ communicationDisabledUntil,
3844
+ ...reason !== void 0 ? { timeoutReason: reason } : {}
3845
+ });
3846
+ }
2982
3847
  _effectivePermissions(overwrites, roleIds) {
2983
3848
  const ownerId = this.guild.ownerId;
2984
3849
  const isOwner = ownerId != null && ownerId !== "" && String(ownerId) === String(this.id);
@@ -2998,8 +3863,8 @@ var GuildMember = class _GuildMember extends Base {
2998
3863
  };
2999
3864
 
3000
3865
  // src/Domain/Guild/GuildSticker.ts
3001
- import { Routes as Routes17 } from "@fluxerjs/types";
3002
- import { SnowflakeUtil as SnowflakeUtil5 } from "@fluxerjs/util";
3866
+ import { Routes as Routes18 } from "@fluxerjs/types";
3867
+ import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
3003
3868
  var GuildSticker = class extends Base {
3004
3869
  client;
3005
3870
  id;
@@ -3041,15 +3906,15 @@ var GuildSticker = class extends Base {
3041
3906
  }
3042
3907
  /** Unix timestamp (ms) when this sticker was created, derived from its snowflake ID. */
3043
3908
  get createdTimestamp() {
3044
- return SnowflakeUtil5.timestampFromSnowflake(this.id);
3909
+ return SnowflakeUtil7.timestampFromSnowflake(this.id);
3045
3910
  }
3046
3911
  /** Date when this sticker was created, derived from its snowflake ID. */
3047
3912
  get createdAt() {
3048
- return SnowflakeUtil5.dateFromSnowflake(this.id);
3913
+ return SnowflakeUtil7.dateFromSnowflake(this.id);
3049
3914
  }
3050
3915
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3051
3916
  async delete() {
3052
- await this.client.rest.delete(Routes17.guildSticker(this.guildId, this.id), {
3917
+ await this.client.rest.delete(Routes18.guildSticker(this.guildId, this.id), {
3053
3918
  auth: true
3054
3919
  });
3055
3920
  const guild = this.client.guilds.get(this.guildId);
@@ -3060,7 +3925,7 @@ var GuildSticker = class extends Base {
3060
3925
  * Requires Manage Emojis and Stickers permission.
3061
3926
  */
3062
3927
  async edit(options) {
3063
- const data = await this.client.rest.patch(Routes17.guildSticker(this.guildId, this.id), {
3928
+ const data = await this.client.rest.patch(Routes18.guildSticker(this.guildId, this.id), {
3064
3929
  body: options,
3065
3930
  auth: true
3066
3931
  });
@@ -3072,12 +3937,12 @@ var GuildSticker = class extends Base {
3072
3937
  };
3073
3938
 
3074
3939
  // src/Domain/Guild/Role.ts
3075
- import { Routes as Routes18 } from "@fluxerjs/types";
3940
+ import { Routes as Routes19 } from "@fluxerjs/types";
3076
3941
  import {
3077
3942
  ALL_PERMISSIONS_BIGINT as ALL_PERMISSIONS_BIGINT2,
3078
- PermissionFlags as PermissionFlags3,
3079
- PermissionsBitField as PermissionsBitField2,
3080
- SnowflakeUtil as SnowflakeUtil6
3943
+ PermissionFlags as PermissionFlags4,
3944
+ PermissionsBitField as PermissionsBitField3,
3945
+ SnowflakeUtil as SnowflakeUtil8
3081
3946
  } from "@fluxerjs/util";
3082
3947
  var Role = class _Role extends Base {
3083
3948
  /** Parent client instance. */
@@ -3121,21 +3986,29 @@ var Role = class _Role extends Base {
3121
3986
  */
3122
3987
  get permissions() {
3123
3988
  const bits = BigInt(this._permissions);
3124
- return new PermissionsBitField2(
3125
- (bits & PermissionFlags3.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
3989
+ return new PermissionsBitField3(
3990
+ (bits & PermissionFlags4.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT2 : bits
3126
3991
  );
3127
3992
  }
3993
+ /**
3994
+ * Alias of {@link permissions}.has for discord.js-style checks.
3995
+ * @example
3996
+ * if (role.has(PermissionFlags.BanMembers)) { ... }
3997
+ */
3998
+ has(permission) {
3999
+ return this.permissions.has(permission);
4000
+ }
3128
4001
  /**
3129
4002
  * Format as a mention string (`<@&id>`).
3130
4003
  * @returns Mention syntax
3131
4004
  */
3132
4005
  /** Unix timestamp (ms) when this role was created, derived from its snowflake ID. */
3133
4006
  get createdTimestamp() {
3134
- return SnowflakeUtil6.timestampFromSnowflake(this.id);
4007
+ return SnowflakeUtil8.timestampFromSnowflake(this.id);
3135
4008
  }
3136
4009
  /** Date when this role was created, derived from its snowflake ID. */
3137
4010
  get createdAt() {
3138
- return SnowflakeUtil6.dateFromSnowflake(this.id);
4011
+ return SnowflakeUtil8.dateFromSnowflake(this.id);
3139
4012
  }
3140
4013
  toString() {
3141
4014
  return `<@&${this.id}>`;
@@ -3178,8 +4051,8 @@ var Role = class _Role extends Base {
3178
4051
  * @returns This role instance (updated in-place)
3179
4052
  */
3180
4053
  async edit(options) {
3181
- const body = toRoleRequestBody(options);
3182
- const data = await this.client.rest.patch(Routes18.guildRole(this.guildId, this.id), {
4054
+ const body = toRoleEditBody(options);
4055
+ const data = await this.client.rest.patch(Routes19.guildRole(this.guildId, this.id), {
3183
4056
  body: Object.keys(body).length ? body : void 0,
3184
4057
  auth: true
3185
4058
  });
@@ -3190,7 +4063,7 @@ var Role = class _Role extends Base {
3190
4063
  * DELETE role. Requires Manage Roles.
3191
4064
  */
3192
4065
  async delete() {
3193
- await this.client.rest.delete(Routes18.guildRole(this.guildId, this.id), { auth: true });
4066
+ await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), { auth: true });
3194
4067
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
3195
4068
  }
3196
4069
  };
@@ -3198,17 +4071,15 @@ var Role = class _Role extends Base {
3198
4071
  // src/Domain/Guild/Cache.ts
3199
4072
  function putChannel(client, channel, guild) {
3200
4073
  client.channels.set(channel.id, channel);
3201
- const resolvedGuild = guild ?? (() => {
3202
- const guildId = "guildId" in channel ? channel.guildId : void 0;
3203
- return guildId ? client.guilds.get(guildId) : void 0;
3204
- })();
4074
+ if (!channel.isGuild()) return;
4075
+ const resolvedGuild = guild ?? (channel.guildId ? client.guilds.get(channel.guildId) : void 0);
3205
4076
  if (resolvedGuild) {
3206
4077
  resolvedGuild.channels.set(channel.id, channel);
3207
4078
  }
3208
4079
  }
3209
4080
  function cacheChannel(guild, data) {
3210
4081
  const existing = guild.channels.get(data.id) ?? guild.client.channels.get(data.id);
3211
- if (existing && "guildId" in existing && existing.type === data.type) {
4082
+ if (existing?.isGuild() && existing.type === data.type) {
3212
4083
  existing._patch(data);
3213
4084
  putChannel(guild.client, existing, guild);
3214
4085
  return existing;
@@ -3322,6 +4193,10 @@ var ChannelManager = class extends LimitedCollection {
3322
4193
  });
3323
4194
  this.client = client;
3324
4195
  }
4196
+ /**
4197
+ * Remove a channel from cache. Does not delete it on the API.
4198
+ * Use {@link Channel.delete} after {@link fetch} to delete the channel.
4199
+ */
3325
4200
  delete(key) {
3326
4201
  const channel = this.get(key);
3327
4202
  const deleted = super.delete(key);
@@ -3335,15 +4210,20 @@ var ChannelManager = class extends LimitedCollection {
3335
4210
  return this.get(channelId) ?? this.fetch(channelId);
3336
4211
  }
3337
4212
  /**
3338
- * Fetch a channel by ID.
3339
- * Returns the cached channel unless `force` is set, in which case REST metadata is applied.
4213
+ * Fetch a channel by ID. The returned {@link Channel} has {@link Channel.delete}
4214
+ * and {@link Channel.send} (send throws if the type is not text-based).
4215
+ * Returns the cached channel unless `force` is set.
4216
+ * @example
4217
+ * const channel = await client.channels.fetch(channelId);
4218
+ * await channel.delete();
4219
+ * await channel.send('hi');
3340
4220
  * @throws {@link FluxerError} with CHANNEL_NOT_FOUND if missing
3341
4221
  */
3342
4222
  async fetch(channelId, options) {
3343
4223
  const cached = this.get(channelId);
3344
4224
  if (cached && !options?.force) return cached;
3345
4225
  try {
3346
- const data = await this.client.rest.get(Routes19.channel(channelId));
4226
+ const data = await this.client.rest.get(Routes20.channel(channelId));
3347
4227
  const guildId = "guild_id" in data ? data.guild_id : void 0;
3348
4228
  if (guildId) {
3349
4229
  const guild = this.client.guilds.get(guildId);
@@ -3379,6 +4259,7 @@ var ChannelManager = class extends LimitedCollection {
3379
4259
  }
3380
4260
  /**
3381
4261
  * Send to a channel by ID without resolving it first.
4262
+ * Prefer {@link Channel.send} after {@link fetch} when you want the channel object.
3382
4263
  * @example
3383
4264
  * await client.channels.send(logChannelId, 'User joined!');
3384
4265
  */
@@ -3387,7 +4268,7 @@ var ChannelManager = class extends LimitedCollection {
3387
4268
  defaultAllowedMentions: this.client.options.defaultAllowedMentions
3388
4269
  });
3389
4270
  const data = await this.client.rest.post(
3390
- Routes19.channelMessages(channelId),
4271
+ Routes20.channelMessages(channelId),
3391
4272
  postPayload
3392
4273
  );
3393
4274
  this.client._addMessageToCache(channelId, data);
@@ -3396,14 +4277,14 @@ var ChannelManager = class extends LimitedCollection {
3396
4277
  };
3397
4278
 
3398
4279
  // src/ClientCore/ClientEmoji.ts
3399
- import { Collection as Collection6 } from "@fluxerjs/collection";
3400
- import { Routes as Routes20 } from "@fluxerjs/types";
3401
- import { formatEmoji, getUnicodeFromShortcode, parseEmoji as parseEmoji2 } from "@fluxerjs/util";
4280
+ import { Collection as Collection8 } from "@fluxerjs/collection";
4281
+ import { Routes as Routes21 } from "@fluxerjs/types";
4282
+ import { formatEmoji, getUnicodeFromShortcode, parseEmoji } from "@fluxerjs/util";
3402
4283
  async function resolveClientEmoji(client, emoji, guildId) {
3403
4284
  if (typeof emoji === "object" && emoji.id) {
3404
4285
  return formatEmoji({ name: emoji.name, id: emoji.id, animated: emoji.animated });
3405
4286
  }
3406
- const parsed = parseEmoji2(
4287
+ const parsed = parseEmoji(
3407
4288
  typeof emoji === "string" ? emoji : emoji.id ? `:${emoji.name}:` : emoji.name
3408
4289
  );
3409
4290
  if (!parsed) {
@@ -3416,7 +4297,7 @@ async function resolveClientEmoji(client, emoji, guildId) {
3416
4297
  const unicodeFromShortcode = getUnicodeFromShortcode(parsed.name);
3417
4298
  if (unicodeFromShortcode) return unicodeFromShortcode;
3418
4299
  if (guildId) {
3419
- const emojis = await client.rest.get(Routes20.guildEmojis(guildId));
4300
+ const emojis = await client.rest.get(Routes21.guildEmojis(guildId));
3420
4301
  const found = emojis.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
3421
4302
  if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
3422
4303
  throw new FluxerError(
@@ -3433,28 +4314,31 @@ async function resolveClientEmoji(client, emoji, guildId) {
3433
4314
  return parsed.name;
3434
4315
  }
3435
4316
  async function fetchInstance(client) {
3436
- const raw = await client.rest.get(Routes20.instanceDiscovery(), { auth: false });
4317
+ const raw = await client.rest.get(Routes21.instanceDiscovery(), { auth: false });
3437
4318
  return parseInstanceDiscovery(raw);
3438
4319
  }
3439
4320
  function fetchGatewayInfo(client) {
3440
- return client.rest.get(Routes20.gatewayBot());
4321
+ return client.rest.get(Routes21.gatewayBot());
3441
4322
  }
3442
4323
  function fetchEmojiMetadata(client, emojiId) {
3443
- return client.rest.get(Routes20.emojiMetadata(emojiId), { auth: true });
4324
+ return client.rest.get(Routes21.emojiMetadata(emojiId), { auth: true });
3444
4325
  }
3445
4326
  function fetchStickerMetadata(client, stickerId) {
3446
- return client.rest.get(Routes20.stickerMetadata(stickerId), { auth: true });
4327
+ return client.rest.get(Routes21.stickerMetadata(stickerId), { auth: true });
3447
4328
  }
3448
4329
  function fetchApplication(client) {
3449
- return client.rest.get(Routes20.applicationsMe(), { auth: true });
4330
+ return client.rest.get(Routes21.applicationsMe(), { auth: true });
3450
4331
  }
3451
4332
  async function fetchOAuthApplications(client) {
3452
- const data = await client.rest.get(Routes20.oauth2ApplicationsMe(), { auth: true });
3453
- return Array.isArray(data) ? data : data.applications ?? [];
3454
- }
3455
- function checkUsernameTag(client, username, discriminator) {
3456
- const params = new URLSearchParams({ username, discriminator });
3457
- return client.rest.get(`${Routes20.checkUsernameTag()}?${params}`, { auth: true });
4333
+ const data = await client.rest.get(Routes21.oauth2ApplicationsMe(), { auth: true });
4334
+ if (Array.isArray(data)) return data;
4335
+ if (data && typeof data === "object" && "applications" in data && Array.isArray(data.applications)) {
4336
+ return data.applications;
4337
+ }
4338
+ if (data && typeof data === "object" && "id" in data && typeof data.id === "string") {
4339
+ return [data];
4340
+ }
4341
+ return [];
3458
4342
  }
3459
4343
  function assertChannelIdBatch(name, channelIds) {
3460
4344
  if (channelIds.length < 1 || channelIds.length > 100) {
@@ -3465,14 +4349,14 @@ function assertChannelIdBatch(name, channelIds) {
3465
4349
  }
3466
4350
  function preloadMessages(client, channelIds) {
3467
4351
  assertChannelIdBatch("preloadMessages", channelIds);
3468
- return client.rest.post(Routes20.preloadMessages(), {
4352
+ return client.rest.post(Routes21.preloadMessages(), {
3469
4353
  body: { channels: channelIds },
3470
4354
  auth: true
3471
4355
  });
3472
4356
  }
3473
4357
  function preloadMessagesAlt(client, channelIds) {
3474
4358
  assertChannelIdBatch("preloadMessagesAlt", channelIds);
3475
- return client.rest.post(Routes20.preloadMessagesAlt(), {
4359
+ return client.rest.post(Routes21.preloadMessagesAlt(), {
3476
4360
  body: { channels: channelIds },
3477
4361
  auth: true
3478
4362
  });
@@ -3480,14 +4364,14 @@ function preloadMessagesAlt(client, channelIds) {
3480
4364
  async function bulkFetchMessages(client, requests, options = {}) {
3481
4365
  validateBulkMessageFetchRequests(requests);
3482
4366
  const wire = toBulkFetchWire(requests);
3483
- const data = await client.rest.post(Routes20.channelsMessagesBulk(), {
4367
+ const data = await client.rest.post(Routes21.channelsMessagesBulk(), {
3484
4368
  body: { requests: wire },
3485
4369
  auth: true
3486
4370
  });
3487
4371
  if (options.hydrate === false) return data;
3488
4372
  return {
3489
4373
  channels: data.channels.map((entry) => {
3490
- const collection = new Collection6();
4374
+ const collection = new Collection8();
3491
4375
  for (const msg of entry.messages) {
3492
4376
  client._addMessageToCache(entry.channel_id, msg);
3493
4377
  collection.set(msg.id, new Message(client, msg));
@@ -3496,6 +4380,13 @@ async function bulkFetchMessages(client, requests, options = {}) {
3496
4380
  })
3497
4381
  };
3498
4382
  }
4383
+ async function searchMessages(client, options = {}) {
4384
+ const data = await client.rest.post(Routes21.searchMessages(), {
4385
+ body: toMessageSearchBody(options),
4386
+ auth: true
4387
+ });
4388
+ return toMessageSearchResponse(data);
4389
+ }
3499
4390
 
3500
4391
  // src/ClientCore/ClientEvents.ts
3501
4392
  function createEventMethods(client) {
@@ -3511,16 +4402,16 @@ function createEventMethods(client) {
3511
4402
  }
3512
4403
 
3513
4404
  // src/ClientCore/GatewayReady.ts
3514
- import { WebSocketManager } from "@fluxerjs/ws";
4405
+ import { GatewayCloseCodes, WebSocketManager } from "@fluxerjs/ws";
3515
4406
 
3516
4407
  // src/Domain/Guild/Guild.ts
3517
- import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4408
+ import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
3518
4409
  import { GuildNSFWLevel } from "@fluxerjs/types";
3519
- import { SnowflakeUtil as SnowflakeUtil7 } from "@fluxerjs/util";
4410
+ import { SnowflakeUtil as SnowflakeUtil9 } from "@fluxerjs/util";
3520
4411
 
3521
4412
  // src/ClientCore/GuildMemberManager.ts
3522
4413
  import { LimitedCollection as LimitedCollection2 } from "@fluxerjs/collection";
3523
- import { Routes as Routes21 } from "@fluxerjs/types";
4414
+ import { Routes as Routes22 } from "@fluxerjs/types";
3524
4415
  var GuildMemberManager = class extends LimitedCollection2 {
3525
4416
  constructor(guild) {
3526
4417
  super({ maxSize: guild.client.cache.limits.members });
@@ -3537,7 +4428,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
3537
4428
  * console.log(member.displayName);
3538
4429
  */
3539
4430
  async resolve(userId) {
3540
- return this.get(userId) ?? this.guild.fetchMember(userId);
4431
+ return this.get(userId) ?? this.fetch(userId);
3541
4432
  }
3542
4433
  /**
3543
4434
  * The current bot user as a GuildMember in this guild.
@@ -3564,17 +4455,20 @@ var GuildMemberManager = class extends LimitedCollection2 {
3564
4455
  async fetchMe() {
3565
4456
  return this.guild.fetchMe();
3566
4457
  }
3567
- /**
3568
- * Fetch guild members with pagination. GET /guilds/{id}/members.
3569
- * @param options - limit (1-1000), after (user ID for pagination)
3570
- * @returns Array of GuildMember objects (cached in guild.members)
3571
- */
3572
- async fetch(options) {
4458
+ async fetch(userIdOrOptions, options) {
4459
+ if (typeof userIdOrOptions === "string") {
4460
+ const cached = this.get(userIdOrOptions);
4461
+ if (cached && !options?.force) return cached;
4462
+ return this.guild.fetchMember(userIdOrOptions);
4463
+ }
4464
+ return this.fetchMany(userIdOrOptions);
4465
+ }
4466
+ async fetchMany(options) {
3573
4467
  const params = new URLSearchParams();
3574
4468
  if (options?.limit != null) params.set("limit", String(options.limit));
3575
4469
  if (options?.after) params.set("after", options.after);
3576
4470
  const qs2 = params.toString();
3577
- const url = Routes21.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
4471
+ const url = Routes22.guildMembers(this.guild.id) + (qs2 ? `?${qs2}` : "");
3578
4472
  const data = await this.guild.client.rest.get(url, { auth: true });
3579
4473
  const members = [];
3580
4474
  for (const m of data) {
@@ -3597,7 +4491,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
3597
4491
  */
3598
4492
  async search(options = {}) {
3599
4493
  const data = await this.guild.client.rest.post(
3600
- Routes21.guildMembersSearch(this.guild.id),
4494
+ Routes22.guildMembersSearch(this.guild.id),
3601
4495
  { body: toMemberSearchBody(options), auth: true }
3602
4496
  );
3603
4497
  const offset = options.offset ?? 0;
@@ -3623,7 +4517,7 @@ var GuildMemberManager = class extends LimitedCollection2 {
3623
4517
  };
3624
4518
 
3625
4519
  // src/Domain/Guild/Admin.ts
3626
- import { Routes as Routes22 } from "@fluxerjs/types";
4520
+ import { Routes as Routes23 } from "@fluxerjs/types";
3627
4521
  function toAuditLogEntryPayload(entry, guildId) {
3628
4522
  return {
3629
4523
  id: entry.id,
@@ -3644,7 +4538,7 @@ function toVanityPayload(data) {
3644
4538
  return { code: data.code ?? null, uses: data.uses };
3645
4539
  }
3646
4540
  async function fetchAuditLogs(guild, options) {
3647
- const url = Routes22.guildAuditLogs(guild.id) + qs({
4541
+ const url = Routes23.guildAuditLogs(guild.id) + qs({
3648
4542
  limit: options?.limit,
3649
4543
  before: options?.before,
3650
4544
  after: options?.after,
@@ -3668,7 +4562,7 @@ async function fetchAuditLogs(guild, options) {
3668
4562
  };
3669
4563
  }
3670
4564
  async function editGuild(guild, options) {
3671
- const data = await guild.client.rest.patch(Routes22.guild(guild.id), {
4565
+ const data = await guild.client.rest.patch(Routes23.guild(guild.id), {
3672
4566
  body: toGuildEditBody(options),
3673
4567
  auth: true
3674
4568
  });
@@ -3676,13 +4570,13 @@ async function editGuild(guild, options) {
3676
4570
  return guild;
3677
4571
  }
3678
4572
  async function fetchVanityURL(guild) {
3679
- const data = await guild.client.rest.get(Routes22.guildVanityUrl(guild.id), {
4573
+ const data = await guild.client.rest.get(Routes23.guildVanityUrl(guild.id), {
3680
4574
  auth: true
3681
4575
  });
3682
4576
  return toVanityPayload(data);
3683
4577
  }
3684
4578
  async function editVanityURL(guild, code) {
3685
- const data = await guild.client.rest.patch(Routes22.guildVanityUrl(guild.id), {
4579
+ const data = await guild.client.rest.patch(Routes23.guildVanityUrl(guild.id), {
3686
4580
  body: { code },
3687
4581
  auth: true
3688
4582
  });
@@ -3690,14 +4584,14 @@ async function editVanityURL(guild, code) {
3690
4584
  return toVanityPayload(data);
3691
4585
  }
3692
4586
  async function fetchDiscoveryStatus(guild) {
3693
- const data = await guild.client.rest.get(Routes22.guildDiscovery(guild.id), {
4587
+ const data = await guild.client.rest.get(Routes23.guildDiscovery(guild.id), {
3694
4588
  auth: true
3695
4589
  });
3696
4590
  return toDiscoveryStatusPayload(data);
3697
4591
  }
3698
4592
  async function applyForDiscovery(guild, options) {
3699
4593
  const data = await guild.client.rest.post(
3700
- Routes22.guildDiscovery(guild.id),
4594
+ Routes23.guildDiscovery(guild.id),
3701
4595
  {
3702
4596
  body: toDiscoveryBody(options),
3703
4597
  auth: true
@@ -3707,7 +4601,7 @@ async function applyForDiscovery(guild, options) {
3707
4601
  }
3708
4602
  async function editDiscoveryApplication(guild, options) {
3709
4603
  const data = await guild.client.rest.patch(
3710
- Routes22.guildDiscovery(guild.id),
4604
+ Routes23.guildDiscovery(guild.id),
3711
4605
  {
3712
4606
  body: toDiscoveryBody(options),
3713
4607
  auth: true
@@ -3716,34 +4610,34 @@ async function editDiscoveryApplication(guild, options) {
3716
4610
  return toDiscoveryApplicationPayload(data);
3717
4611
  }
3718
4612
  async function withdrawDiscoveryApplication(guild) {
3719
- await guild.client.rest.delete(Routes22.guildDiscovery(guild.id), { auth: true });
4613
+ await guild.client.rest.delete(Routes23.guildDiscovery(guild.id), { auth: true });
3720
4614
  }
3721
4615
  async function deleteGuild(guild, options) {
3722
4616
  const body = options ? toSudoBody(options) : {};
3723
- await guild.client.rest.post(Routes22.guildDelete(guild.id), {
4617
+ await guild.client.rest.post(Routes23.guildDelete(guild.id), {
3724
4618
  body,
3725
4619
  auth: true
3726
4620
  });
3727
4621
  guild.client.guilds.delete(guild.id);
3728
4622
  }
3729
4623
  async function transferOwnership(guild, newOwnerId, password) {
3730
- await guild.client.rest.post(Routes22.guildTransferOwnership(guild.id), {
4624
+ await guild.client.rest.post(Routes23.guildTransferOwnership(guild.id), {
3731
4625
  body: { new_owner_id: newOwnerId, ...password != null && { password } },
3732
4626
  auth: true
3733
4627
  });
3734
4628
  }
3735
4629
 
3736
4630
  // src/Domain/Guild/Channels.ts
3737
- import { Routes as Routes23 } from "@fluxerjs/types";
3738
- async function createChannel(guild, data) {
3739
- const created = await guild.client.rest.post(Routes23.guildChannels(guild.id), {
3740
- body: data,
4631
+ import { Routes as Routes24 } from "@fluxerjs/types";
4632
+ async function createChannel(guild, options) {
4633
+ const created = await guild.client.rest.post(Routes24.guildChannels(guild.id), {
4634
+ body: toChannelCreateBody(options),
3741
4635
  auth: true
3742
4636
  });
3743
4637
  return cacheChannel(guild, created);
3744
4638
  }
3745
4639
  async function fetchChannels(guild) {
3746
- const data = await guild.client.rest.get(Routes23.guildChannels(guild.id));
4640
+ const data = await guild.client.rest.get(Routes24.guildChannels(guild.id));
3747
4641
  const channels = [];
3748
4642
  for (const ch of data) {
3749
4643
  const channel = cacheChannel(guild, ch);
@@ -3752,17 +4646,17 @@ async function fetchChannels(guild) {
3752
4646
  return channels;
3753
4647
  }
3754
4648
  async function setChannelPositions(guild, updates) {
3755
- await guild.client.rest.patch(Routes23.guildChannels(guild.id), {
4649
+ await guild.client.rest.patch(Routes24.guildChannels(guild.id), {
3756
4650
  body: toChannelPositionBody(updates),
3757
4651
  auth: true
3758
4652
  });
3759
4653
  }
3760
4654
  async function fetchWebhooks(guild) {
3761
- const data = await guild.client.rest.get(Routes23.guildWebhooks(guild.id));
4655
+ const data = await guild.client.rest.get(Routes24.guildWebhooks(guild.id));
3762
4656
  return data.map((w) => new Webhook(guild.client, w));
3763
4657
  }
3764
4658
  async function fetchInvites(guild) {
3765
- const data = await guild.client.rest.get(Routes23.guildInvites(guild.id));
4659
+ const data = await guild.client.rest.get(Routes24.guildInvites(guild.id));
3766
4660
  return data.map((invite) => new Invite(guild.client, invite));
3767
4661
  }
3768
4662
  async function fetchInvite(guild, codeOrUrl) {
@@ -3782,14 +4676,14 @@ function resolveGuildOnlineCount(data) {
3782
4676
  }
3783
4677
 
3784
4678
  // src/Domain/Guild/Emojis.ts
3785
- import { Routes as Routes24 } from "@fluxerjs/types";
4679
+ import { Routes as Routes25 } from "@fluxerjs/types";
3786
4680
  async function fetchEmojis(guild) {
3787
- const data = await guild.client.rest.get(Routes24.guildEmojis(guild.id));
4681
+ const data = await guild.client.rest.get(Routes25.guildEmojis(guild.id));
3788
4682
  return data.map((e) => cacheEmoji(guild, e));
3789
4683
  }
3790
4684
  async function fetchEmoji(guild, emojiId) {
3791
4685
  try {
3792
- const data = await guild.client.rest.get(Routes24.guildEmoji(guild.id, emojiId));
4686
+ const data = await guild.client.rest.get(Routes25.guildEmoji(guild.id, emojiId));
3793
4687
  return cacheEmoji(guild, data);
3794
4688
  } catch (err) {
3795
4689
  rethrowMapped(err, {
@@ -3799,14 +4693,14 @@ async function fetchEmoji(guild, emojiId) {
3799
4693
  }
3800
4694
  }
3801
4695
  async function createEmoji(guild, options) {
3802
- const data = await guild.client.rest.post(Routes24.guildEmojis(guild.id), {
4696
+ const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
3803
4697
  body: options,
3804
4698
  auth: true
3805
4699
  });
3806
4700
  return cacheEmoji(guild, data);
3807
4701
  }
3808
4702
  async function cloneEmoji(guild, sourceEmojiId) {
3809
- const data = await guild.client.rest.post(Routes24.guildEmojisClone(guild.id), {
4703
+ const data = await guild.client.rest.post(Routes25.guildEmojisClone(guild.id), {
3810
4704
  body: { source_emoji_id: sourceEmojiId },
3811
4705
  auth: true
3812
4706
  });
@@ -3814,18 +4708,18 @@ async function cloneEmoji(guild, sourceEmojiId) {
3814
4708
  }
3815
4709
  async function createEmojisBulk(guild, emojis) {
3816
4710
  const data = await guild.client.rest.post(
3817
- Routes24.guildEmojisBulk(guild.id),
4711
+ Routes25.guildEmojisBulk(guild.id),
3818
4712
  { body: { emojis }, auth: true }
3819
4713
  );
3820
4714
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
3821
4715
  }
3822
4716
 
3823
4717
  // src/Domain/Guild/MemberHttp.ts
3824
- import { Routes as Routes25 } from "@fluxerjs/types";
4718
+ import { Routes as Routes26 } from "@fluxerjs/types";
3825
4719
  async function fetchMember(guild, userId) {
3826
4720
  try {
3827
4721
  const data = await guild.client.rest.get(
3828
- Routes25.guildMember(guild.id, userId)
4722
+ Routes26.guildMember(guild.id, userId)
3829
4723
  );
3830
4724
  return cacheMember(guild, data);
3831
4725
  } catch (err) {
@@ -3840,23 +4734,28 @@ async function fetchMember(guild, userId) {
3840
4734
  }
3841
4735
  async function fetchMe(guild) {
3842
4736
  const data = await guild.client.rest.get(
3843
- Routes25.guildMemberMe(guild.id),
4737
+ Routes26.guildMemberMe(guild.id),
3844
4738
  { auth: true }
3845
4739
  );
3846
4740
  return cacheMember(guild, data);
3847
4741
  }
3848
4742
 
3849
4743
  // src/Domain/Guild/Moderation.ts
3850
- import { Routes as Routes27 } from "@fluxerjs/types";
4744
+ import { Routes as Routes28 } from "@fluxerjs/types";
3851
4745
 
3852
4746
  // src/Domain/Guild/GuildBan.ts
3853
- import { Routes as Routes26 } from "@fluxerjs/types";
4747
+ import { Routes as Routes27 } from "@fluxerjs/types";
4748
+ function parseOptionalDate2(value) {
4749
+ if (value == null || value === "") return null;
4750
+ const date = new Date(value);
4751
+ return Number.isNaN(date.getTime()) ? null : date;
4752
+ }
3854
4753
  var GuildBan = class extends Base {
3855
4754
  client;
3856
4755
  guildId;
3857
4756
  user;
3858
4757
  reason;
3859
- /** ISO timestamp when a temporary ban expires. Null for permanent bans. */
4758
+ /** When a temporary ban expires. Null for permanent bans. */
3860
4759
  expiresAt;
3861
4760
  /** @param data - API ban from GET /guilds/{id}/bans or gateway GUILD_BAN_ADD */
3862
4761
  constructor(client, data, guildId) {
@@ -3865,14 +4764,14 @@ var GuildBan = class extends Base {
3865
4764
  this.guildId = data.guild_id ?? guildId;
3866
4765
  this.user = client.getOrCreateUser(data.user);
3867
4766
  this.reason = data.reason ?? null;
3868
- this.expiresAt = data.expires_at ?? null;
4767
+ this.expiresAt = parseOptionalDate2(data.expires_at);
3869
4768
  }
3870
4769
  /**
3871
4770
  * Remove this ban (unban the user).
3872
4771
  * Requires Ban Members permission.
3873
4772
  */
3874
4773
  async unban() {
3875
- await this.client.rest.delete(Routes26.guildBan(this.guildId, this.user.id), {
4774
+ await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
3876
4775
  auth: true
3877
4776
  });
3878
4777
  }
@@ -3881,40 +4780,53 @@ var GuildBan = class extends Base {
3881
4780
  // src/Domain/Guild/Moderation.ts
3882
4781
  async function ban(guild, userId, options) {
3883
4782
  const body = options ? toGuildBanBody(options) : {};
3884
- await guild.client.rest.put(Routes27.guildBan(guild.id, userId), {
4783
+ await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
3885
4784
  body: Object.keys(body).length ? body : void 0,
3886
4785
  auth: true
3887
4786
  });
3888
4787
  }
3889
4788
  async function fetchBans(guild) {
3890
- const data = await guild.client.rest.get(Routes27.guildBans(guild.id));
4789
+ const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
3891
4790
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
3892
4791
  }
3893
4792
  async function unban(guild, userId) {
3894
- await guild.client.rest.delete(Routes27.guildBan(guild.id, userId), { auth: true });
4793
+ await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), { auth: true });
3895
4794
  }
3896
4795
  async function kick(guild, userId) {
3897
- await guild.client.rest.delete(Routes27.guildMember(guild.id, userId), { auth: true });
4796
+ await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), { auth: true });
3898
4797
  }
3899
4798
 
4799
+ // src/Domain/Guild/GuildRoleManager.ts
4800
+ import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4801
+ var GuildRoleManager = class extends LimitedCollection3 {
4802
+ constructor(guildId, options) {
4803
+ super(options);
4804
+ this.guildId = guildId;
4805
+ }
4806
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4807
+ get everyone() {
4808
+ return this.get(this.guildId);
4809
+ }
4810
+ };
4811
+
3900
4812
  // src/Domain/Guild/Roles.ts
3901
- import { Routes as Routes28 } from "@fluxerjs/types";
4813
+ import { Routes as Routes29 } from "@fluxerjs/types";
3902
4814
  import { parseRoleMention } from "@fluxerjs/util";
3903
4815
  async function createRole(guild, options = {}) {
3904
- const body = toRoleRequestBody(options);
3905
- const data = await guild.client.rest.post(Routes28.guildRoles(guild.id), {
4816
+ const body = toRoleCreateBody(options);
4817
+ const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
3906
4818
  body: Object.keys(body).length ? body : void 0,
3907
4819
  auth: true
3908
4820
  });
3909
4821
  return cacheRole(guild, data);
3910
4822
  }
3911
4823
  async function fetchRoles(guild) {
3912
- const data = await guild.client.rest.get(Routes28.guildRoles(guild.id));
4824
+ const data = await guild.client.rest.get(Routes29.guildRoles(guild.id));
3913
4825
  return data.map((r) => cacheRole(guild, r));
3914
4826
  }
3915
4827
  async function fetchRole(guild, roleId2) {
3916
4828
  try {
3917
- const data = await guild.client.rest.get(Routes28.guildRole(guild.id, roleId2));
4829
+ const data = await guild.client.rest.get(Routes29.guildRole(guild.id, roleId2));
3918
4830
  return cacheRole(guild, data);
3919
4831
  } catch (err) {
3920
4832
  rethrowMapped(err, {
@@ -3931,7 +4843,7 @@ async function resolveRoleId(guild, arg) {
3931
4843
  const needle = trimmed.toLowerCase();
3932
4844
  const cached = guild.roles.find((r) => r.name?.toLowerCase() === needle);
3933
4845
  if (cached) return cached.id;
3934
- const roles = await guild.client.rest.get(Routes28.guildRoles(guild.id));
4846
+ const roles = await guild.client.rest.get(Routes29.guildRoles(guild.id));
3935
4847
  const role = roles.find((r) => r.name?.toLowerCase() === needle);
3936
4848
  if (!role) return null;
3937
4849
  cacheRole(guild, role);
@@ -3940,7 +4852,7 @@ async function resolveRoleId(guild, arg) {
3940
4852
  async function setRolePositions(guild, updates) {
3941
4853
  return replaceRoles(
3942
4854
  guild,
3943
- await guild.client.rest.patch(Routes28.guildRoles(guild.id), {
4855
+ await guild.client.rest.patch(Routes29.guildRoles(guild.id), {
3944
4856
  body: updates,
3945
4857
  auth: true
3946
4858
  })
@@ -3949,7 +4861,7 @@ async function setRolePositions(guild, updates) {
3949
4861
  async function setRoleHoistPositions(guild, updates) {
3950
4862
  return replaceRoles(
3951
4863
  guild,
3952
- await guild.client.rest.patch(Routes28.guildRolesHoistPositions(guild.id), {
4864
+ await guild.client.rest.patch(Routes29.guildRolesHoistPositions(guild.id), {
3953
4865
  body: updates.map((u) => ({
3954
4866
  id: u.id,
3955
4867
  ...u.hoistPosition !== void 0 ? { hoist_position: u.hoistPosition } : {}
@@ -3961,23 +4873,23 @@ async function setRoleHoistPositions(guild, updates) {
3961
4873
  async function resetRoleHoistPositions(guild) {
3962
4874
  return replaceRoles(
3963
4875
  guild,
3964
- await guild.client.rest.delete(Routes28.guildRolesHoistPositions(guild.id), {
4876
+ await guild.client.rest.delete(Routes29.guildRolesHoistPositions(guild.id), {
3965
4877
  auth: true
3966
4878
  })
3967
4879
  );
3968
4880
  }
3969
4881
 
3970
4882
  // src/Domain/Guild/Stickers.ts
3971
- import { Routes as Routes29 } from "@fluxerjs/types";
4883
+ import { Routes as Routes30 } from "@fluxerjs/types";
3972
4884
  async function createSticker(guild, options) {
3973
- const data = await guild.client.rest.post(Routes29.guildStickers(guild.id), {
4885
+ const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
3974
4886
  body: options,
3975
4887
  auth: true
3976
4888
  });
3977
4889
  return cacheSticker(guild, data);
3978
4890
  }
3979
4891
  async function cloneSticker(guild, sourceStickerId) {
3980
- const data = await guild.client.rest.post(Routes29.guildStickersClone(guild.id), {
4892
+ const data = await guild.client.rest.post(Routes30.guildStickersClone(guild.id), {
3981
4893
  body: { source_sticker_id: sourceStickerId },
3982
4894
  auth: true
3983
4895
  });
@@ -3985,17 +4897,17 @@ async function cloneSticker(guild, sourceStickerId) {
3985
4897
  }
3986
4898
  async function createStickersBulk(guild, stickers) {
3987
4899
  const data = await guild.client.rest.post(
3988
- Routes29.guildStickersBulk(guild.id),
4900
+ Routes30.guildStickersBulk(guild.id),
3989
4901
  { body: { stickers }, auth: true }
3990
4902
  );
3991
4903
  return { success: data.success.map((s) => cacheSticker(guild, s)), failed: data.failed };
3992
4904
  }
3993
4905
  async function fetchStickers(guild) {
3994
- const data = await guild.client.rest.get(Routes29.guildStickers(guild.id));
4906
+ const data = await guild.client.rest.get(Routes30.guildStickers(guild.id));
3995
4907
  return data.map((s) => cacheSticker(guild, s));
3996
4908
  }
3997
4909
  async function fetchSticker(guild, stickerId) {
3998
- const data = await guild.client.rest.get(Routes29.guildSticker(guild.id, stickerId));
4910
+ const data = await guild.client.rest.get(Routes30.guildSticker(guild.id, stickerId));
3999
4911
  return cacheSticker(guild, data);
4000
4912
  }
4001
4913
 
@@ -4035,8 +4947,26 @@ var Guild = class extends Base {
4035
4947
  systemChannelId;
4036
4948
  /** Rules channel ID (for Community guilds), or null if none. */
4037
4949
  rulesChannelId;
4950
+ /** {@link SystemChannelFlags} bitfield. */
4951
+ systemChannelFlags;
4952
+ /** Splash card alignment. */
4953
+ splashCardAlignment;
4954
+ /** Embed splash hash. */
4955
+ embedSplash;
4038
4956
  /** NSFW level for this guild. */
4039
4957
  nsfwLevel;
4958
+ /** Whether the guild is marked as adult (18+) content. */
4959
+ nsfw;
4960
+ /** Content warning level. */
4961
+ contentWarningLevel;
4962
+ /** Custom guild-wide content warning text. */
4963
+ contentWarningText;
4964
+ /** {@link GuildOperations} bitfield of disabled operations. */
4965
+ disabledOperations;
4966
+ /** ISO-8601 timestamp before which message history is not available. */
4967
+ messageHistoryCutoff;
4968
+ /** Permissions for the current member in this guild (bitfield string). */
4969
+ permissions;
4040
4970
  /** MFA level required for moderation actions. */
4041
4971
  mfaLevel;
4042
4972
  /** Banner width in pixels. */
@@ -4070,13 +5000,13 @@ var Guild = class extends Base {
4070
5000
  this.client = client;
4071
5001
  this.id = data.id;
4072
5002
  this.members = new GuildMemberManager(this);
4073
- this.channels = new LimitedCollection3({
5003
+ this.channels = new LimitedCollection4({
4074
5004
  maxSize: Number.POSITIVE_INFINITY,
4075
5005
  onEvict: (_id, channel) => client.cache.cascadeChannel(channel, "guild")
4076
5006
  });
4077
- this.roles = new LimitedCollection3({ maxSize: client.cache.limits.roles });
4078
- this.emojis = new LimitedCollection3({ maxSize: client.cache.limits.emojis });
4079
- this.stickers = new LimitedCollection3({ maxSize: client.cache.limits.stickers });
5007
+ this.roles = new GuildRoleManager(this.id, { maxSize: client.cache.limits.roles });
5008
+ this.emojis = new LimitedCollection4({ maxSize: client.cache.limits.emojis });
5009
+ this.stickers = new LimitedCollection4({ maxSize: client.cache.limits.stickers });
4080
5010
  this.name = data.name ?? "";
4081
5011
  this.icon = data.icon ?? null;
4082
5012
  this.banner = data.banner ?? null;
@@ -4091,7 +5021,16 @@ var Guild = class extends Base {
4091
5021
  this.afkTimeout = data.afk_timeout ?? 0;
4092
5022
  this.systemChannelId = data.system_channel_id ?? null;
4093
5023
  this.rulesChannelId = data.rules_channel_id ?? null;
5024
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5025
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5026
+ this.embedSplash = data.embed_splash ?? null;
4094
5027
  this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
5028
+ this.nsfw = data.nsfw ?? false;
5029
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5030
+ this.contentWarningText = data.content_warning_text ?? null;
5031
+ this.disabledOperations = data.disabled_operations ?? 0;
5032
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5033
+ this.permissions = data.permissions ?? null;
4095
5034
  this.mfaLevel = data.mfa_level ?? 0;
4096
5035
  this.bannerWidth = data.banner_width ?? null;
4097
5036
  this.bannerHeight = data.banner_height ?? null;
@@ -4126,7 +5065,28 @@ var Guild = class extends Base {
4126
5065
  if (data.afk_timeout !== void 0) this.afkTimeout = data.afk_timeout ?? 0;
4127
5066
  if (data.system_channel_id !== void 0) this.systemChannelId = data.system_channel_id ?? null;
4128
5067
  if (data.rules_channel_id !== void 0) this.rulesChannelId = data.rules_channel_id ?? null;
5068
+ if (data.system_channel_flags !== void 0) {
5069
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
5070
+ }
5071
+ if (data.splash_card_alignment !== void 0) {
5072
+ this.splashCardAlignment = data.splash_card_alignment ?? 0;
5073
+ }
5074
+ if (data.embed_splash !== void 0) this.embedSplash = data.embed_splash ?? null;
4129
5075
  if (data.nsfw_level !== void 0) this.nsfwLevel = data.nsfw_level ?? GuildNSFWLevel.Safe;
5076
+ if (data.nsfw !== void 0) this.nsfw = data.nsfw ?? false;
5077
+ if (data.content_warning_level !== void 0) {
5078
+ this.contentWarningLevel = data.content_warning_level ?? 0;
5079
+ }
5080
+ if (data.content_warning_text !== void 0) {
5081
+ this.contentWarningText = data.content_warning_text ?? null;
5082
+ }
5083
+ if (data.disabled_operations !== void 0) {
5084
+ this.disabledOperations = data.disabled_operations ?? 0;
5085
+ }
5086
+ if (data.message_history_cutoff !== void 0) {
5087
+ this.messageHistoryCutoff = data.message_history_cutoff ?? null;
5088
+ }
5089
+ if (data.permissions !== void 0) this.permissions = data.permissions ?? null;
4130
5090
  if (data.mfa_level !== void 0) this.mfaLevel = data.mfa_level ?? 0;
4131
5091
  if (data.banner_width !== void 0) this.bannerWidth = data.banner_width ?? null;
4132
5092
  if (data.banner_height !== void 0) this.bannerHeight = data.banner_height ?? null;
@@ -4147,11 +5107,11 @@ var Guild = class extends Base {
4147
5107
  }
4148
5108
  /** Unix timestamp (ms) when this guild was created, derived from its snowflake ID. */
4149
5109
  get createdTimestamp() {
4150
- return SnowflakeUtil7.timestampFromSnowflake(this.id);
5110
+ return SnowflakeUtil9.timestampFromSnowflake(this.id);
4151
5111
  }
4152
5112
  /** Date when this guild was created, derived from its snowflake ID. */
4153
5113
  get createdAt() {
4154
- return SnowflakeUtil7.dateFromSnowflake(this.id);
5114
+ return SnowflakeUtil9.dateFromSnowflake(this.id);
4155
5115
  }
4156
5116
  /** The guild's name. */
4157
5117
  toString() {
@@ -4179,11 +5139,11 @@ var Guild = class extends Base {
4179
5139
  });
4180
5140
  }
4181
5141
  /**
4182
- * Create a channel. `data.type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
5142
+ * Create a channel. `type`: 0=text, 2=voice, 4=category, 998=link (set `url`).
4183
5143
  * Requires Manage Channels.
4184
5144
  */
4185
- createChannel(data) {
4186
- return createChannel(this, data);
5145
+ createChannel(options) {
5146
+ return createChannel(this, options);
4187
5147
  }
4188
5148
  /** Fetch all channels in this guild from the API. */
4189
5149
  fetchChannels() {
@@ -4245,7 +5205,7 @@ var Guild = class extends Base {
4245
5205
  resetRoleHoistPositions() {
4246
5206
  return resetRoleHoistPositions(this);
4247
5207
  }
4248
- /** Ban a user from the guild. Requires Ban Members. `ban_duration_seconds`: 0 = permanent. */
5208
+ /** Ban a user from the guild. Requires Ban Members. `banDurationSeconds`: 0 = permanent. */
4249
5209
  ban(userId, options) {
4250
5210
  return ban(this, userId, options);
4251
5211
  }
@@ -4445,23 +5405,23 @@ function applyGuildSnapshotFromGateway(client, raw) {
4445
5405
  }
4446
5406
 
4447
5407
  // src/ClientCore/ClientUser.ts
4448
- import { GatewayOpcodes, Routes as Routes30 } from "@fluxerjs/types";
5408
+ import { GatewayOpcodes, Routes as Routes31 } from "@fluxerjs/types";
4449
5409
  var ClientUser = class extends User {
4450
5410
  /** Broadcast presence (gateway opcode 3) on all shards. */
4451
5411
  setPresence(presence) {
5412
+ this.client.options.presence = presence;
4452
5413
  const wire = toPresenceWire(presence);
4453
- this.client.options.presence = wire;
4454
5414
  this.client._sendToAllShards({ op: GatewayOpcodes.PresenceUpdate, d: wire });
4455
5415
  }
4456
5416
  /** GET /users/@me — refresh the logged-in user from REST and patch this instance. */
4457
5417
  async fetch() {
4458
- const data = await this.client.rest.get(Routes30.currentUser(), { auth: true });
5418
+ const data = await this.client.rest.get(Routes31.currentUser(), { auth: true });
4459
5419
  this._patch(data);
4460
5420
  return this;
4461
5421
  }
4462
5422
  /** GET /users/@me/guilds — returns camelCase partial guilds. */
4463
5423
  async fetchGuilds(options) {
4464
- const path = Routes30.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
5424
+ const path = Routes31.currentUserGuilds() + (options?.withCounts ? "?with_counts=true" : "");
4465
5425
  const data = await this.client.rest.get(path, { auth: true });
4466
5426
  return data.map((g) => ({
4467
5427
  id: g.id,
@@ -4474,10 +5434,18 @@ var ClientUser = class extends User {
4474
5434
  ...g.approximate_presence_count !== void 0 ? { approximatePresenceCount: g.approximate_presence_count } : {}
4475
5435
  }));
4476
5436
  }
4477
- /** DELETE /users/@me/guilds/{guild_id} */
5437
+ /**
5438
+ * Leave a guild (`client.user.leaveGuild`).
5439
+ * DELETE /users/@me/guilds/{guild_id}.
5440
+ *
5441
+ * @param guildId - Guild to leave
5442
+ * @param options - Optional sudo / MFA body for user accounts
5443
+ * @example
5444
+ * await client.user.leaveGuild(guildId);
5445
+ */
4478
5446
  async leaveGuild(guildId, options) {
4479
5447
  const body = options ? toSudoBody(options) : void 0;
4480
- await this.client.rest.delete(Routes30.leaveGuild(guildId), {
5448
+ await this.client.rest.delete(Routes31.leaveGuild(guildId), {
4481
5449
  body: body && Object.keys(body).length ? body : void 0,
4482
5450
  auth: true
4483
5451
  });
@@ -4485,7 +5453,7 @@ var ClientUser = class extends User {
4485
5453
  /** Delete every message authored by the caller across a guild (sudo). */
4486
5454
  async bulkDeleteMyMessagesInGuild(guildId, options) {
4487
5455
  const body = options ? toSudoBody(options) : void 0;
4488
- await this.client.rest.post(Routes30.guildBulkDeleteMine(guildId), {
5456
+ await this.client.rest.post(Routes31.guildBulkDeleteMine(guildId), {
4489
5457
  body: body && Object.keys(body).length ? body : void 0,
4490
5458
  auth: true
4491
5459
  });
@@ -4652,7 +5620,7 @@ var guildResourceHandlers = {
4652
5620
  role = new Role(client, data.role, data.guild_id);
4653
5621
  guild?.roles.set(role.id, role);
4654
5622
  }
4655
- client.emit(Events.GuildRoleUpdate, { role, oldRole });
5623
+ client.emit(Events.GuildRoleUpdate, oldRole, role);
4656
5624
  },
4657
5625
  GUILD_ROLE_UPDATE_BULK(client, d) {
4658
5626
  const data = d;
@@ -4668,11 +5636,7 @@ var guildResourceHandlers = {
4668
5636
  const guild = client.guilds.get(data.guild_id);
4669
5637
  const role = guild?.roles.get(data.role_id) ?? null;
4670
5638
  guild?.roles.delete(data.role_id);
4671
- client.emit(Events.GuildRoleDelete, {
4672
- roleId: data.role_id,
4673
- guildId: data.guild_id,
4674
- role
4675
- });
5639
+ client.emit(Events.GuildRoleDelete, role, data.guild_id, data.role_id);
4676
5640
  },
4677
5641
  GUILD_BAN_ADD(client, d) {
4678
5642
  const data = d;
@@ -4781,7 +5745,7 @@ function normalizeInviteCreate(client, payload) {
4781
5745
  const code = str(raw?.code);
4782
5746
  if (!raw || !code) return null;
4783
5747
  const typeNum = num(raw.type);
4784
- const type = typeNum === InviteType2.GroupDM || typeNum === InviteType2.EmojiPack || typeNum === InviteType2.StickerPack ? typeNum : InviteType2.Guild;
5748
+ const type = typeNum === InviteType2.GroupDM ? InviteType2.GroupDM : InviteType2.Guild;
4785
5749
  const shared = {
4786
5750
  code,
4787
5751
  inviter: raw.inviter ?? null,
@@ -4793,11 +5757,6 @@ function normalizeInviteCreate(client, payload) {
4793
5757
  max_uses: num(raw.max_uses),
4794
5758
  max_age: num(raw.max_age)
4795
5759
  };
4796
- if (type === InviteType2.EmojiPack || type === InviteType2.StickerPack) {
4797
- const pack = asRecord(raw.pack);
4798
- if (!pack || !str(pack.id) || !str(pack.name)) return null;
4799
- return { ...shared, type, pack };
4800
- }
4801
5760
  const guildObj = asRecord(raw.guild);
4802
5761
  const channelObj = asRecord(raw.channel);
4803
5762
  const guildId = str(guildObj?.id) ?? str(raw.guild_id) ?? "0";
@@ -4849,6 +5808,30 @@ var inviteHandlers = {
4849
5808
  }
4850
5809
  };
4851
5810
 
5811
+ // src/Domain/Guild/PartialGuildMember.ts
5812
+ var PartialGuildMember = class {
5813
+ partial = true;
5814
+ client;
5815
+ id;
5816
+ user;
5817
+ guildId;
5818
+ guild;
5819
+ constructor(data) {
5820
+ this.client = data.client;
5821
+ this.id = data.id;
5822
+ this.user = data.user;
5823
+ this.guild = data.guild;
5824
+ this.guildId = data.guild.id;
5825
+ }
5826
+ /**
5827
+ * Fetch the full {@link GuildMember} from the API (cache-aware via `guild.members.fetch`).
5828
+ * @throws FluxerError with MEMBER_NOT_FOUND if the user is not in the guild
5829
+ */
5830
+ async fetch() {
5831
+ return this.guild.members.fetch(this.id);
5832
+ }
5833
+ };
5834
+
4852
5835
  // src/ClientCore/EventHandlers/Members.ts
4853
5836
  var memberHandlers = {
4854
5837
  GUILD_MEMBER_ADD(client, d) {
@@ -4875,28 +5858,15 @@ var memberHandlers = {
4875
5858
  const data = d;
4876
5859
  const guild = client.guilds.get(data.guild_id);
4877
5860
  if (!guild || !data.user?.id) return;
4878
- let member = guild.members.get(data.user.id);
4879
- if (member) {
4880
- guild.members.delete(data.user.id);
4881
- } else {
4882
- member = new GuildMember(
4883
- client,
4884
- {
4885
- user: {
4886
- ...unknownUser(data.user.id),
4887
- ...data.user,
4888
- username: data.user.username ?? "Unknown",
4889
- discriminator: data.user.discriminator ?? "0"
4890
- },
4891
- roles: [],
4892
- joined_at: (/* @__PURE__ */ new Date(0)).toISOString(),
4893
- nick: null,
4894
- mute: false,
4895
- deaf: false
4896
- },
4897
- guild
4898
- );
4899
- }
5861
+ const cached = guild.members.get(data.user.id);
5862
+ if (cached) guild.members.delete(data.user.id);
5863
+ const user = client.getOrCreateUser(data.user);
5864
+ const member = cached ?? new PartialGuildMember({
5865
+ client,
5866
+ id: data.user.id,
5867
+ user,
5868
+ guild
5869
+ });
4900
5870
  guild.adjustMemberCount(-1);
4901
5871
  client.emit(Events.GuildMemberRemove, member);
4902
5872
  },
@@ -4915,7 +5885,7 @@ var memberHandlers = {
4915
5885
  members,
4916
5886
  chunkIndex: data.chunk_index,
4917
5887
  chunkCount: data.chunk_count,
4918
- notFound: [],
5888
+ notFound: data.not_found ?? [],
4919
5889
  nonce: data.nonce ?? null
4920
5890
  };
4921
5891
  client.emit(Events.GuildMembersChunk, payload);
@@ -4923,7 +5893,35 @@ var memberHandlers = {
4923
5893
  };
4924
5894
 
4925
5895
  // src/ClientCore/EventHandlers/Messages.ts
4926
- function toReactionEmoji2(emoji) {
5896
+ import { SnowflakeUtil as SnowflakeUtil10 } from "@fluxerjs/util";
5897
+ function cachedTextChannel(client, channelId) {
5898
+ const channel = client.channels.get(channelId);
5899
+ return channel?.isTextBased() ? channel : null;
5900
+ }
5901
+ function cachedMessage(client, channelId, messageId) {
5902
+ const data = client._getMessageCache(channelId)?.get(messageId);
5903
+ return data ? new Message(client, data) : null;
5904
+ }
5905
+ function isHydratableMessage(data) {
5906
+ return Boolean(data.author?.id && data.timestamp);
5907
+ }
5908
+ function toPartialMessage(client, args) {
5909
+ const cached = args.cached;
5910
+ const authorId = args.authorId ?? cached?.author?.id ?? null;
5911
+ const author = cached?.author ? client.getOrCreateUser(cached.author) : authorId ? client.users.get(authorId) ?? null : null;
5912
+ const createdAt = cached?.timestamp ? new Date(cached.timestamp) : SnowflakeUtil10.isValid(args.id) ? SnowflakeUtil10.dateFromSnowflake(args.id) : null;
5913
+ return new PartialMessage(client, {
5914
+ id: args.id,
5915
+ channelId: args.channelId,
5916
+ guildId: args.guildId ?? cached?.guild_id ?? null,
5917
+ channel: cachedTextChannel(client, args.channelId),
5918
+ content: args.content ?? cached?.content ?? null,
5919
+ authorId,
5920
+ author,
5921
+ createdAt
5922
+ });
5923
+ }
5924
+ function toReactionEmoji(emoji) {
4927
5925
  return {
4928
5926
  name: emoji.name,
4929
5927
  ...emoji.id !== void 0 ? { id: emoji.id } : {},
@@ -4940,9 +5938,12 @@ function emitReaction(event) {
4940
5938
  const payload = {
4941
5939
  reaction,
4942
5940
  user,
5941
+ message: cachedMessage(client, data.channel_id, data.message_id),
5942
+ channel: cachedTextChannel(client, data.channel_id),
5943
+ member,
4943
5944
  messageId: data.message_id,
4944
5945
  channelId: data.channel_id,
4945
- emoji: toReactionEmoji2(data.emoji),
5946
+ emoji: toReactionEmoji(data.emoji),
4946
5947
  userId: data.user_id
4947
5948
  };
4948
5949
  client.emit(event, payload);
@@ -4962,37 +5963,60 @@ var messageHandlers = {
4962
5963
  },
4963
5964
  MESSAGE_UPDATE(client, d) {
4964
5965
  const partial = d;
4965
- const cache = client._getMessageCache(partial.channel_id);
4966
- let oldMessage = null;
4967
- let mergedData = partial;
4968
- if (cache) {
4969
- const oldData = cache.get(partial.id);
4970
- if (oldData) {
4971
- oldMessage = new Message(client, oldData);
4972
- mergedData = { ...oldData, ...partial };
4973
- }
5966
+ const oldData = client._getMessageCache(partial.channel_id)?.get(partial.id);
5967
+ const oldMessage = oldData ? new Message(client, oldData) : null;
5968
+ const mergedData = oldData ? { ...oldData, ...partial } : partial;
5969
+ if (isHydratableMessage(mergedData)) {
5970
+ client._addMessageToCache(partial.channel_id, mergedData);
5971
+ client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
5972
+ return;
4974
5973
  }
4975
- client._addMessageToCache(partial.channel_id, mergedData);
4976
- client.emit(Events.MessageUpdate, oldMessage, new Message(client, mergedData));
5974
+ client.emit(
5975
+ Events.MessageUpdate,
5976
+ oldMessage,
5977
+ toPartialMessage(client, {
5978
+ id: partial.id,
5979
+ channelId: partial.channel_id,
5980
+ guildId: partial.guild_id ?? oldData?.guild_id ?? null,
5981
+ content: partial.content ?? oldData?.content ?? null,
5982
+ authorId: partial.author?.id ?? oldData?.author?.id ?? null,
5983
+ cached: oldData
5984
+ })
5985
+ );
4977
5986
  },
4978
5987
  MESSAGE_DELETE(client, d) {
4979
5988
  const data = d;
4980
- client._removeMessageFromCache(data.channel_id, data.id);
4981
- client.emit(Events.MessageDelete, {
5989
+ const cached = client._getMessageCache(data.channel_id)?.get(data.id);
5990
+ const payload = toPartialMessage(client, {
4982
5991
  id: data.id,
4983
5992
  channelId: data.channel_id,
4984
- channel: client.channels.get(data.channel_id) ?? null,
4985
- content: data.content ?? null,
4986
- authorId: data.author_id ?? null
5993
+ guildId: data.guild_id ?? cached?.guild_id ?? null,
5994
+ content: data.content ?? cached?.content ?? null,
5995
+ authorId: data.author_id ?? cached?.author?.id ?? null,
5996
+ cached
4987
5997
  });
5998
+ client._removeMessageFromCache(data.channel_id, data.id);
5999
+ client.emit(Events.MessageDelete, payload);
4988
6000
  },
4989
6001
  MESSAGE_DELETE_BULK(client, d) {
4990
6002
  const data = d;
4991
- for (const id of data.ids ?? []) client._removeMessageFromCache(data.channel_id, id);
6003
+ const ids = data.ids ?? [];
6004
+ const cache = client._getMessageCache(data.channel_id);
6005
+ const messages = ids.map(
6006
+ (id) => toPartialMessage(client, {
6007
+ id,
6008
+ channelId: data.channel_id,
6009
+ guildId: data.guild_id ?? cache?.get(id)?.guild_id ?? null,
6010
+ cached: cache?.get(id)
6011
+ })
6012
+ );
6013
+ for (const id of ids) client._removeMessageFromCache(data.channel_id, id);
4992
6014
  client.emit(Events.MessageDeleteBulk, {
4993
- ids: data.ids ?? [],
6015
+ ids,
4994
6016
  channelId: data.channel_id,
4995
- guildId: data.guild_id ?? null
6017
+ guildId: data.guild_id ?? null,
6018
+ channel: cachedTextChannel(client, data.channel_id),
6019
+ messages
4996
6020
  });
4997
6021
  },
4998
6022
  MESSAGE_REACTION_ADD: emitReaction(Events.MessageReactionAdd),
@@ -5002,7 +6026,9 @@ var messageHandlers = {
5002
6026
  const payload = {
5003
6027
  messageId: data.message_id,
5004
6028
  channelId: data.channel_id,
5005
- guildId: data.guild_id ?? null
6029
+ guildId: data.guild_id ?? null,
6030
+ message: cachedMessage(client, data.channel_id, data.message_id),
6031
+ channel: cachedTextChannel(client, data.channel_id)
5006
6032
  };
5007
6033
  client.emit(Events.MessageReactionRemoveAll, payload);
5008
6034
  },
@@ -5012,7 +6038,9 @@ var messageHandlers = {
5012
6038
  messageId: data.message_id,
5013
6039
  channelId: data.channel_id,
5014
6040
  guildId: data.guild_id ?? null,
5015
- emoji: toReactionEmoji2(data.emoji)
6041
+ emoji: toReactionEmoji(data.emoji),
6042
+ message: cachedMessage(client, data.channel_id, data.message_id),
6043
+ channel: cachedTextChannel(client, data.channel_id)
5016
6044
  };
5017
6045
  client.emit(Events.MessageReactionRemoveEmoji, payload);
5018
6046
  },
@@ -5031,7 +6059,7 @@ var messageHandlers = {
5031
6059
  }
5032
6060
  reactions.push({
5033
6061
  userId: entry.user_id,
5034
- emoji: toReactionEmoji2(entry.emoji),
6062
+ emoji: toReactionEmoji(entry.emoji),
5035
6063
  member
5036
6064
  });
5037
6065
  }
@@ -5039,6 +6067,8 @@ var messageHandlers = {
5039
6067
  channelId: data.channel_id,
5040
6068
  messageId: data.message_id,
5041
6069
  guildId: data.guild_id ?? null,
6070
+ message: cachedMessage(client, data.channel_id, data.message_id),
6071
+ channel: cachedTextChannel(client, data.channel_id),
5042
6072
  reactions
5043
6073
  };
5044
6074
  client.emit(Events.MessageReactionAddMany, payload);
@@ -5249,15 +6279,27 @@ function handleReadyPayload(client, data) {
5249
6279
  const waitForGuilds = client.options.waitForGuilds === true;
5250
6280
  const guilds = data.guilds ?? [];
5251
6281
  const pending = hydrateReadyGuilds(client, guilds, waitForGuilds);
6282
+ if (client.readyAt !== null) {
6283
+ if (pending !== null && pending.size > 0) {
6284
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6285
+ for (const id of pending) existing.add(id);
6286
+ client._pendingGuildIds = existing;
6287
+ }
6288
+ return;
6289
+ }
5252
6290
  if (pending !== null && pending.size > 0) {
5253
- client._pendingGuildIds = pending;
6291
+ const existing = client._pendingGuildIds ?? /* @__PURE__ */ new Set();
6292
+ for (const id of pending) existing.add(id);
6293
+ client._pendingGuildIds = existing;
5254
6294
  return;
5255
6295
  }
5256
6296
  if (waitForGuilds && guilds.length === 0) {
5257
- client._guildStreamSettleTimeout = setTimeout(() => {
5258
- client._guildStreamSettleTimeout = null;
5259
- finalizeClientReady(client);
5260
- }, GUILD_STREAM_SETTLE_MS);
6297
+ if (client._guildStreamSettleTimeout === null) {
6298
+ client._guildStreamSettleTimeout = setTimeout(() => {
6299
+ client._guildStreamSettleTimeout = null;
6300
+ if (client.readyAt === null) finalizeClientReady(client);
6301
+ }, GUILD_STREAM_SETTLE_MS);
6302
+ }
5261
6303
  return;
5262
6304
  }
5263
6305
  finalizeClientReady(client);
@@ -5269,7 +6311,7 @@ async function connectClientGateway(client, token, signal) {
5269
6311
  const ws = new WebSocketManager({
5270
6312
  token,
5271
6313
  intents: client.options.intents ?? 0,
5272
- presence: client.options.presence,
6314
+ presence: client.options.presence ? toPresenceWire(client.options.presence) : void 0,
5273
6315
  flags: client.options.identifyFlags,
5274
6316
  ignoredEvents: client.options.ignoredEvents,
5275
6317
  initialGuildId: client.options.initialGuildId,
@@ -5278,24 +6320,57 @@ async function connectClientGateway(client, token, signal) {
5278
6320
  },
5279
6321
  version: client.options.rest?.version ?? "1",
5280
6322
  debug: client.options.gatewayDebug !== false,
5281
- WebSocket: client.options.WebSocket
6323
+ WebSocket: client.options.WebSocket,
6324
+ shardCount: client.options.shardCount ?? client.options.totalShards,
6325
+ shardIds: client.options.shardIds ?? client.options.shardList,
6326
+ guildsPerShard: client.options.guildsPerShard,
6327
+ buildStrategy: client.options.buildStrategy,
6328
+ sessionStore: client.options.sessionStore,
6329
+ identifyThrottler: client.options.identifyThrottler
5282
6330
  });
5283
6331
  ws.on("dispatch", ({ payload }) => {
5284
6332
  handleGatewayDispatch(client, payload, client._deferredGatewayDispatches).catch(
5285
6333
  (err) => emitClientError(client, err)
5286
6334
  );
5287
6335
  });
5288
- ws.on("ready", ({ data }) => {
5289
- handleReadyPayload(client, data);
6336
+ ws.on("ready", ({ shardId, data }) => {
6337
+ client.emit(Events.ShardReady, shardId);
6338
+ try {
6339
+ handleReadyPayload(client, data);
6340
+ } catch (err) {
6341
+ emitClientError(client, err);
6342
+ }
6343
+ });
6344
+ ws.on("resumed", (shardId) => {
6345
+ client.emit(Events.ShardResumed, shardId);
6346
+ });
6347
+ ws.on("close", ({ shardId, code }) => {
6348
+ client.emit(Events.ShardDisconnect, shardId, code);
6349
+ if (code === GatewayCloseCodes.AuthenticationFailed) {
6350
+ emitClientError(
6351
+ client,
6352
+ new FluxerError("Gateway authentication failed (4004). Check the bot token.", {
6353
+ code: ErrorCodes.InvalidToken
6354
+ })
6355
+ );
6356
+ }
5290
6357
  });
5291
- ws.on("error", ({ error }) => {
5292
- client.logger.error("gateway error", { error: error.message, name: error.name });
6358
+ ws.on("error", ({ shardId, error }) => {
6359
+ if (shardId >= 0) client.emit(Events.ShardError, shardId, error);
6360
+ client.logger.error("gateway error", {
6361
+ error: error.message,
6362
+ name: error.name,
6363
+ shardId
6364
+ });
5293
6365
  client.emit(Events.Error, error);
5294
6366
  });
5295
6367
  ws.on("debug", (msg) => {
5296
6368
  client.logger.debug(msg);
5297
6369
  client.emit(Events.Debug, msg);
5298
6370
  });
6371
+ ws.on("shardingRequired", (payload) => {
6372
+ client.emit(Events.ShardingRequired, payload);
6373
+ });
5299
6374
  client._ws = ws;
5300
6375
  const onAbort = () => {
5301
6376
  ws.destroy();
@@ -5321,9 +6396,9 @@ async function connectClientGateway(client, token, signal) {
5321
6396
  }
5322
6397
 
5323
6398
  // src/ClientCore/GuildManager.ts
5324
- import { LimitedCollection as LimitedCollection4 } from "@fluxerjs/collection";
5325
- import { Routes as Routes31 } from "@fluxerjs/types";
5326
- var GuildManager = class extends LimitedCollection4 {
6399
+ import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
6400
+ import { Routes as Routes32 } from "@fluxerjs/types";
6401
+ var GuildManager = class extends LimitedCollection5 {
5327
6402
  constructor(client) {
5328
6403
  super({
5329
6404
  maxSize: client.cache.limits.guilds,
@@ -5332,8 +6407,8 @@ var GuildManager = class extends LimitedCollection4 {
5332
6407
  this.client = client;
5333
6408
  }
5334
6409
  /**
5335
- * Remove a guild and cascade its channels / message caches.
5336
- * FIFO eviction uses `onEvict` instead (via `super.delete` in LimitedCollection).
6410
+ * Remove a guild from cache and cascade its channels / message caches.
6411
+ * Does not leave the guild. Use {@link ClientUser.leaveGuild} for that.
5337
6412
  */
5338
6413
  delete(key) {
5339
6414
  const guild = this.get(key);
@@ -5361,7 +6436,7 @@ var GuildManager = class extends LimitedCollection4 {
5361
6436
  const cached = this.get(guildId);
5362
6437
  if (cached && !options?.force) return cached;
5363
6438
  try {
5364
- const data = await this.client.rest.get(Routes31.guild(guildId));
6439
+ const data = await this.client.rest.get(Routes32.guild(guildId));
5365
6440
  if (cached) {
5366
6441
  cached._patch(data);
5367
6442
  return cached;
@@ -5446,184 +6521,13 @@ var MessageCache = class {
5446
6521
  }
5447
6522
  };
5448
6523
 
5449
- // src/ClientCore/PackManager.ts
5450
- import {
5451
- Routes as Routes32
5452
- } from "@fluxerjs/types";
5453
- function toPackSummaryPayload(data) {
5454
- return {
5455
- id: data.id,
5456
- name: data.name,
5457
- description: data.description,
5458
- type: data.type,
5459
- creatorId: data.creator_id,
5460
- createdAt: data.created_at,
5461
- updatedAt: data.updated_at,
5462
- ...data.installed_at !== void 0 ? { installedAt: data.installed_at } : {}
5463
- };
5464
- }
5465
- function toEmojiPayload(data) {
5466
- return {
5467
- id: data.id,
5468
- name: data.name,
5469
- animated: data.animated
5470
- };
5471
- }
5472
- function toStickerPayload(data) {
5473
- return {
5474
- id: data.id,
5475
- name: data.name,
5476
- description: data.description,
5477
- tags: data.tags,
5478
- animated: data.animated,
5479
- nsfw: data.nsfw
5480
- };
5481
- }
5482
- function toInvitePayload(data) {
5483
- return {
5484
- code: data.code,
5485
- ...data.max_uses !== void 0 ? { maxUses: data.max_uses } : {},
5486
- ...data.max_age !== void 0 ? { maxAge: data.max_age } : {},
5487
- ...data.uses !== void 0 ? { uses: data.uses } : {},
5488
- ...data.temporary !== void 0 ? { temporary: data.temporary } : {},
5489
- ...data.created_at !== void 0 ? { createdAt: data.created_at } : {},
5490
- ...data.expires_at !== void 0 ? { expiresAt: data.expires_at } : {}
5491
- };
5492
- }
5493
- function mapDashboardSection(section) {
5494
- return {
5495
- installedLimit: section.installed_limit,
5496
- createdLimit: section.created_limit,
5497
- installed: section.installed.map(toPackSummaryPayload),
5498
- created: section.created.map(toPackSummaryPayload)
5499
- };
5500
- }
5501
- var PackManager = class {
5502
- constructor(client) {
5503
- this.client = client;
5504
- }
5505
- /** Fetch the current user's pack dashboard (camelCase summaries). */
5506
- async fetchDashboard() {
5507
- const data = await this.client.rest.get(Routes32.packs());
5508
- return {
5509
- emoji: mapDashboardSection(data.emoji),
5510
- sticker: mapDashboardSection(data.sticker)
5511
- };
5512
- }
5513
- /** Create a pack. */
5514
- async create(packType, body) {
5515
- const data = await this.client.rest.post(Routes32.packsByType(packType), {
5516
- body
5517
- });
5518
- return toPackSummaryPayload(data);
5519
- }
5520
- /** Edit a pack. */
5521
- async edit(packId, body) {
5522
- const data = await this.client.rest.patch(Routes32.pack(packId), { body });
5523
- return toPackSummaryPayload(data);
5524
- }
5525
- /** Delete a pack. */
5526
- async delete(packId) {
5527
- await this.client.rest.delete(Routes32.pack(packId));
5528
- }
5529
- /** Install a pack for the current user. */
5530
- async install(packId) {
5531
- await this.client.rest.post(Routes32.packInstall(packId));
5532
- }
5533
- /** Uninstall a pack for the current user. */
5534
- async uninstall(packId) {
5535
- await this.client.rest.delete(Routes32.packInstall(packId));
5536
- }
5537
- /** List invites for a pack. */
5538
- async listInvites(packId) {
5539
- const data = await this.client.rest.get(Routes32.packInvites(packId));
5540
- return data.map(toInvitePayload);
5541
- }
5542
- /** Create an invite for a pack. */
5543
- async createInvite(packId, options = {}) {
5544
- const body = toPackInviteBody(options);
5545
- const data = await this.client.rest.post(Routes32.packInvites(packId), {
5546
- body: Object.keys(body).length ? body : void 0
5547
- });
5548
- return toInvitePayload(data);
5549
- }
5550
- /** List emojis in a pack. */
5551
- async listEmojis(packId) {
5552
- const data = await this.client.rest.get(Routes32.packEmojis(packId));
5553
- return data.map(toEmojiPayload);
5554
- }
5555
- /** Create an emoji in a pack. */
5556
- async createEmoji(packId, options) {
5557
- const data = await this.client.rest.post(Routes32.packEmojis(packId), {
5558
- body: toEmojiCreateBody(options)
5559
- });
5560
- return toEmojiPayload(data);
5561
- }
5562
- /** Bulk-create emojis in a pack. */
5563
- async createEmojisBulk(packId, emojis) {
5564
- const data = await this.client.rest.post(
5565
- Routes32.packEmojisBulk(packId),
5566
- { body: { emojis: emojis.map(toEmojiCreateBody) } }
5567
- );
5568
- return {
5569
- success: data.success.map(toEmojiPayload),
5570
- failed: data.failed
5571
- };
5572
- }
5573
- /** Edit an emoji in a pack. */
5574
- async editEmoji(packId, emojiId, options) {
5575
- const data = await this.client.rest.patch(Routes32.packEmoji(packId, emojiId), {
5576
- body: toEmojiEditBody(options)
5577
- });
5578
- return toEmojiPayload(data);
5579
- }
5580
- /** Delete an emoji from a pack. */
5581
- async deleteEmoji(packId, emojiId) {
5582
- await this.client.rest.delete(Routes32.packEmoji(packId, emojiId));
5583
- }
5584
- /** List stickers in a pack. */
5585
- async listStickers(packId) {
5586
- const data = await this.client.rest.get(Routes32.packStickers(packId));
5587
- return data.map(toStickerPayload);
5588
- }
5589
- /** Create a sticker in a pack. */
5590
- async createSticker(packId, options) {
5591
- const data = await this.client.rest.post(Routes32.packStickers(packId), {
5592
- body: toStickerCreateBody(options)
5593
- });
5594
- return toStickerPayload(data);
5595
- }
5596
- /** Bulk-create stickers in a pack. */
5597
- async createStickersBulk(packId, stickers) {
5598
- const data = await this.client.rest.post(
5599
- Routes32.packStickersBulk(packId),
5600
- { body: { stickers: stickers.map(toStickerCreateBody) } }
5601
- );
5602
- return {
5603
- success: data.success.map(toStickerPayload),
5604
- failed: data.failed
5605
- };
5606
- }
5607
- /** Edit a sticker in a pack. */
5608
- async editSticker(packId, stickerId, options) {
5609
- const data = await this.client.rest.patch(Routes32.packSticker(packId, stickerId), {
5610
- body: toStickerEditBody(options)
5611
- });
5612
- return toStickerPayload(data);
5613
- }
5614
- /** Delete a sticker from a pack. */
5615
- async deleteSticker(packId, stickerId) {
5616
- await this.client.rest.delete(Routes32.packSticker(packId, stickerId));
5617
- }
5618
- };
5619
-
5620
6524
  // src/ClientCore/UserManager.ts
5621
- import { LimitedCollection as LimitedCollection5 } from "@fluxerjs/collection";
6525
+ import { LimitedCollection as LimitedCollection6 } from "@fluxerjs/collection";
5622
6526
  import {
5623
6527
  Routes as Routes33
5624
6528
  } from "@fluxerjs/types";
5625
6529
  var soft = (p) => p.catch(() => null);
5626
- var UserManager = class extends LimitedCollection5 {
6530
+ var UserManager = class extends LimitedCollection6 {
5627
6531
  constructor(client) {
5628
6532
  super({ maxSize: client.cache.limits.users });
5629
6533
  this.client = client;
@@ -5641,11 +6545,17 @@ var UserManager = class extends LimitedCollection5 {
5641
6545
  }
5642
6546
  return removed;
5643
6547
  }
5644
- /** Fetch a user by ID and update cache. */
5645
- async fetch(userId) {
6548
+ /** Fetch a user by ID and update cache. Returns cache unless `force` is set. */
6549
+ async fetch(userId, options) {
6550
+ const cached = this.get(userId);
6551
+ if (cached && !options?.force) return cached;
5646
6552
  const data = await this.client.rest.get(Routes33.user(userId));
5647
6553
  return this.client.getOrCreateUser(data);
5648
6554
  }
6555
+ /** Return a cached user, otherwise {@link fetch}. */
6556
+ async resolve(userId) {
6557
+ return this.get(userId) ?? this.fetch(userId);
6558
+ }
5649
6559
  /**
5650
6560
  * Fetch user + profiles (+ optional guild member). Ideal for userinfo commands.
5651
6561
  * @example
@@ -5705,14 +6615,22 @@ var Client = class _Client extends EventEmitter3 {
5705
6615
  users;
5706
6616
  /** Cache limits, stats, sweeps, and cascade entry points. */
5707
6617
  cache;
5708
- /** Emoji/sticker pack REST wrappers (`/packs/*`). */
5709
- packs = new PackManager(this);
5710
- /** Typed event handlers. Prefer `client.events.*` or `client.on(Events.*, ...)`. */
6618
+ /** Typed event handlers. Prefer `client.on(Events.*, ...)`. */
5711
6619
  events;
5712
6620
  /** The authenticated bot user. Null until READY is received. */
5713
6621
  user = null;
5714
6622
  /** Timestamp when the client became ready. Null until READY is received. */
5715
6623
  readyAt = null;
6624
+ /**
6625
+ * Milliseconds since {@link readyAt}, or `null` if the client is not ready.
6626
+ * @example
6627
+ * client.on(Events.Ready, () => {
6628
+ * console.log(client.uptime);
6629
+ * });
6630
+ */
6631
+ get uptime() {
6632
+ return this.readyAt ? Date.now() - this.readyAt.getTime() : null;
6633
+ }
5716
6634
  /** @internal WebSocket manager. */
5717
6635
  _ws = null;
5718
6636
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
@@ -5853,33 +6771,23 @@ var Client = class _Client extends EventEmitter3 {
5853
6771
  return fetchApplication(this);
5854
6772
  }
5855
6773
  /**
5856
- * Fetch OAuth2 applications owned by this bot.
5857
- * @returns Array of OAuth application objects
6774
+ * Fetch OAuth2 applications (`GET /oauth2/applications/@me`).
6775
+ * A bot token returns the bot application object (normalized to a one-element array).
6776
+ * A user token returns the owner's application list.
5858
6777
  */
5859
6778
  fetchOAuthApplications() {
5860
6779
  return fetchOAuthApplications(this);
5861
6780
  }
5862
- /**
5863
- * Check username#discriminator availability.
5864
- * @param username - Username to check
5865
- * @param discriminator - Discriminator to check
5866
- * @returns Availability result
5867
- */
5868
- checkUsernameTag(username, discriminator) {
5869
- return checkUsernameTag(this, username, discriminator);
5870
- }
5871
6781
  /**
5872
6782
  * Preload recent messages for multiple channels (batch endpoint).
5873
- * @param channelIds - Array of channel IDs to preload
5874
- * @returns Preload response with message counts/timestamps
6783
+ * Prefer this over {@link bulkFetchMessages} for bots (`bulkFetchMessages` is user-account only).
5875
6784
  */
5876
6785
  preloadMessages(channelIds) {
5877
6786
  return preloadMessages(this, channelIds);
5878
6787
  }
5879
6788
  /**
5880
6789
  * Preload recent messages (alternate endpoint).
5881
- * @param channelIds - Array of channel IDs to preload
5882
- * @returns Preload response with message counts/timestamps
6790
+ * Prefer this over {@link bulkFetchMessages} for bots.
5883
6791
  */
5884
6792
  preloadMessagesAlt(channelIds) {
5885
6793
  return preloadMessagesAlt(this, channelIds);
@@ -5887,6 +6795,14 @@ var Client = class _Client extends EventEmitter3 {
5887
6795
  bulkFetchMessages(requests, options = {}) {
5888
6796
  return bulkFetchMessages(this, requests, options);
5889
6797
  }
6798
+ /**
6799
+ * Search messages in the current bot scope (`POST /search/messages`, `scope: current`).
6800
+ * Other scopes are denied for bots (`BOT_SEARCH_SCOPE_UNAVAILABLE`).
6801
+ * Returns camelCase results (`hitsPerPage`) or `{ indexing: true }` while channels are indexed.
6802
+ */
6803
+ searchMessages(options) {
6804
+ return searchMessages(this, options);
6805
+ }
5890
6806
  /** @internal */
5891
6807
  _getMessageCache(channelId) {
5892
6808
  return this._messageCache.get(channelId);
@@ -5910,12 +6826,16 @@ var Client = class _Client extends EventEmitter3 {
5910
6826
  /**
5911
6827
  * Sweep cached messages (remove entries matching filter).
5912
6828
  * Prefer {@link CacheController.sweepMessages} (`client.cache.sweepMessages`).
6829
+ * The filter receives a hydrated {@link Message} (`createdAt`), not the stored wire payload.
5913
6830
  * @param filter - Predicate to test each message (return true to remove)
5914
6831
  * @param channelId - Optional channel ID to scope sweep
5915
6832
  * @returns Count of messages removed
5916
6833
  */
5917
6834
  sweepMessages(filter, channelId) {
5918
- return this._messageCache.sweep(filter, channelId);
6835
+ return this._messageCache.sweep(
6836
+ filter ? (data, chId) => filter(new Message(this, data), chId) : void 0,
6837
+ channelId
6838
+ );
5919
6839
  }
5920
6840
  /**
5921
6841
  * Sweep cached members across all guilds (remove entries matching filter).
@@ -5948,6 +6868,9 @@ var Client = class _Client extends EventEmitter3 {
5948
6868
  }
5949
6869
  /**
5950
6870
  * The underlying {@link WebSocketManager} (throws if not logged in).
6871
+ * Gateway heartbeat ACK latency: `client.ws.ping` (ms, or `-1` before the first ACK).
6872
+ * @example
6873
+ * console.log(client.ws.ping);
5951
6874
  * @throws {@link FluxerError} with {@link ErrorCodes.NotLoggedIn}
5952
6875
  */
5953
6876
  get ws() {
@@ -5986,6 +6909,37 @@ var Client = class _Client extends EventEmitter3 {
5986
6909
  if (options.nonce !== void 0) data.nonce = options.nonce;
5987
6910
  this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildMembers, d: data });
5988
6911
  }
6912
+ /**
6913
+ * Request guild member/online counts via gateway opcode 15.
6914
+ * Listen for `guildCountsUpdate`. Cached `guild.memberCount` / `guild.onlineCount` update when that event arrives.
6915
+ */
6916
+ requestGuildCounts(options) {
6917
+ const guildIds = [...new Set(options.guildIds.filter(Boolean))];
6918
+ if (!guildIds.length) {
6919
+ throw new FluxerError("requestGuildCounts requires at least one guildId", {
6920
+ code: ErrorCodes.InvalidGatewayRequest
6921
+ });
6922
+ }
6923
+ const data = { guild_ids: guildIds };
6924
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6925
+ this._sendToAllShards({ op: GatewayOpcodes2.RequestGuildCounts, d: data });
6926
+ }
6927
+ /**
6928
+ * Request per-channel member counts via gateway opcode 16.
6929
+ * Event-only: listen for `channelMemberCountsUpdate`. There is no `channel.memberCount` field.
6930
+ */
6931
+ requestChannelMemberCounts(options) {
6932
+ if (!options.guildId) {
6933
+ throw new FluxerError("requestChannelMemberCounts requires guildId", {
6934
+ code: ErrorCodes.InvalidGatewayRequest
6935
+ });
6936
+ }
6937
+ const data = { guild_id: options.guildId };
6938
+ if (options.channelId !== void 0) data.channel_id = options.channelId;
6939
+ if (options.channelIds !== void 0) data.channel_ids = [...new Set(options.channelIds)];
6940
+ if (options.nonce !== void 0) data.nonce = options.nonce;
6941
+ this._sendToAllShards({ op: GatewayOpcodes2.RequestChannelMemberCounts, d: data });
6942
+ }
5989
6943
  /**
5990
6944
  * Broadcast a gateway payload to all shards.
5991
6945
  * @param payload - Gateway send payload
@@ -5999,9 +6953,13 @@ var Client = class _Client extends EventEmitter3 {
5999
6953
  }
6000
6954
  /**
6001
6955
  * Connect to the gateway with a bot token.
6956
+ * @example
6957
+ * const client = new Client();
6958
+ * client.on(Events.Ready, () => console.log('Ready!'));
6959
+ * await client.login(process.env.FLUXER_BOT_TOKEN);
6002
6960
  * @param token - Bot token from the developer portal
6003
6961
  * @param options - Optional abort signal for cancellation
6004
- * @returns The token that was used (echo)
6962
+ * @returns This client (for chaining)
6005
6963
  * @throws {@link FluxerError} if already logged in or token is invalid
6006
6964
  */
6007
6965
  async login(token, options) {
@@ -6016,7 +6974,7 @@ var Client = class _Client extends EventEmitter3 {
6016
6974
  this.rest.setToken(token);
6017
6975
  try {
6018
6976
  this._ws = await connectClientGateway(this, token, options?.signal);
6019
- return token;
6977
+ return this;
6020
6978
  } catch (err) {
6021
6979
  this._ws?.destroy();
6022
6980
  this._ws = null;
@@ -6069,6 +7027,20 @@ var Client = class _Client extends EventEmitter3 {
6069
7027
  );
6070
7028
  }
6071
7029
  }
7030
+ /**
7031
+ * REST path helpers ({@link Routes}). Pass the path to {@link REST client.rest}.
7032
+ * Prefer high-level helpers (`channel.send()`, `guild.members.fetch()`) when they exist.
7033
+ *
7034
+ * @example
7035
+ * const channel = await client.rest.get(Client.Routes.channel(channelId));
7036
+ *
7037
+ * @example
7038
+ * await client.rest.post(Client.Routes.channelMessages(channelId), {
7039
+ * body: { content: 'hello' },
7040
+ * });
7041
+ *
7042
+ * @see {@link Routes}
7043
+ */
6072
7044
  static get Routes() {
6073
7045
  return Routes34;
6074
7046
  }