lunibee 0.2.2 → 0.2.3

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.
Files changed (43) hide show
  1. package/dist/builders/attachment.d.ts +2 -2
  2. package/dist/builders/commands.d.ts +39 -36
  3. package/dist/builders/components.d.ts +44 -44
  4. package/dist/builders/embed.d.ts +2 -2
  5. package/dist/builders/index.d.ts +1 -1
  6. package/dist/builders/index.js +12 -3
  7. package/dist/builders/index.js.map +7 -7
  8. package/dist/core/index.d.ts +1 -0
  9. package/dist/core/index.js +196 -96
  10. package/dist/core/index.js.map +21 -21
  11. package/dist/core/permissions.d.ts +2 -2
  12. package/dist/index.js +254 -105
  13. package/dist/index.js.map +29 -28
  14. package/dist/managers/base.d.ts +4 -0
  15. package/dist/managers/emoji.d.ts +7 -1
  16. package/dist/managers/guild-resources.d.ts +11 -3
  17. package/dist/managers/guild.d.ts +13 -5
  18. package/dist/managers/index.d.ts +26 -13
  19. package/dist/managers/index.js +139 -68
  20. package/dist/managers/index.js.map +16 -16
  21. package/dist/managers/member.d.ts +5 -3
  22. package/dist/managers/role.d.ts +13 -1
  23. package/dist/rest/error-codes.d.ts +48 -0
  24. package/dist/rest/errors.d.ts +1 -0
  25. package/dist/rest/index.d.ts +1 -0
  26. package/dist/rest/index.js +53 -3
  27. package/dist/rest/index.js.map +7 -6
  28. package/dist/rest/routes.d.ts +4 -2
  29. package/dist/sharding/index.js +6 -6
  30. package/dist/sharding/index.js.map +4 -4
  31. package/dist/structures/base.d.ts +18 -9
  32. package/dist/structures/index.d.ts +6 -6
  33. package/dist/structures/index.js +74 -42
  34. package/dist/structures/index.js.map +11 -11
  35. package/dist/structures/interactions.d.ts +2 -2
  36. package/dist/structures/resources.d.ts +2 -2
  37. package/dist/types/index.d.ts +43 -18
  38. package/dist/types/index.js.map +2 -2
  39. package/dist/voice/index.js +4 -3
  40. package/dist/voice/index.js.map +3 -3
  41. package/dist/ws/index.js +1 -1
  42. package/dist/ws/index.js.map +3 -3
  43. package/package.json +15 -15
@@ -101,6 +101,7 @@ export declare class Client extends EventEmitter<ClientEvents> implements Intera
101
101
  /** Fetches an invite from Discord. */
102
102
  fetchInvite(code: string, options?: {
103
103
  withCounts?: boolean;
104
+ /** @deprecated No effect: Discord always returns `expires_at` and deprecated `with_expiration`. Removed in 0.3.0. */
104
105
  withExpiration?: boolean;
105
106
  guildScheduledEventId?: string;
106
107
  }): Promise<Record<string, unknown>>;
@@ -1363,6 +1363,11 @@ class Collection extends Map {
1363
1363
  }
1364
1364
 
1365
1365
  // packages/managers/src/base.ts
1366
+ function splitReason(options) {
1367
+ const { reason, ...payload } = options;
1368
+ return [payload, reason];
1369
+ }
1370
+
1366
1371
  class Manager {
1367
1372
  cache = new Collection;
1368
1373
  get(id) {
@@ -1464,12 +1469,15 @@ class ResourceManager extends Manager {
1464
1469
  // packages/rest/package.json
1465
1470
  var package_default = {
1466
1471
  name: "@lunibee/rest",
1467
- version: "0.2.2",
1472
+ version: "0.2.3",
1468
1473
  type: "module",
1469
1474
  module: "./src/index.ts",
1470
1475
  types: "./src/index.ts",
1471
1476
  exports: {
1472
1477
  ".": "./src/index.ts"
1478
+ },
1479
+ dependencies: {
1480
+ "@lunibee/types": "workspace:*"
1473
1481
  }
1474
1482
  };
1475
1483
 
@@ -1544,6 +1552,10 @@ function kindFromStatus(status) {
1544
1552
  function redactPath(path) {
1545
1553
  return path.replace(/^(\/webhooks\/[^/?]+\/)[^/?]+/, "$1:token").replace(/^(\/interactions\/[^/?]+\/)[^/?]+/, "$1:token");
1546
1554
  }
1555
+ var HINTS = {
1556
+ 50001: "The bot cannot see this resource: check that it is in the guild and has View Channel there.",
1557
+ 50013: "The bot lacks a permission for this action, or the target role or member is at or above the bot's highest role."
1558
+ };
1547
1559
 
1548
1560
  class RESTError extends Error {
1549
1561
  kind;
@@ -1552,12 +1564,14 @@ class RESTError extends Error {
1552
1564
  errors;
1553
1565
  method;
1554
1566
  path;
1567
+ hint;
1555
1568
  constructor(message, status, code, errors, options = {}) {
1556
1569
  super(message, options.cause === undefined ? undefined : { cause: options.cause });
1557
1570
  this.name = "RESTError";
1558
1571
  this.status = status;
1559
1572
  this.kind = options.kind ?? kindFromStatus(status);
1560
1573
  this.code = code;
1574
+ this.hint = code === undefined ? undefined : HINTS[code];
1561
1575
  this.errors = errors;
1562
1576
  this.method = options.method;
1563
1577
  this.path = options.path === undefined ? undefined : redactPath(options.path);
@@ -1866,6 +1880,8 @@ var Routes = {
1866
1880
  crosspostMessage: (channelId, messageId) => `${Routes.message(channelId, messageId)}/crosspost`,
1867
1881
  messageReactions: (channelId, messageId, emoji) => `${Routes.message(channelId, messageId)}/reactions/${encodeURIComponent(emoji)}`,
1868
1882
  messageReactionsAll: (channelId, messageId) => `${Routes.message(channelId, messageId)}/reactions`,
1883
+ channelMessagesPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins`,
1884
+ channelMessagesPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins/${snowflake(messageId, "Message ID")}`,
1869
1885
  channelPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/pins`,
1870
1886
  channelPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/pins/${snowflake(messageId, "Message ID")}`,
1871
1887
  messageThread: (channelId, messageId) => `${Routes.message(channelId, messageId)}/threads`,
@@ -1928,7 +1944,7 @@ function snowflake(value, field) {
1928
1944
  // packages/rest/src/index.ts
1929
1945
  var LIBRARY_VERSION = package_default.version;
1930
1946
  var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
1931
- var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${package_default.version})`;
1947
+ var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${LIBRARY_VERSION})`;
1932
1948
  var REQUEST_DATA_KEYS = new Set([
1933
1949
  "body",
1934
1950
  "files",
@@ -2251,13 +2267,13 @@ class Channel extends BaseStructure {
2251
2267
  this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
2252
2268
  this.#context = context;
2253
2269
  }
2254
- sendMessage(options) {
2270
+ send(options) {
2255
2271
  if (!this.#context)
2256
2272
  throw new Error("This channel is not attached to a client.");
2257
2273
  return this.#context.sendMessage(this.id, options);
2258
2274
  }
2259
- send(options) {
2260
- return this.sendMessage(options);
2275
+ sendMessage(options) {
2276
+ return this.send(options);
2261
2277
  }
2262
2278
  edit(options) {
2263
2279
  if (!this.#context?.editChannel)
@@ -2280,10 +2296,10 @@ class Channel extends BaseStructure {
2280
2296
  editParent(parentId) {
2281
2297
  return this.edit({ parent_id: parentId });
2282
2298
  }
2283
- delete() {
2299
+ delete(reason) {
2284
2300
  if (!this.#context?.deleteChannel)
2285
2301
  throw new Error("This channel is not attached to a client.");
2286
- return this.#context.deleteChannel(this.id);
2302
+ return this.#context.deleteChannel(this.id, reason);
2287
2303
  }
2288
2304
  update(options) {
2289
2305
  return this.edit(options);
@@ -2330,6 +2346,15 @@ class Guild extends BaseStructure {
2330
2346
  mfaLevel;
2331
2347
  explicitContentFilter;
2332
2348
  defaultMessageNotifications;
2349
+ afkChannelId;
2350
+ afkTimeout;
2351
+ widgetEnabled;
2352
+ widgetChannelId;
2353
+ applicationId;
2354
+ publicUpdatesChannelId;
2355
+ safetyAlertsChannelId;
2356
+ maxPresences;
2357
+ maxVideoChannelUsers;
2333
2358
  constructor(data) {
2334
2359
  super(data.id);
2335
2360
  if (!data.name)
@@ -2351,14 +2376,22 @@ class Guild extends BaseStructure {
2351
2376
  this.vanityUrlCode = data.vanity_url_code ?? null;
2352
2377
  this.nsfwLevel = data.nsfw_level ?? 0;
2353
2378
  this.discoverySplash = data.discovery_splash ?? null;
2354
- const d = data;
2355
- this.rulesChannelId = d.rules_channel_id ?? null;
2356
- this.systemChannelId = d.system_channel_id ?? null;
2357
- this.systemChannelFlags = d.system_channel_flags ?? 0;
2358
- this.maxMembers = d.max_members ?? 0;
2359
- this.mfaLevel = d.mfa_level ?? 0;
2360
- this.explicitContentFilter = d.explicit_content_filter ?? 0;
2361
- this.defaultMessageNotifications = d.default_message_notifications ?? 0;
2379
+ this.rulesChannelId = data.rules_channel_id ?? null;
2380
+ this.systemChannelId = data.system_channel_id ?? null;
2381
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
2382
+ this.maxMembers = data.max_members ?? 0;
2383
+ this.mfaLevel = data.mfa_level ?? 0;
2384
+ this.explicitContentFilter = data.explicit_content_filter ?? 0;
2385
+ this.defaultMessageNotifications = data.default_message_notifications ?? 0;
2386
+ this.afkChannelId = data.afk_channel_id ?? null;
2387
+ this.afkTimeout = data.afk_timeout;
2388
+ this.widgetEnabled = data.widget_enabled ?? false;
2389
+ this.widgetChannelId = data.widget_channel_id ?? null;
2390
+ this.applicationId = data.application_id ?? null;
2391
+ this.publicUpdatesChannelId = data.public_updates_channel_id ?? null;
2392
+ this.safetyAlertsChannelId = data.safety_alerts_channel_id ?? null;
2393
+ this.maxPresences = data.max_presences ?? null;
2394
+ this.maxVideoChannelUsers = data.max_video_channel_users;
2362
2395
  }
2363
2396
  iconURL(options = {}) {
2364
2397
  if (!this.icon)
@@ -2753,6 +2786,13 @@ var OptionType = {
2753
2786
  class CommandOptions {
2754
2787
  #options;
2755
2788
  #resolved;
2789
+ #lookup(kind, id) {
2790
+ const group = this.#resolved?.[kind];
2791
+ if (typeof group !== "object" || group === null)
2792
+ return;
2793
+ const entry = group[id];
2794
+ return typeof entry === "object" && entry !== null ? entry : undefined;
2795
+ }
2756
2796
  constructor(options, resolved = {}) {
2757
2797
  let currentOptions = options;
2758
2798
  let group = null;
@@ -2841,7 +2881,7 @@ class CommandOptions {
2841
2881
  return null;
2842
2882
  }
2843
2883
  const userId = String(opt.value);
2844
- const resolved = this.#resolved?.users?.[userId] ?? null;
2884
+ const resolved = this.#lookup("users", userId) ?? null;
2845
2885
  if (!resolved && required)
2846
2886
  throw new TypeError(`Resolved user for option "${name}" is missing.`);
2847
2887
  return resolved;
@@ -2854,7 +2894,7 @@ class CommandOptions {
2854
2894
  return null;
2855
2895
  }
2856
2896
  const channelId = String(opt.value);
2857
- const resolved = this.#resolved?.channels?.[channelId] ?? null;
2897
+ const resolved = this.#lookup("channels", channelId) ?? null;
2858
2898
  if (!resolved && required)
2859
2899
  throw new TypeError(`Resolved channel for option "${name}" is missing.`);
2860
2900
  return resolved;
@@ -2867,7 +2907,7 @@ class CommandOptions {
2867
2907
  return null;
2868
2908
  }
2869
2909
  const roleId = String(opt.value);
2870
- const resolved = this.#resolved?.roles?.[roleId] ?? null;
2910
+ const resolved = this.#lookup("roles", roleId) ?? null;
2871
2911
  if (!resolved && required)
2872
2912
  throw new TypeError(`Resolved role for option "${name}" is missing.`);
2873
2913
  return resolved;
@@ -2880,7 +2920,7 @@ class CommandOptions {
2880
2920
  return null;
2881
2921
  }
2882
2922
  const id = String(opt.value);
2883
- const resolved = this.#resolved?.users?.[id] ?? this.#resolved?.roles?.[id] ?? null;
2923
+ const resolved = this.#lookup("users", id) ?? this.#lookup("roles", id) ?? null;
2884
2924
  if (!resolved && required)
2885
2925
  throw new TypeError(`Resolved mentionable for option "${name}" is missing.`);
2886
2926
  return resolved;
@@ -2890,9 +2930,9 @@ class CommandOptions {
2890
2930
  if (!opt || opt.type !== OptionType.Mentionable)
2891
2931
  return null;
2892
2932
  const id = String(opt.value);
2893
- if (this.#resolved?.users?.[id])
2933
+ if (this.#lookup("users", id))
2894
2934
  return "user";
2895
- if (this.#resolved?.roles?.[id])
2935
+ if (this.#lookup("roles", id))
2896
2936
  return "role";
2897
2937
  return null;
2898
2938
  }
@@ -2904,7 +2944,7 @@ class CommandOptions {
2904
2944
  return null;
2905
2945
  }
2906
2946
  const attachmentId = String(opt.value);
2907
- const resolved = this.#resolved?.attachments?.[attachmentId] ?? null;
2947
+ const resolved = this.#lookup("attachments", attachmentId) ?? null;
2908
2948
  if (!resolved && required)
2909
2949
  throw new TypeError(`Resolved attachment for option "${name}" is missing.`);
2910
2950
  return resolved;
@@ -3208,16 +3248,19 @@ class ContextMenuCommandInteraction extends CommandInteraction {
3208
3248
 
3209
3249
  class ComponentInteraction extends Interaction {
3210
3250
  get customId() {
3211
- return this.data?.data?.custom_id ?? "";
3251
+ const id = this.data.data?.custom_id;
3252
+ return typeof id === "string" ? id : "";
3212
3253
  }
3213
3254
  get messageId() {
3214
- return this.data?.message?.id;
3255
+ return this.data.message?.id;
3215
3256
  }
3216
3257
  get componentType() {
3217
- return this.data?.data?.component_type ?? 0;
3258
+ const type = this.data.data?.component_type;
3259
+ return typeof type === "number" ? type : 0;
3218
3260
  }
3219
3261
  get values() {
3220
- return this.data?.data?.values ?? [];
3262
+ const values = this.data.data?.values;
3263
+ return Array.isArray(values) ? values : [];
3221
3264
  }
3222
3265
  async deferUpdate(options = {}) {
3223
3266
  const withResponse = options.withResponse === true;
@@ -3229,10 +3272,11 @@ class ComponentInteraction extends Interaction {
3229
3272
 
3230
3273
  class ModalSubmitInteraction extends Interaction {
3231
3274
  get customId() {
3232
- return this.data?.data?.custom_id ?? "";
3275
+ const id = this.data.data?.custom_id;
3276
+ return typeof id === "string" ? id : "";
3233
3277
  }
3234
3278
  getInputValue(customId) {
3235
- const rows = this.data?.data?.components ?? [];
3279
+ const rows = this.data.data?.components ?? [];
3236
3280
  for (const row of rows) {
3237
3281
  for (const comp of row.components ?? []) {
3238
3282
  if (comp.custom_id === customId)
@@ -3256,11 +3300,12 @@ class AutocompleteInteraction extends Interaction {
3256
3300
  this.options = new CommandOptions(data.data?.options ?? []);
3257
3301
  }
3258
3302
  get commandName() {
3259
- return this.data?.data?.name ?? "";
3303
+ const name = this.data.data?.name;
3304
+ return typeof name === "string" ? name : "";
3260
3305
  }
3261
3306
  get focusedOption() {
3262
- const options = this.data?.data?.options ?? [];
3263
- return findFocused(options);
3307
+ const options = this.data.data?.options;
3308
+ return findFocused(Array.isArray(options) ? options : []);
3264
3309
  }
3265
3310
  async respond(choices) {
3266
3311
  if (!Array.isArray(choices))
@@ -3377,10 +3422,10 @@ class Message extends BaseStructure {
3377
3422
  update(options) {
3378
3423
  return this.edit(options);
3379
3424
  }
3380
- delete() {
3425
+ delete(reason) {
3381
3426
  if (!this.#context)
3382
3427
  throw new Error("This message is not attached to a client.");
3383
- return this.#context.deleteMessage(this.channelId, this.id);
3428
+ return this.#context.deleteMessage(this.channelId, this.id, reason);
3384
3429
  }
3385
3430
  reply(options) {
3386
3431
  if (!this.#context)
@@ -3427,15 +3472,15 @@ class Message extends BaseStructure {
3427
3472
  throw new Error("This message is not attached to a client.");
3428
3473
  return this.#context.removeAllReactions(this.channelId, this.id);
3429
3474
  }
3430
- pin() {
3475
+ pin(reason) {
3431
3476
  if (!this.#context?.pinMessage)
3432
3477
  throw new Error("This message is not attached to a client.");
3433
- return this.#context.pinMessage(this.channelId, this.id);
3478
+ return this.#context.pinMessage(this.channelId, this.id, reason);
3434
3479
  }
3435
- unpin() {
3480
+ unpin(reason) {
3436
3481
  if (!this.#context?.unpinMessage)
3437
3482
  throw new Error("This message is not attached to a client.");
3438
- return this.#context.unpinMessage(this.channelId, this.id);
3483
+ return this.#context.unpinMessage(this.channelId, this.id, reason);
3439
3484
  }
3440
3485
  get isEphemeral() {
3441
3486
  return (this.flags & 64) !== 0;
@@ -3614,15 +3659,22 @@ class EmojiManager extends Manager {
3614
3659
  return data.map((item) => this.upsert(item));
3615
3660
  }
3616
3661
  async create(options) {
3617
- return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), options));
3662
+ const [payload, reason] = splitReason(options);
3663
+ return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), payload, { reason }));
3618
3664
  }
3619
3665
  async edit(emojiId, options) {
3620
- return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), options));
3666
+ const [payload, reason] = splitReason(options);
3667
+ return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), payload, { reason }));
3621
3668
  }
3622
- async deleteEmoji(emojiId) {
3623
- await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId));
3669
+ async remove(emojiId, reason) {
3670
+ await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId), {
3671
+ reason
3672
+ });
3624
3673
  this.delete(emojiId);
3625
3674
  }
3675
+ deleteEmoji(emojiId) {
3676
+ return this.remove(emojiId);
3677
+ }
3626
3678
  upsert(data) {
3627
3679
  const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
3628
3680
  return this.#merge(key, new Emoji(data));
@@ -3826,11 +3878,16 @@ class GuildMemberManager extends ResourceManager {
3826
3878
  await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
3827
3879
  this.delete(userId);
3828
3880
  }
3829
- async unban(userId) {
3830
- await this.#rest.delete(Routes.guildBan(this.guildId, userId));
3881
+ async unban(userId, reason) {
3882
+ await this.#rest.delete(Routes.guildBan(this.guildId, userId), {
3883
+ reason
3884
+ });
3831
3885
  }
3832
3886
  async edit(userId, options, reason) {
3833
- const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options, { reason });
3887
+ const [payload, optionsReason] = splitReason(options);
3888
+ const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), payload, {
3889
+ reason: optionsReason ?? reason
3890
+ });
3834
3891
  const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
3835
3892
  this.set(member.user.id, member);
3836
3893
  return member;
@@ -3869,7 +3926,7 @@ class RoleManager extends ResourceManager {
3869
3926
  const data = await this.#rest.post(Routes.guildRoles(this.guildId), {
3870
3927
  ...payload,
3871
3928
  permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
3872
- });
3929
+ }, { reason });
3873
3930
  const role = new Role(data);
3874
3931
  this.set(role.id, role);
3875
3932
  return role;
@@ -3879,15 +3936,28 @@ class RoleManager extends ResourceManager {
3879
3936
  const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), {
3880
3937
  ...payload,
3881
3938
  permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
3882
- });
3939
+ }, { reason });
3883
3940
  const role = new Role(data);
3884
3941
  this.set(role.id, role);
3885
3942
  return role;
3886
3943
  }
3887
- async deleteRole(roleId) {
3888
- await this.#rest.delete(Routes.guildRole(this.guildId, roleId));
3944
+ async remove(roleId, reason) {
3945
+ await this.#rest.delete(Routes.guildRole(this.guildId, roleId), {
3946
+ reason
3947
+ });
3889
3948
  this.delete(roleId);
3890
3949
  }
3950
+ async setPositions(positions, reason) {
3951
+ const data = await this.#rest.patch(Routes.guildRoles(this.guildId), positions.map(({ id, position }) => ({ id, position })), { reason });
3952
+ return data.map((item) => {
3953
+ const role = new Role(item);
3954
+ this.set(role.id, role);
3955
+ return role;
3956
+ });
3957
+ }
3958
+ deleteRole(roleId) {
3959
+ return this.remove(roleId);
3960
+ }
3891
3961
  }
3892
3962
 
3893
3963
  // packages/managers/src/guild-resources.ts
@@ -3959,13 +4029,15 @@ class GuildScheduledEventManager extends Manager {
3959
4029
  return events.map((event) => this.#store(event));
3960
4030
  }
3961
4031
  async create(options, reason) {
3962
- return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), options, { reason }));
4032
+ const [payload, optionsReason] = splitReason(options);
4033
+ return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), payload, { reason: optionsReason ?? reason }));
3963
4034
  }
3964
4035
  async edit(eventId, options, reason) {
3965
- return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), options, { reason }));
4036
+ const [payload, optionsReason] = splitReason(options);
4037
+ return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), payload, { reason: optionsReason ?? reason }));
3966
4038
  }
3967
- async remove(eventId) {
3968
- await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId));
4039
+ async remove(eventId, reason) {
4040
+ await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId), { reason });
3969
4041
  this.delete(eventId);
3970
4042
  }
3971
4043
  async fetchSubscribers(eventId, options = {}) {
@@ -3996,13 +4068,13 @@ class StageInstanceManager extends Manager {
3996
4068
  privacy_level: options.privacyLevel,
3997
4069
  send_start_notification: options.sendStartNotification,
3998
4070
  guild_scheduled_event_id: options.guildScheduledEventId
3999
- }, { reason }));
4071
+ }, { reason: options.reason ?? reason }));
4000
4072
  }
4001
4073
  async fetch(channelId) {
4002
4074
  return this.#store(await this.#rest.get(Routes.stageInstanceByChannel(channelId)));
4003
4075
  }
4004
4076
  async edit(channelId, options, reason) {
4005
- return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason }));
4077
+ return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason: options.reason ?? reason }));
4006
4078
  }
4007
4079
  async remove(channelId, reason) {
4008
4080
  await this.#rest.delete(Routes.stageInstanceByChannel(channelId), {
@@ -4039,7 +4111,7 @@ class PermissionOverwriteManager {
4039
4111
  type: options.type,
4040
4112
  allow: BigInt(options.allow ?? 0).toString(),
4041
4113
  deny: BigInt(options.deny ?? 0).toString()
4042
- }, { reason });
4114
+ }, { reason: options.reason ?? reason });
4043
4115
  }
4044
4116
  async remove(overwriteId, reason) {
4045
4117
  await this.#rest.delete(Routes.channelPermission(this.channelId, overwriteId), { reason });
@@ -4157,12 +4229,16 @@ class GuildManager extends ResourceManager {
4157
4229
  return this.upsert(new Guild(data));
4158
4230
  }
4159
4231
  async edit(id, options) {
4160
- const data = await this.#rest.patch(Routes.guild(id), options);
4232
+ const [payload, reason] = splitReason(options);
4233
+ const data = await this.#rest.patch(Routes.guild(id), payload, { reason });
4161
4234
  return this.upsert(new Guild(data));
4162
4235
  }
4163
- async deleteGuild(id) {
4236
+ async remove(id) {
4164
4237
  await this.#rest.delete(Routes.guild(id));
4165
4238
  }
4239
+ deleteGuild(id) {
4240
+ return this.remove(id);
4241
+ }
4166
4242
  async fetchPreview(id) {
4167
4243
  return this.#rest.get(Routes.guildPreview(id));
4168
4244
  }
@@ -4206,15 +4282,17 @@ class GuildManager extends ResourceManager {
4206
4282
  return new AutoModerationRule(rule);
4207
4283
  }
4208
4284
  async createAutoModerationRule(guildId, options) {
4209
- const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), options);
4285
+ const [payload, reason] = splitReason(options);
4286
+ const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), payload, { reason });
4210
4287
  return new AutoModerationRule(rule);
4211
4288
  }
4212
4289
  async editAutoModerationRule(guildId, ruleId, options) {
4213
- const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), options);
4290
+ const [payload, reason] = splitReason(options);
4291
+ const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), payload, { reason });
4214
4292
  return new AutoModerationRule(rule);
4215
4293
  }
4216
- async deleteAutoModerationRule(guildId, ruleId) {
4217
- await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId));
4294
+ async deleteAutoModerationRule(guildId, ruleId, reason) {
4295
+ await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId), { reason });
4218
4296
  }
4219
4297
  }
4220
4298
  // packages/managers/src/application.ts
@@ -4277,16 +4355,16 @@ class ChannelManager extends Manager {
4277
4355
  this.#context = {
4278
4356
  sendMessage: (channelId, options) => this.send(channelId, options),
4279
4357
  editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
4280
- deleteMessage: (channelId, messageId) => this.deleteMessage(channelId, messageId),
4358
+ deleteMessage: (channelId, messageId, reason) => this.deleteMessage(channelId, messageId, reason),
4281
4359
  crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId),
4282
4360
  editChannel: (channelId, options) => this.edit(channelId, options),
4283
- deleteChannel: (channelId) => this.deleteChannel(channelId),
4361
+ deleteChannel: (channelId, reason) => this.remove(channelId, reason),
4284
4362
  addReaction: (channelId, messageId, emoji) => this.addReaction(channelId, messageId, emoji),
4285
4363
  removeOwnReaction: (channelId, messageId, emoji) => this.removeOwnReaction(channelId, messageId, emoji),
4286
4364
  removeReaction: (channelId, messageId, emoji, userId) => this.removeReaction(channelId, messageId, emoji, userId),
4287
4365
  removeAllReactions: (channelId, messageId) => this.removeAllReactions(channelId, messageId),
4288
- pinMessage: (channelId, messageId) => this.pinMessage(channelId, messageId),
4289
- unpinMessage: (channelId, messageId) => this.unpinMessage(channelId, messageId)
4366
+ pinMessage: (channelId, messageId, reason) => this.pinMessage(channelId, messageId, reason),
4367
+ unpinMessage: (channelId, messageId, reason) => this.unpinMessage(channelId, messageId, reason)
4290
4368
  };
4291
4369
  }
4292
4370
  messages(channelId) {
@@ -4356,15 +4434,20 @@ class ChannelManager extends Manager {
4356
4434
  return this.#messageManagers.get(channelId);
4357
4435
  }
4358
4436
  async create(guildId, options) {
4359
- return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), options));
4437
+ const [payload, reason] = splitReason(options);
4438
+ return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), payload, { reason }));
4360
4439
  }
4361
4440
  async edit(channelId, options) {
4362
- return this.upsert(await this.#rest.patch(Routes.channel(channelId), options));
4441
+ const [payload, reason] = splitReason(options);
4442
+ return this.upsert(await this.#rest.patch(Routes.channel(channelId), payload, { reason }));
4363
4443
  }
4364
- async deleteChannel(channelId) {
4365
- await this.#rest.delete(Routes.channel(channelId));
4444
+ async remove(channelId, reason) {
4445
+ await this.#rest.delete(Routes.channel(channelId), { reason });
4366
4446
  this.delete(channelId);
4367
4447
  }
4448
+ deleteChannel(channelId) {
4449
+ return this.remove(channelId);
4450
+ }
4368
4451
  delete(channelId) {
4369
4452
  this.#messageManagers.delete(channelId);
4370
4453
  return super.delete(channelId);
@@ -4400,8 +4483,10 @@ class ChannelManager extends Manager {
4400
4483
  async editMessage(channelId, messageId, options) {
4401
4484
  return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), toRequest(options, this.#allowedMentions)));
4402
4485
  }
4403
- async deleteMessage(channelId, messageId) {
4404
- await this.#rest.delete(Routes.message(channelId, messageId));
4486
+ async deleteMessage(channelId, messageId, reason) {
4487
+ await this.#rest.delete(Routes.message(channelId, messageId), {
4488
+ reason
4489
+ });
4405
4490
  this.messages(channelId).delete(messageId);
4406
4491
  }
4407
4492
  deleteCachedMessage(channelId, messageId) {
@@ -4410,19 +4495,17 @@ class ChannelManager extends Manager {
4410
4495
  async crosspostMessage(channelId, messageId) {
4411
4496
  return this.messages(channelId).upsert(await this.#rest.post(Routes.crosspostMessage(channelId, messageId)));
4412
4497
  }
4413
- async bulkDeleteMessages(channelId, messageIds) {
4498
+ async bulkDeleteMessages(channelId, messageIds, reason) {
4414
4499
  const ids = [...new Set(messageIds)];
4415
4500
  if (ids.length < 1 || ids.length > 100)
4416
4501
  throw new RangeError("bulkDelete requires between 1 and 100 message IDs.");
4417
4502
  if (ids.length === 1)
4418
- return this.deleteMessage(channelId, ids[0]);
4503
+ return this.deleteMessage(channelId, ids[0], reason);
4419
4504
  const cutoff = Date.now() - BULK_DELETE_MAX_AGE_MS;
4420
4505
  const tooOld = ids.filter((id) => snowflakeTime(id) < cutoff);
4421
4506
  if (tooOld.length)
4422
4507
  throw new RangeError(`bulkDelete cannot delete messages older than 14 days: ${tooOld.join(", ")}`);
4423
- await this.#rest.post(Routes.channelBulkDelete(channelId), {
4424
- messages: ids
4425
- });
4508
+ await this.#rest.post(Routes.channelBulkDelete(channelId), { messages: ids }, { reason });
4426
4509
  for (const id of ids)
4427
4510
  this.messages(channelId).delete(id);
4428
4511
  }
@@ -4465,14 +4548,20 @@ class ChannelManager extends Manager {
4465
4548
  await this.#rest.delete(Routes.messageReactionsAll(channelId, messageId));
4466
4549
  }
4467
4550
  async fetchPinnedMessages(channelId) {
4468
- const data = await this.#rest.get(Routes.channelPins(channelId));
4469
- return data.map((item) => this.messages(channelId).upsert(item));
4551
+ const data = await this.#rest.get(Routes.channelMessagesPins(channelId));
4552
+ return data.items.map((item) => this.messages(channelId).upsert(item.message));
4553
+ }
4554
+ async pinMessage(channelId, messageId, reason) {
4555
+ await this.#rest.put(Routes.channelMessagesPin(channelId, messageId), undefined, { reason });
4470
4556
  }
4471
- async pinMessage(channelId, messageId) {
4472
- await this.#rest.put(Routes.channelPin(channelId, messageId));
4557
+ async unpinMessage(channelId, messageId, reason) {
4558
+ await this.#rest.delete(Routes.channelMessagesPin(channelId, messageId), { reason });
4473
4559
  }
4474
- async unpinMessage(channelId, messageId) {
4475
- await this.#rest.delete(Routes.channelPin(channelId, messageId));
4560
+ async createWebhook(channelId, options) {
4561
+ const [payload, reason] = splitReason(options);
4562
+ return this.#rest.post(Routes.channelWebhooks(channelId), payload, {
4563
+ reason
4564
+ });
4476
4565
  }
4477
4566
  createThreadFromMessage(channelId, messageId, options) {
4478
4567
  return this.threads(channelId).createFromMessage(messageId, options);
@@ -4490,7 +4579,7 @@ class ChannelManager extends Manager {
4490
4579
  hasMore: messages.length === limit
4491
4580
  };
4492
4581
  }
4493
- async bulkDelete(channelId, messageIds) {
4582
+ bulkDelete(channelId, messageIds) {
4494
4583
  return this.bulkDeleteMessages(channelId, messageIds);
4495
4584
  }
4496
4585
  clear() {
@@ -5633,18 +5722,31 @@ class EventEmitter2 {
5633
5722
  return true;
5634
5723
  }
5635
5724
  #handleError(event, error) {
5636
- if (event === "error" /* Error */)
5637
- return;
5638
5725
  const normalized = error instanceof Error ? error : new Error(String(error), { cause: error });
5639
- for (const listener of [
5726
+ const listeners = event === "error" /* Error */ ? [] : [
5640
5727
  ...this.#listeners.get("error" /* Error */) ?? []
5641
- ]) {
5728
+ ];
5729
+ if (listeners.length === 0)
5730
+ return warnListenerError(event, normalized);
5731
+ for (const listener of listeners) {
5642
5732
  try {
5643
- listener(normalized);
5644
- } catch {}
5733
+ const result = listener(normalized);
5734
+ if (result && typeof result.then === "function")
5735
+ Promise.resolve(result).catch((failure) => warnListenerError("error" /* Error */, failure));
5736
+ } catch (failure) {
5737
+ warnListenerError("error" /* Error */, failure);
5738
+ }
5645
5739
  }
5646
5740
  }
5647
5741
  }
5742
+ function warnListenerError(event, error) {
5743
+ const failure = error instanceof Error ? error : new Error(String(error));
5744
+ process.emitWarning(`A "${String(event)}" listener threw and no error listener handled it: ${failure.message}`, {
5745
+ type: "LunibeeWarning",
5746
+ code: "LUNIBEE_UNHANDLED_LISTENER_ERROR",
5747
+ detail: failure.stack
5748
+ });
5749
+ }
5648
5750
 
5649
5751
  class Client extends EventEmitter2 {
5650
5752
  options;
@@ -5713,16 +5815,16 @@ class Client extends EventEmitter2 {
5713
5815
  this.#resourceContext = {
5714
5816
  sendMessage: (channelId, options) => this.channels.send(channelId, options),
5715
5817
  editMessage: (channelId, messageId, options) => this.channels.editMessage(channelId, messageId, options),
5716
- deleteMessage: (channelId, messageId) => this.channels.deleteMessage(channelId, messageId),
5818
+ deleteMessage: (channelId, messageId, reason) => this.channels.deleteMessage(channelId, messageId, reason),
5717
5819
  crosspostMessage: (channelId, messageId) => this.channels.crosspostMessage(channelId, messageId),
5718
5820
  editChannel: (channelId, options) => this.channels.edit(channelId, options),
5719
- deleteChannel: (channelId) => this.channels.deleteChannel(channelId),
5821
+ deleteChannel: (channelId, reason) => this.channels.remove(channelId, reason),
5720
5822
  addReaction: (channelId, messageId, emoji) => this.channels.addReaction(channelId, messageId, emoji),
5721
5823
  removeOwnReaction: (channelId, messageId, emoji) => this.channels.removeOwnReaction(channelId, messageId, emoji),
5722
5824
  removeReaction: (channelId, messageId, emoji, userId) => this.channels.removeReaction(channelId, messageId, emoji, userId),
5723
5825
  removeAllReactions: (channelId, messageId) => this.channels.removeAllReactions(channelId, messageId),
5724
- pinMessage: (channelId, messageId) => this.channels.pinMessage(channelId, messageId),
5725
- unpinMessage: (channelId, messageId) => this.channels.unpinMessage(channelId, messageId),
5826
+ pinMessage: (channelId, messageId, reason) => this.channels.pinMessage(channelId, messageId, reason),
5827
+ unpinMessage: (channelId, messageId, reason) => this.channels.unpinMessage(channelId, messageId, reason),
5726
5828
  collectInteractions: (options) => this.createCollector("interactionCreate" /* InteractionCreate */, options),
5727
5829
  memberPermissions: (guildId, memberId, roleIds, channelId) => this.#memberPermissions(guildId, memberId, roleIds, channelId),
5728
5830
  kickMember: (guildId, userId, reason) => this.guilds.members(guildId).kick(userId, reason),
@@ -6275,8 +6377,6 @@ class Client extends EventEmitter2 {
6275
6377
  const query = new URLSearchParams;
6276
6378
  if (options?.withCounts)
6277
6379
  query.set("with_counts", "true");
6278
- if (options?.withExpiration)
6279
- query.set("with_expiration", "true");
6280
6380
  if (options?.guildScheduledEventId)
6281
6381
  query.set("guild_scheduled_event_id", options.guildScheduledEventId);
6282
6382
  const qs = query.toString();
@@ -6324,4 +6424,4 @@ export {
6324
6424
  resolveGatewayIntents
6325
6425
  };
6326
6426
 
6327
- //# debugId=A5606C420611230B64756E2164756E21
6427
+ //# debugId=A8C0111D9C7EBB3664756E2164756E21