@fluxerjs/core 1.4.0 → 2.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/message.js CHANGED
@@ -24,18 +24,25 @@ __export(subpath_message_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(subpath_message_exports);
26
26
 
27
- // src/structures/Base.ts
28
- var Base = class {
29
- };
30
-
31
- // src/structures/Message.ts
27
+ // src/structures/message/Message.ts
32
28
  var import_collection2 = require("@fluxerjs/collection");
33
- var import_types2 = require("@fluxerjs/types");
34
- var import_builders2 = require("@fluxerjs/builders");
29
+ var import_builders3 = require("@fluxerjs/builders");
30
+ var import_types5 = require("@fluxerjs/types");
35
31
 
36
- // src/util/messageUtils.ts
37
- var import_types = require("@fluxerjs/types");
38
- var import_builders = require("@fluxerjs/builders");
32
+ // src/client/sdkOptions.ts
33
+ function toMessageAttachmentEditWire(attachments) {
34
+ return attachments.map((a) => {
35
+ const out = { id: a.id };
36
+ if (a.filename !== void 0) out.filename = a.filename;
37
+ if (a.uploadFilename !== void 0) out.upload_filename = a.uploadFilename;
38
+ if (a.fileSize !== void 0) out.file_size = a.fileSize;
39
+ if (a.contentType !== void 0) out.content_type = a.contentType;
40
+ if (a.title !== void 0) out.title = a.title;
41
+ if (a.description !== void 0) out.description = a.description;
42
+ if (a.flags !== void 0) out.flags = a.flags;
43
+ return out;
44
+ });
45
+ }
39
46
 
40
47
  // src/errors/ErrorCodes.ts
41
48
  var import_util = require("@fluxerjs/util");
@@ -43,8 +50,30 @@ var import_util = require("@fluxerjs/util");
43
50
  // src/errors/FluxerError.ts
44
51
  var import_util2 = require("@fluxerjs/util");
45
52
 
46
- // src/util/messageUtils.ts
53
+ // src/util/messageUtils/files.ts
47
54
  var FILE_FETCH_TIMEOUT_MS = 3e4;
55
+ async function fetchFileBuffer(url, index) {
56
+ if (!URL.canParse(url)) {
57
+ throw new import_util2.FluxerError(`Invalid file URL at index ${index}: ${url}`, {
58
+ code: import_util.ErrorCodes.InvalidFileUrl
59
+ });
60
+ }
61
+ let res;
62
+ try {
63
+ res = await fetch(url, { signal: AbortSignal.timeout(FILE_FETCH_TIMEOUT_MS) });
64
+ } catch (err) {
65
+ throw new import_util2.FluxerError(`Failed to fetch file from ${url}`, {
66
+ code: import_util.ErrorCodes.FileFetchFailed,
67
+ cause: err instanceof Error ? err : void 0
68
+ });
69
+ }
70
+ if (!res.ok) {
71
+ throw new import_util2.FluxerError(`Failed to fetch file from ${url}: ${res.status} ${res.statusText}`, {
72
+ code: import_util.ErrorCodes.FileFetchFailed
73
+ });
74
+ }
75
+ return res.arrayBuffer();
76
+ }
48
77
  async function resolveMessageFiles(files) {
49
78
  const result = [];
50
79
  for (let i = 0; i < files.length; i++) {
@@ -52,32 +81,7 @@ async function resolveMessageFiles(files) {
52
81
  if (!f) continue;
53
82
  const filename = f.filename ?? f.name;
54
83
  if ("url" in f && f.url) {
55
- if (!URL.canParse(f.url)) {
56
- throw new import_util2.FluxerError(`Invalid file URL at index ${i}: ${f.url}`, {
57
- code: import_util.ErrorCodes.InvalidFileUrl
58
- });
59
- }
60
- let res;
61
- try {
62
- res = await fetch(f.url, {
63
- signal: AbortSignal.timeout(FILE_FETCH_TIMEOUT_MS)
64
- });
65
- } catch (err) {
66
- throw new import_util2.FluxerError(`Failed to fetch file from ${f.url}`, {
67
- code: import_util.ErrorCodes.FileFetchFailed,
68
- cause: err instanceof Error ? err : void 0
69
- });
70
- }
71
- if (!res.ok) {
72
- throw new import_util2.FluxerError(
73
- `Failed to fetch file from ${f.url}: ${res.status} ${res.statusText}`,
74
- {
75
- code: import_util.ErrorCodes.FileFetchFailed
76
- }
77
- );
78
- }
79
- const data = await res.arrayBuffer();
80
- result.push({ name: f.name, data, filename });
84
+ result.push({ name: f.name, data: await fetchFileBuffer(f.url, i), filename });
81
85
  } else if ("data" in f && f.data != null) {
82
86
  result.push({ name: f.name, data: f.data, filename });
83
87
  } else {
@@ -88,74 +92,141 @@ async function resolveMessageFiles(files) {
88
92
  }
89
93
  return result;
90
94
  }
95
+
96
+ // src/util/messageUtils/body.ts
97
+ var import_types = require("@fluxerjs/types");
98
+ var import_builders = require("@fluxerjs/builders");
91
99
  function toAPIAllowedMentions(options) {
92
100
  const result = {};
93
- if (options.parse?.length) result.parse = options.parse;
101
+ if (options.parse !== void 0) result.parse = options.parse;
94
102
  if (options.users?.length) result.users = options.users;
95
103
  if (options.roles?.length) result.roles = options.roles;
96
104
  if (options.repliedUser !== void 0) result.replied_user = options.repliedUser;
97
105
  return result;
98
106
  }
99
107
  function applyReplyPingSuppression(body) {
100
- body.flags = (body.flags ?? 0) | import_types.MessageFlags.SuppressNotifications;
101
108
  body.allowed_mentions = {
102
109
  ...body.allowed_mentions ?? {},
103
110
  replied_user: false
104
111
  };
105
112
  }
113
+ function assignIfDefined(target, key, value) {
114
+ if (value !== void 0) target[key] = value;
115
+ }
106
116
  function buildSendBody(options) {
107
117
  const body = typeof options === "string" ? { content: options } : options;
108
118
  const result = {};
109
- if (body.content !== void 0) result.content = body.content;
119
+ assignIfDefined(result, "content", body.content);
110
120
  if (body.embeds?.length) {
111
121
  result.embeds = body.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
112
122
  }
113
- if (body.files?.length && body.attachments) {
114
- result.attachments = body.attachments.map((a) => ({
123
+ if (body.uploadedAttachments?.length) {
124
+ result.attachments = body.uploadedAttachments;
125
+ } else if (body.files?.length) {
126
+ result.attachments = body.attachments?.length ? body.attachments.map((a) => ({
115
127
  id: a.id,
116
128
  filename: a.filename,
117
129
  ...a.title != null && { title: a.title },
118
130
  ...a.description != null && { description: a.description },
119
131
  ...a.flags != null && { flags: a.flags }
120
- }));
121
- } else if (body.files?.length) {
122
- result.attachments = body.files.map((f, i) => ({
123
- id: i,
124
- filename: f.filename ?? f.name
125
- }));
132
+ })) : body.files.map((f, i) => ({ id: i, filename: f.filename ?? f.name }));
126
133
  }
127
134
  if (body.allowedMentions) result.allowed_mentions = toAPIAllowedMentions(body.allowedMentions);
128
135
  if (body.stickerIds?.length) result.sticker_ids = body.stickerIds;
129
- if (body.nonce !== void 0) result.nonce = body.nonce;
130
- if (body.favoriteMemeId !== void 0) result.favorite_meme_id = body.favoriteMemeId;
131
- if (body.tts !== void 0) result.tts = body.tts;
132
- if (body.flags !== void 0) result.flags = body.flags;
136
+ assignIfDefined(result, "nonce", body.nonce);
137
+ assignIfDefined(result, "favorite_meme_id", body.favoriteMemeId);
138
+ assignIfDefined(result, "tts", body.tts);
139
+ assignIfDefined(result, "flags", body.flags);
133
140
  return result;
134
141
  }
135
- function toMessageReference(target) {
142
+ function toMessageReference(target, forceForward = false) {
136
143
  const ref = {
137
144
  channel_id: target.channelId,
138
145
  message_id: target.messageId
139
146
  };
140
- if (target.guildId != null && target.guildId !== "") ref.guild_id = target.guildId;
147
+ if (target.guildId) ref.guild_id = target.guildId;
148
+ const type = forceForward ? import_types.MessageReferenceType.Forward : target.type ?? import_types.MessageReferenceType.Default;
149
+ if (type !== import_types.MessageReferenceType.Default) ref.type = type;
150
+ if (target.attachmentIds?.length) ref.attachment_ids = target.attachmentIds;
151
+ if (target.embedIndices?.length) ref.embed_indices = target.embedIndices;
141
152
  return ref;
142
153
  }
143
- async function prepareMessagePostPayload(options) {
144
- if (typeof options === "string") {
145
- if (options.length === 0) throw new RangeError("Cannot send an empty message");
146
- options = { content: options };
147
- }
148
- const { replyTo, ping, files, allowedMentions, ...sendFields } = options;
149
- const body = buildSendBody({ ...sendFields, files, allowedMentions });
150
- if (replyTo) {
154
+ function shouldSuppressReplyPing(ping, allowedMentions, body) {
155
+ return ping === false || allowedMentions?.repliedUser === false || body.allowed_mentions?.replied_user === false;
156
+ }
157
+ function messagePayloadToSendOptions(payload) {
158
+ const json = payload.toJSON();
159
+ const options = {};
160
+ if (json.content != null) options.content = json.content;
161
+ if (json.embeds?.length) options.embeds = json.embeds;
162
+ if (json.tts !== void 0) options.tts = json.tts;
163
+ if (json.flags !== void 0) options.flags = json.flags;
164
+ if (json.allowed_mentions) {
165
+ options.allowedMentions = {
166
+ parse: json.allowed_mentions.parse,
167
+ users: json.allowed_mentions.users,
168
+ roles: json.allowed_mentions.roles,
169
+ repliedUser: json.allowed_mentions.replied_user
170
+ };
171
+ }
172
+ if (json.message_reference?.channel_id && json.message_reference.message_id) {
173
+ options.replyTo = {
174
+ channelId: json.message_reference.channel_id,
175
+ messageId: json.message_reference.message_id,
176
+ guildId: json.message_reference.guild_id
177
+ };
178
+ }
179
+ if (json.attachments?.length) {
180
+ options.attachments = json.attachments.map((a) => ({
181
+ id: a.id,
182
+ filename: a.filename,
183
+ description: a.description ?? void 0
184
+ }));
185
+ }
186
+ return options;
187
+ }
188
+ async function prepareMessagePostPayload(options, defaults) {
189
+ let normalized = options instanceof import_builders.MessagePayload ? messagePayloadToSendOptions(options) : options;
190
+ if (typeof normalized === "string") {
191
+ if (normalized.length === 0) {
192
+ throw new import_util2.FluxerError("Cannot send an empty message", { code: import_util.ErrorCodes.EmptyMessage });
193
+ }
194
+ normalized = { content: normalized };
195
+ } else {
196
+ normalized = { ...normalized };
197
+ if (!normalized.allowedMentions && defaults?.defaultAllowedMentions) {
198
+ normalized.allowedMentions = defaults.defaultAllowedMentions;
199
+ }
200
+ }
201
+ const { replyTo, forward, ping, files, allowedMentions, uploadedAttachments, ...sendFields } = normalized;
202
+ if (files?.length && uploadedAttachments?.length) {
203
+ throw new import_util2.FluxerError("Cannot combine multipart files with uploadedAttachments", {
204
+ code: import_util.ErrorCodes.InvalidMessageOptions
205
+ });
206
+ }
207
+ if (replyTo && forward) {
208
+ throw new import_util2.FluxerError("Cannot combine replyTo and forward", {
209
+ code: import_util.ErrorCodes.InvalidMessageOptions
210
+ });
211
+ }
212
+ const body = buildSendBody({ ...sendFields, files, allowedMentions, uploadedAttachments });
213
+ if (forward) {
214
+ if (!forward.channelId || !forward.messageId) {
215
+ throw new import_util2.FluxerError("forward requires channelId and messageId", {
216
+ code: import_util.ErrorCodes.InvalidMessageOptions
217
+ });
218
+ }
219
+ body.message_reference = toMessageReference(forward, true);
220
+ } else if (replyTo) {
151
221
  body.message_reference = toMessageReference(replyTo);
152
- const suppressPing = ping === false || allowedMentions?.repliedUser === false || body.allowed_mentions?.replied_user === false;
153
- if (suppressPing) applyReplyPingSuppression(body);
222
+ if (shouldSuppressReplyPing(ping, allowedMentions, body)) applyReplyPingSuppression(body);
154
223
  } else if (allowedMentions?.repliedUser === false) {
155
224
  applyReplyPingSuppression(body);
156
225
  }
157
- const resolvedFiles = files?.length ? await resolveMessageFiles(files) : void 0;
158
- return { body, files: resolvedFiles };
226
+ return {
227
+ body,
228
+ files: !uploadedAttachments?.length && files?.length ? await resolveMessageFiles(files) : void 0
229
+ };
159
230
  }
160
231
 
161
232
  // src/util/ReactionCollector.ts
@@ -170,18 +241,20 @@ var Events = {
170
241
  MessageDelete: "messageDelete",
171
242
  MessageDeleteBulk: "messageDeleteBulk",
172
243
  MessageReactionAdd: "messageReactionAdd",
244
+ MessageReactionAddMany: "messageReactionAddMany",
173
245
  MessageReactionRemove: "messageReactionRemove",
174
246
  MessageReactionRemoveAll: "messageReactionRemoveAll",
175
247
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
176
- InteractionCreate: "interactionCreate",
177
248
  GuildCreate: "guildCreate",
178
249
  GuildUpdate: "guildUpdate",
179
250
  GuildDelete: "guildDelete",
180
251
  GuildBanAdd: "guildBanAdd",
181
252
  GuildBanRemove: "guildBanRemove",
253
+ GuildAuditLogEntryCreate: "guildAuditLogEntryCreate",
182
254
  GuildEmojisUpdate: "guildEmojisUpdate",
183
255
  GuildStickersUpdate: "guildStickersUpdate",
184
- GuildIntegrationsUpdate: "guildIntegrationsUpdate",
256
+ GuildCountsUpdate: "guildCountsUpdate",
257
+ ChannelMemberCountsUpdate: "channelMemberCountsUpdate",
185
258
  GuildMemberAdd: "guildMemberAdd",
186
259
  GuildMemberUpdate: "guildMemberUpdate",
187
260
  GuildMemberRemove: "guildMemberRemove",
@@ -189,9 +262,6 @@ var Events = {
189
262
  GuildRoleCreate: "guildRoleCreate",
190
263
  GuildRoleUpdate: "guildRoleUpdate",
191
264
  GuildRoleDelete: "guildRoleDelete",
192
- GuildScheduledEventCreate: "guildScheduledEventCreate",
193
- GuildScheduledEventUpdate: "guildScheduledEventUpdate",
194
- GuildScheduledEventDelete: "guildScheduledEventDelete",
195
265
  ChannelCreate: "channelCreate",
196
266
  ChannelUpdate: "channelUpdate",
197
267
  ChannelDelete: "channelDelete",
@@ -200,9 +270,14 @@ var Events = {
200
270
  InviteDelete: "inviteDelete",
201
271
  TypingStart: "typingStart",
202
272
  UserUpdate: "userUpdate",
273
+ UserConnectionsUpdate: "userConnectionsUpdate",
274
+ WebAuthnCredentialsUpdate: "webauthnCredentialsUpdate",
203
275
  PresenceUpdate: "presenceUpdate",
276
+ PresenceUpdateBulk: "presenceUpdateBulk",
204
277
  VoiceStateUpdate: "voiceStateUpdate",
278
+ VoiceStateAck: "voiceStateAck",
205
279
  VoiceServerUpdate: "voiceServerUpdate",
280
+ EntranceSoundPlay: "entranceSoundPlay",
206
281
  VoiceStatesSync: "voiceStatesSync",
207
282
  WebhooksUpdate: "webhooksUpdate",
208
283
  Resumed: "resumed",
@@ -230,12 +305,14 @@ var ReactionCollector = class extends import_events.EventEmitter {
230
305
  time: options.time ?? 0,
231
306
  max: options.max ?? 0
232
307
  };
233
- this._listener = (reaction, user, _msgId, chId, _emoji, userId) => {
234
- if (this._ended || reaction.messageId !== this.messageId || chId !== this.channelId) return;
235
- if (!this.options.filter(reaction, user)) return;
236
- const key = `${userId}:${reaction.emoji.id ?? reaction.emoji.name}`;
237
- this.collected.set(key, { reaction, user });
238
- this.emit("collect", reaction, user);
308
+ this._listener = (payload) => {
309
+ if (this._ended || payload.reaction.messageId !== this.messageId || payload.channelId !== this.channelId) {
310
+ return;
311
+ }
312
+ if (!this.options.filter(payload.reaction, payload.user)) return;
313
+ const key = `${payload.userId}:${payload.reaction.emoji.id ?? payload.reaction.emoji.name}`;
314
+ this.collected.set(key, { reaction: payload.reaction, user: payload.user });
315
+ this.emit("collect", payload.reaction, payload.user);
239
316
  if (this.options.max > 0 && this.collected.size >= this.options.max) {
240
317
  this.stop("limit");
241
318
  }
@@ -263,64 +340,199 @@ var ReactionCollector = class extends import_events.EventEmitter {
263
340
  }
264
341
  };
265
342
 
266
- // src/structures/Message.ts
343
+ // src/structures/Base.ts
344
+ var Base = class {
345
+ };
346
+
347
+ // src/structures/message/reactions.ts
348
+ var import_types3 = require("@fluxerjs/types");
349
+ async function emojiPath(message, emoji) {
350
+ return message.client.resolveEmoji(emoji, message.guildId);
351
+ }
352
+ async function reactToMessage(message, emoji) {
353
+ const e = await emojiPath(message, emoji);
354
+ await message.client.rest.put(import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e));
355
+ }
356
+ async function removeMessageReaction(message, emoji, userId) {
357
+ const e = await emojiPath(message, emoji);
358
+ const route = userId ? import_types3.Routes.channelMessageReactionUser(message.channelId, message.id, e, userId) : import_types3.Routes.channelMessageReactionMe(message.channelId, message.id, e);
359
+ await message.client.rest.delete(route);
360
+ }
361
+ async function removeAllMessageReactions(message) {
362
+ await message.client.rest.delete(import_types3.Routes.channelMessageReactions(message.channelId, message.id));
363
+ }
364
+ async function removeMessageReactionEmoji(message, emoji) {
365
+ const e = await emojiPath(message, emoji);
366
+ await message.client.rest.delete(import_types3.Routes.channelMessageReaction(message.channelId, message.id, e));
367
+ }
368
+ async function fetchMessageReactionUsers(message, emoji, options) {
369
+ return (await fetchMessageReactionUsersPage(message, emoji, options)).users;
370
+ }
371
+ async function fetchMessageReactionUsersPage(message, emoji, options) {
372
+ const e = await emojiPath(message, emoji);
373
+ const params = new URLSearchParams();
374
+ if (options?.limit != null) params.set("limit", String(options.limit));
375
+ if (options?.after) params.set("after", options.after);
376
+ const qs = params.toString();
377
+ const route = import_types3.Routes.channelMessageReactionUsers(message.channelId, message.id, e) + (qs ? `?${qs}` : "");
378
+ const data = await message.client.rest.get(route);
379
+ if (Array.isArray(data)) {
380
+ return {
381
+ users: data.map((u) => message.client.getOrCreateUser(u)),
382
+ hasMore: false,
383
+ nextAfter: null
384
+ };
385
+ }
386
+ const list = data.items ?? data.users ?? [];
387
+ return {
388
+ users: list.map((u) => message.client.getOrCreateUser(u)),
389
+ hasMore: data.has_more ?? false,
390
+ nextAfter: data.next_after ?? null
391
+ };
392
+ }
393
+
394
+ // src/structures/message/send.ts
395
+ var import_builders2 = require("@fluxerjs/builders");
396
+ var import_types4 = require("@fluxerjs/types");
397
+ function toReplyTarget(ref) {
398
+ return {
399
+ channelId: ref.channel_id,
400
+ messageId: ref.message_id,
401
+ ...ref.guild_id != null ? { guildId: ref.guild_id } : {}
402
+ };
403
+ }
404
+ function toSendOptions(content) {
405
+ if (typeof content === "string") return { content };
406
+ if (content instanceof import_builders2.MessagePayload) return messagePayloadToSendOptions(content);
407
+ return { ...content };
408
+ }
409
+ async function createMessageBody(content, referenced_message, ping) {
410
+ if (typeof content === "string" && content.length === 0) {
411
+ throw new import_util2.FluxerError("Cannot send an empty message", { code: import_util.ErrorCodes.EmptyMessage });
412
+ }
413
+ const opts = toSendOptions(content);
414
+ if (referenced_message) {
415
+ opts.replyTo = toReplyTarget(referenced_message);
416
+ if (ping !== void 0) opts.ping = ping;
417
+ }
418
+ return prepareMessagePostPayload(opts);
419
+ }
420
+ function asReplyTarget(value) {
421
+ if ("messageId" in value) return value;
422
+ return {
423
+ channelId: value.channelId,
424
+ messageId: value.id,
425
+ guildId: value.guildId
426
+ };
427
+ }
428
+ async function sendPrepared(message, payload) {
429
+ const data = await message.client.rest.post(
430
+ import_types4.Routes.channelMessages(message.channelId),
431
+ payload
432
+ );
433
+ message.client._addMessageToCache(message.channelId, data);
434
+ return new message.constructor(message.client, data);
435
+ }
436
+ async function sendMessage(message, options) {
437
+ return message._send(
438
+ await prepareMessagePostPayload(options, {
439
+ defaultAllowedMentions: message.client.options.defaultAllowedMentions
440
+ })
441
+ );
442
+ }
443
+ async function sendMessageTo(message, channelId, options) {
444
+ return message.client.channels.send(channelId, options);
445
+ }
446
+ async function replyToMessage(message, options, replyOptions) {
447
+ const opts = typeof options === "string" ? { content: options } : { ...options };
448
+ const { replyTo: inlineReplyTo, ping: inlinePing, ...sendOpts } = opts;
449
+ const ping = replyOptions?.ping ?? inlinePing ?? message.client.options.defaultReplyPing;
450
+ const replyTo = asReplyTarget(replyOptions?.replyTo ?? inlineReplyTo ?? message);
451
+ return message._send(
452
+ await prepareMessagePostPayload(
453
+ { ...sendOpts, replyTo, ping },
454
+ { defaultAllowedMentions: message.client.options.defaultAllowedMentions }
455
+ )
456
+ );
457
+ }
458
+
459
+ // src/structures/message/Message.ts
267
460
  var Message = class _Message extends Base {
461
+ /** The {@link Client} that instantiated this message. */
268
462
  client;
463
+ /** Snowflake ID of this message. */
269
464
  id;
465
+ /** Channel ID where this message was sent. */
270
466
  channelId;
467
+ /** Guild ID if in a guild channel, null for DMs. */
271
468
  guildId;
469
+ /** The user who sent this message. */
272
470
  author;
471
+ /** Text content of the message. */
273
472
  content;
473
+ /** When the message was created. */
274
474
  createdAt;
475
+ /** When the message was last edited, or null if never edited. */
275
476
  editedAt;
477
+ /** Whether the message is pinned. */
276
478
  pinned;
479
+ /** Attached files (images, videos, etc.). */
277
480
  attachments;
481
+ /** Message type (Default, Reply, etc.). */
278
482
  type;
483
+ /** Message flags bitfield. */
279
484
  flags;
485
+ /** Whether `@everyone` or `@here` was mentioned. */
280
486
  mentionEveryone;
487
+ /** Whether this is a text-to-speech message. */
281
488
  tts;
489
+ /** Embedded content (rich previews, etc.). */
282
490
  embeds;
491
+ /** Stickers sent with the message. */
283
492
  stickers;
493
+ /** Reactions on the message. */
284
494
  reactions;
495
+ /** Reference to a replied-to message, if any. */
285
496
  messageReference;
497
+ /** Message snapshots for forwarded messages. */
286
498
  messageSnapshots;
499
+ /** Call data if this message represents a call event. */
287
500
  call;
501
+ /** The full referenced (replied-to) message, or null. */
288
502
  referencedMessage;
289
- /** Webhook ID if this message was sent via webhook. Null otherwise. */
503
+ /** Webhook ID if sent by a webhook. */
290
504
  webhookId;
291
- /** Users mentioned in this message. */
505
+ /** Users mentioned in the message. */
292
506
  mentions;
293
- /** Role IDs mentioned in this message. */
507
+ /** Role IDs mentioned in the message. */
294
508
  mentionRoles;
295
- /** Client-side nonce for acknowledgment. Null if not provided. */
509
+ /** Client-side nonce for deduplication. */
296
510
  nonce;
297
- /**
298
- * Channel where this message was sent. Resolved from cache; null if not cached.
299
- * Messages can only exist in text-based channels (text, DM, announcement), so this always has send() when non-null.
300
- */
511
+ /** Cached text/DM/guild channel, or null if uncached. */
301
512
  get channel() {
302
513
  return this.client.channels.get(this.channelId) ?? null;
303
514
  }
304
- /** Guild where this message was sent. Resolved from cache; null for DMs or if not cached. */
515
+ /** Cached guild, or null for DMs / uncached. */
305
516
  get guild() {
306
517
  return this.guildId ? this.client.guilds.get(this.guildId) ?? null : null;
307
518
  }
308
- /**
309
- * Resolve the channel (from cache or API). Use when you need the channel and it may not be cached.
310
- * @returns The channel
311
- * @throws FluxerError with CHANNEL_NOT_FOUND if the channel does not exist
312
- */
519
+ /** Fetch and resolve the channel this message is in. */
313
520
  async resolveChannel() {
314
521
  return this.client.channels.resolve(this.channelId);
315
522
  }
316
- /**
317
- * Resolve the guild (from cache or API). Returns null for DMs.
318
- * @returns The guild, or null if this is a DM or guild not found
319
- */
523
+ /** Fetch and resolve the guild, or null if a DM. */
320
524
  async resolveGuild() {
321
- return this.guildId ? this.client.guilds.resolve(this.guildId) : null;
525
+ if (!this.guildId) return null;
526
+ try {
527
+ return await this.client.guilds.resolve(this.guildId);
528
+ } catch {
529
+ return null;
530
+ }
322
531
  }
323
- /** @param data - API message from POST/PATCH /channels/{id}/messages or gateway MESSAGE_CREATE */
532
+ /**
533
+ * Construct a message from API data.
534
+ * @param data - API message from REST or MESSAGE_CREATE
535
+ */
324
536
  constructor(client, data) {
325
537
  super();
326
538
  this.client = client;
@@ -334,7 +546,7 @@ var Message = class _Message extends Base {
334
546
  this.pinned = data.pinned;
335
547
  this.attachments = new import_collection2.Collection();
336
548
  for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
337
- this.type = data.type ?? import_types2.MessageType.Default;
549
+ this.type = data.type ?? import_types5.MessageType.Default;
338
550
  this.flags = data.flags ?? 0;
339
551
  this.mentionEveryone = data.mention_everyone ?? false;
340
552
  this.tts = data.tts ?? false;
@@ -350,220 +562,109 @@ var Message = class _Message extends Base {
350
562
  this.mentionRoles = data.mention_roles ?? [];
351
563
  this.nonce = data.nonce ?? null;
352
564
  }
353
- /**
354
- * Send a message to this channel without replying. Use when you want a standalone message.
355
- * @param options - Text content or object with content, embeds, and/or files
356
- * @example
357
- * await message.send('Pong!');
358
- * await message.send({ embeds: [embed] }); // EmbedBuilder auto-converted
359
- * await message.send({ content: 'File', files: [{ name: 'data.txt', data }] });
360
- */
565
+ /** Send a message in this channel without replying. */
361
566
  async send(options) {
362
- const payload = await prepareMessagePostPayload(options);
363
- return this._send(payload);
567
+ return sendMessage(this, options);
364
568
  }
365
- /**
366
- * Send a message to a specific channel. Use for logging, forwarding, or sending to another channel in the guild.
367
- * @param channelId - Snowflake of the target channel (e.g. log channel ID)
368
- * @param options - Text content or object with content and/or embeds
369
- * @example
370
- * await message.sendTo(logChannelId, 'User ' + message.author.username + ' said: ' + message.content);
371
- * await message.sendTo(announceChannelId, { embeds: [embed] });
372
- */
569
+ /** Send a message to another channel by ID. */
373
570
  async sendTo(channelId, options) {
374
- return this.client.channels.send(channelId, options);
571
+ return sendMessageTo(this, channelId, options);
375
572
  }
376
573
  /**
377
- * Reply to this message (shows as a reply in the client).
378
- * @param options - Text content or object with content, embeds, and/or reply options (ping, replyTo)
574
+ * Reply to this message.
379
575
  * @example
380
576
  * await message.reply('Pong!');
381
- * await message.reply({ embeds: [embed] });
382
577
  * await message.reply('No ping!', { ping: false });
383
- * await message.reply({ content: 'Silent reply', allowedMentions: AllowedMentions.suppressReplyPing });
384
- * await message.reply({ content: 'Reply to other', replyTo: otherMessage });
578
+ * await message.reply({ content: 'Silent', allowedMentions: AllowedMentions.suppressReplyPing });
385
579
  */
386
580
  async reply(options, replyOptions) {
387
- const opts = typeof options === "string" ? { content: options } : options;
388
- const mergedReply = replyOptions ?? (opts.ping !== void 0 || opts.replyTo !== void 0) ? { ping: opts.ping, replyTo: opts.replyTo } : void 0;
389
- const refMessage = mergedReply?.replyTo ?? this;
390
- const replyTo = refMessage instanceof _Message ? {
391
- channelId: refMessage.channelId,
392
- messageId: refMessage.id,
393
- guildId: refMessage.guildId
394
- } : refMessage;
395
- const { replyTo: _ignored, ping: _ping, ...sendOpts } = opts;
396
- const payload = await prepareMessagePostPayload({
397
- ...sendOpts,
398
- replyTo,
399
- ping: mergedReply?.ping
400
- });
401
- return this._send(payload);
581
+ return replyToMessage(this, options, replyOptions);
402
582
  }
403
- /** Exposed for testing — prefer `message.reply()` / `prepareMessagePostPayload()`. */
583
+ /** Test helper — prefer {@link reply} / `prepareMessagePostPayload()`. */
404
584
  static async _createMessageBody(content, referenced_message, ping) {
405
- if (typeof content === "string" && content.length === 0) {
406
- throw new RangeError("Cannot send an empty message");
407
- }
408
- if (typeof content === "string") {
409
- const opts2 = { content };
410
- if (referenced_message) {
411
- opts2.replyTo = {
412
- channelId: referenced_message.channel_id,
413
- messageId: referenced_message.message_id,
414
- ...referenced_message.guild_id != null ? { guildId: referenced_message.guild_id } : {}
415
- };
416
- if (ping !== void 0) opts2.ping = ping;
417
- }
418
- return prepareMessagePostPayload(opts2);
419
- }
420
- const opts = { ...content };
421
- if (referenced_message) {
422
- opts.replyTo = {
423
- channelId: referenced_message.channel_id,
424
- messageId: referenced_message.message_id,
425
- ...referenced_message.guild_id != null ? { guildId: referenced_message.guild_id } : {}
426
- };
427
- if (ping !== void 0) opts.ping = ping;
428
- }
429
- return prepareMessagePostPayload(opts);
585
+ return createMessageBody(content, referenced_message, ping);
430
586
  }
587
+ /** Send a prepared payload (internal helper). */
431
588
  async _send(payload) {
432
- const data = await this.client.rest.post(
433
- import_types2.Routes.channelMessages(this.channelId),
434
- payload
435
- );
436
- this.client._addMessageToCache(this.channelId, data);
437
- return new _Message(this.client, data);
589
+ return sendPrepared(this, payload);
438
590
  }
439
- /**
440
- * Edit this message. Only the author (or admins) can edit.
441
- * @param options - New content and/or embeds
442
- */
591
+ /** Edit this message (requires author or admin permissions). */
443
592
  async edit(options) {
444
593
  const body = {};
445
594
  if (options.content !== void 0) body.content = options.content;
446
595
  if (options.embeds?.length) {
447
- body.embeds = options.embeds.map((e) => e instanceof import_builders2.EmbedBuilder ? e.toJSON() : e);
596
+ body.embeds = options.embeds.map(
597
+ (e) => e instanceof import_builders3.EmbedBuilder ? e.toJSON() : e
598
+ );
448
599
  }
449
600
  if (options.allowedMentions) {
450
601
  body.allowed_mentions = toAPIAllowedMentions(options.allowedMentions);
451
602
  }
452
- const data = await this.client.rest.patch(import_types2.Routes.channelMessage(this.channelId, this.id), {
603
+ if (options.flags !== void 0) body.flags = options.flags;
604
+ if (options.attachments !== void 0) {
605
+ body.attachments = toMessageAttachmentEditWire(options.attachments);
606
+ }
607
+ const data = await this.client.rest.patch(import_types5.Routes.channelMessage(this.channelId, this.id), {
453
608
  body
454
609
  });
455
- return new _Message(this.client, data);
610
+ const updated = new _Message(this.client, data);
611
+ this.client._addMessageToCache(this.channelId, data);
612
+ return updated;
456
613
  }
457
- /**
458
- * Create a reaction collector for this message.
459
- * Collects reactions matching the filter until time expires or max is reached.
460
- * @param options - Filter, time (ms), and max count
461
- * @example
462
- * const collector = message.createReactionCollector({ filter: (r, u) => u.id === userId, time: 10000 });
463
- * collector.on('collect', (reaction, user) => console.log(user.username, 'reacted with', reaction.emoji.name));
464
- * collector.on('end', (collected, reason) => { ... });
465
- */
614
+ /** Create a {@link ReactionCollector} for this message. */
466
615
  createReactionCollector(options) {
467
616
  return new ReactionCollector(this.client, this.id, this.channelId, options);
468
617
  }
469
- /**
470
- * Re-fetch this message from the API to get the latest content, embeds, reactions, etc.
471
- * Use when you have a stale Message (e.g. from an old event or cache) and need fresh data.
472
- * @returns The updated message
473
- * @throws FluxerError with MESSAGE_NOT_FOUND if the message was deleted or does not exist
474
- * @example
475
- * const updated = await message.fetch();
476
- * console.log('Latest content:', updated.content);
477
- */
618
+ /** Fetch the latest version of this message from the API. */
478
619
  async fetch() {
479
620
  return this.client.channels.fetchMessage(this.channelId, this.id);
480
621
  }
481
622
  /** Delete this message. */
482
623
  async delete() {
483
- await this.client.rest.delete(import_types2.Routes.channelMessage(this.channelId, this.id));
624
+ await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id));
625
+ this.client._removeMessageFromCache(this.channelId, this.id);
484
626
  }
485
- /**
486
- * Delete a specific attachment from this message.
487
- * DELETE /channels/{id}/messages/{id}/attachments/{attachmentId}.
488
- */
627
+ /** Delete a specific attachment from this message. */
489
628
  async deleteAttachment(attachmentId) {
490
629
  await this.client.rest.delete(
491
- import_types2.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
630
+ import_types5.Routes.channelMessageAttachment(this.channelId, this.id, attachmentId),
492
631
  { auth: true }
493
632
  );
494
633
  this.attachments.delete(attachmentId);
495
634
  }
496
- /** Pin this message to the channel. Requires Manage Messages permission. */
635
+ /** Pin this message in the channel. */
497
636
  async pin() {
498
- await this.client.rest.put(import_types2.Routes.channelPinMessage(this.channelId, this.id));
637
+ await this.client.rest.put(import_types5.Routes.channelPinMessage(this.channelId, this.id));
499
638
  this.pinned = true;
500
639
  }
501
- /** Unpin this message from the channel. Requires Manage Messages permission. */
640
+ /** Unpin this message from the channel. */
502
641
  async unpin() {
503
- await this.client.rest.delete(import_types2.Routes.channelPinMessage(this.channelId, this.id));
642
+ await this.client.rest.delete(import_types5.Routes.channelPinMessage(this.channelId, this.id));
504
643
  this.pinned = false;
505
644
  }
506
- /**
507
- * Format emoji for reaction API: unicode string or "name:id" for custom.
508
- * For string resolution (e.g. :name:), use client.resolveEmoji; Message methods resolve automatically when guildId is available.
509
- */
510
- static formatEmoji(emoji) {
511
- if (typeof emoji === "string") return emoji;
512
- return `${emoji.name}:${emoji.id}`;
513
- }
514
- resolveEmojiForReaction(emoji) {
515
- return this.client.resolveEmoji(emoji, this.guildId);
516
- }
517
- /**
518
- * Add a reaction to this message (as the bot).
519
- * @param emoji - Unicode emoji, custom `{ name, id }`, `:name:`, `name:id`, or `<:name:id>`
520
- */
645
+ /** React to this message with an emoji. */
521
646
  async react(emoji) {
522
- const emojiStr = await this.resolveEmojiForReaction(emoji);
523
- const route = `${import_types2.Routes.channelMessageReaction(this.channelId, this.id, emojiStr)}/@me`;
524
- await this.client.rest.put(route);
647
+ return reactToMessage(this, emoji);
525
648
  }
526
- /**
527
- * Remove the bot's reaction, or a specific user's reaction if userId is provided.
528
- * @param emoji - Unicode emoji, custom `{ name, id }`, `:name:`, `name:id`, or `<:name:id>`
529
- * @param userId - If provided, removes that user's reaction (requires moderator permissions)
530
- */
649
+ /** Remove a reaction (bot's own or a user's if ID is provided). */
531
650
  async removeReaction(emoji, userId) {
532
- const emojiStr = await this.resolveEmojiForReaction(emoji);
533
- const route = `${import_types2.Routes.channelMessageReaction(this.channelId, this.id, emojiStr)}/${userId ?? "@me"}`;
534
- await this.client.rest.delete(route);
651
+ return removeMessageReaction(this, emoji, userId);
535
652
  }
536
- /**
537
- * Remove all reactions from this message.
538
- * Requires moderator permissions.
539
- */
653
+ /** Remove all reactions from this message. */
540
654
  async removeAllReactions() {
541
- await this.client.rest.delete(import_types2.Routes.channelMessageReactions(this.channelId, this.id));
655
+ return removeAllMessageReactions(this);
542
656
  }
543
- /**
544
- * Remove all reactions of a specific emoji from this message.
545
- * @param emoji - Unicode emoji, custom `{ name, id }`, `:name:`, `name:id`, or `<:name:id>`. Requires moderator permissions.
546
- */
657
+ /** Remove all reactions of a specific emoji. */
547
658
  async removeReactionEmoji(emoji) {
548
- const emojiStr = await this.resolveEmojiForReaction(emoji);
549
- await this.client.rest.delete(import_types2.Routes.channelMessageReaction(this.channelId, this.id, emojiStr));
659
+ return removeMessageReactionEmoji(this, emoji);
550
660
  }
551
- /**
552
- * Fetch users who reacted with the given emoji.
553
- * @param emoji - Unicode emoji or custom `{ name, id }`
554
- * @param options - limit (1–100), after (user ID for pagination)
555
- * @returns Array of User objects
556
- */
661
+ /** Fetch users who reacted with a specific emoji. */
557
662
  async fetchReactionUsers(emoji, options) {
558
- const emojiStr = await this.resolveEmojiForReaction(emoji);
559
- const params = new URLSearchParams();
560
- if (options?.limit != null) params.set("limit", String(options.limit));
561
- if (options?.after) params.set("after", options.after);
562
- const qs = params.toString();
563
- const route = import_types2.Routes.channelMessageReaction(this.channelId, this.id, emojiStr) + (qs ? `?${qs}` : "");
564
- const data = await this.client.rest.get(route);
565
- const list = Array.isArray(data) ? data : data?.users ?? [];
566
- return list.map((u) => this.client.getOrCreateUser(u));
663
+ return fetchMessageReactionUsers(this, emoji, options);
664
+ }
665
+ /** Fetch reaction users with pagination metadata. */
666
+ async fetchReactionUsersPage(emoji, options) {
667
+ return fetchMessageReactionUsersPage(this, emoji, options);
567
668
  }
568
669
  };
569
670
  // Annotate the CommonJS export names for ESM import in node: