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
package/dist/index.js CHANGED
@@ -1549,6 +1549,11 @@ class Collection extends Map {
1549
1549
  }
1550
1550
 
1551
1551
  // packages/managers/src/base.ts
1552
+ function splitReason(options) {
1553
+ const { reason, ...payload } = options;
1554
+ return [payload, reason];
1555
+ }
1556
+
1552
1557
  class Manager {
1553
1558
  cache = new Collection;
1554
1559
  get(id) {
@@ -1650,12 +1655,15 @@ class ResourceManager extends Manager {
1650
1655
  // packages/rest/package.json
1651
1656
  var package_default = {
1652
1657
  name: "@lunibee/rest",
1653
- version: "0.2.2",
1658
+ version: "0.2.3",
1654
1659
  type: "module",
1655
1660
  module: "./src/index.ts",
1656
1661
  types: "./src/index.ts",
1657
1662
  exports: {
1658
1663
  ".": "./src/index.ts"
1664
+ },
1665
+ dependencies: {
1666
+ "@lunibee/types": "workspace:*"
1659
1667
  }
1660
1668
  };
1661
1669
 
@@ -1730,6 +1738,10 @@ function kindFromStatus(status) {
1730
1738
  function redactPath(path) {
1731
1739
  return path.replace(/^(\/webhooks\/[^/?]+\/)[^/?]+/, "$1:token").replace(/^(\/interactions\/[^/?]+\/)[^/?]+/, "$1:token");
1732
1740
  }
1741
+ var HINTS = {
1742
+ 50001: "The bot cannot see this resource: check that it is in the guild and has View Channel there.",
1743
+ 50013: "The bot lacks a permission for this action, or the target role or member is at or above the bot's highest role."
1744
+ };
1733
1745
 
1734
1746
  class RESTError extends Error {
1735
1747
  kind;
@@ -1738,12 +1750,14 @@ class RESTError extends Error {
1738
1750
  errors;
1739
1751
  method;
1740
1752
  path;
1753
+ hint;
1741
1754
  constructor(message, status, code, errors, options = {}) {
1742
1755
  super(message, options.cause === undefined ? undefined : { cause: options.cause });
1743
1756
  this.name = "RESTError";
1744
1757
  this.status = status;
1745
1758
  this.kind = options.kind ?? kindFromStatus(status);
1746
1759
  this.code = code;
1760
+ this.hint = code === undefined ? undefined : HINTS[code];
1747
1761
  this.errors = errors;
1748
1762
  this.method = options.method;
1749
1763
  this.path = options.path === undefined ? undefined : redactPath(options.path);
@@ -2052,6 +2066,8 @@ var Routes = {
2052
2066
  crosspostMessage: (channelId, messageId) => `${Routes.message(channelId, messageId)}/crosspost`,
2053
2067
  messageReactions: (channelId, messageId, emoji) => `${Routes.message(channelId, messageId)}/reactions/${encodeURIComponent(emoji)}`,
2054
2068
  messageReactionsAll: (channelId, messageId) => `${Routes.message(channelId, messageId)}/reactions`,
2069
+ channelMessagesPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins`,
2070
+ channelMessagesPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins/${snowflake(messageId, "Message ID")}`,
2055
2071
  channelPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/pins`,
2056
2072
  channelPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/pins/${snowflake(messageId, "Message ID")}`,
2057
2073
  messageThread: (channelId, messageId) => `${Routes.message(channelId, messageId)}/threads`,
@@ -2110,6 +2126,44 @@ function snowflake(value, field) {
2110
2126
  throw new TypeError(`${field} must be a valid Discord snowflake.`);
2111
2127
  return value;
2112
2128
  }
2129
+ // packages/rest/src/error-codes.ts
2130
+ var RESTErrorCode = {
2131
+ UnknownAccount: 10001,
2132
+ UnknownChannel: 10003,
2133
+ UnknownGuild: 10004,
2134
+ UnknownInvite: 10006,
2135
+ UnknownMember: 10007,
2136
+ UnknownMessage: 10008,
2137
+ UnknownPermissionOverwrite: 10009,
2138
+ UnknownRole: 10011,
2139
+ UnknownUser: 10013,
2140
+ UnknownEmoji: 10014,
2141
+ UnknownWebhook: 10015,
2142
+ UnknownBan: 10026,
2143
+ UnknownSticker: 10060,
2144
+ UnknownInteraction: 10062,
2145
+ UnknownScheduledEvent: 10070,
2146
+ BotsCannotUseEndpoint: 20001,
2147
+ MaxGuilds: 30001,
2148
+ MaxPins: 30003,
2149
+ MaxRoles: 30005,
2150
+ MaxWebhooks: 30007,
2151
+ MaxEmojis: 30008,
2152
+ MaxReactions: 30010,
2153
+ MaxChannels: 30013,
2154
+ InteractionAlreadyAcknowledged: 40060,
2155
+ MissingAccess: 50001,
2156
+ CannotExecuteInDM: 50003,
2157
+ CannotEditOthersMessage: 50005,
2158
+ CannotSendEmptyMessage: 50006,
2159
+ CannotSendMessagesToUser: 50007,
2160
+ MissingPermissions: 50013,
2161
+ InvalidToken: 50014,
2162
+ MessageTooOldToBulkDelete: 50034,
2163
+ InvalidFormBody: 50035,
2164
+ ThreadArchived: 50083,
2165
+ CannotReplyWithoutReadHistory: 160002
2166
+ };
2113
2167
  // packages/rest/src/redis.ts
2114
2168
  var RESERVE_SCRIPT = `
2115
2169
  local raw = redis.call('GET', KEYS[1])
@@ -2291,7 +2345,7 @@ class WebhookClient {
2291
2345
  // packages/rest/src/index.ts
2292
2346
  var LIBRARY_VERSION = package_default.version;
2293
2347
  var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
2294
- var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${package_default.version})`;
2348
+ var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${LIBRARY_VERSION})`;
2295
2349
  var REQUEST_DATA_KEYS = new Set([
2296
2350
  "body",
2297
2351
  "files",
@@ -2614,13 +2668,13 @@ class Channel extends BaseStructure {
2614
2668
  this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
2615
2669
  this.#context = context;
2616
2670
  }
2617
- sendMessage(options) {
2671
+ send(options) {
2618
2672
  if (!this.#context)
2619
2673
  throw new Error("This channel is not attached to a client.");
2620
2674
  return this.#context.sendMessage(this.id, options);
2621
2675
  }
2622
- send(options) {
2623
- return this.sendMessage(options);
2676
+ sendMessage(options) {
2677
+ return this.send(options);
2624
2678
  }
2625
2679
  edit(options) {
2626
2680
  if (!this.#context?.editChannel)
@@ -2643,10 +2697,10 @@ class Channel extends BaseStructure {
2643
2697
  editParent(parentId) {
2644
2698
  return this.edit({ parent_id: parentId });
2645
2699
  }
2646
- delete() {
2700
+ delete(reason) {
2647
2701
  if (!this.#context?.deleteChannel)
2648
2702
  throw new Error("This channel is not attached to a client.");
2649
- return this.#context.deleteChannel(this.id);
2703
+ return this.#context.deleteChannel(this.id, reason);
2650
2704
  }
2651
2705
  update(options) {
2652
2706
  return this.edit(options);
@@ -2693,6 +2747,15 @@ class Guild extends BaseStructure {
2693
2747
  mfaLevel;
2694
2748
  explicitContentFilter;
2695
2749
  defaultMessageNotifications;
2750
+ afkChannelId;
2751
+ afkTimeout;
2752
+ widgetEnabled;
2753
+ widgetChannelId;
2754
+ applicationId;
2755
+ publicUpdatesChannelId;
2756
+ safetyAlertsChannelId;
2757
+ maxPresences;
2758
+ maxVideoChannelUsers;
2696
2759
  constructor(data) {
2697
2760
  super(data.id);
2698
2761
  if (!data.name)
@@ -2714,14 +2777,22 @@ class Guild extends BaseStructure {
2714
2777
  this.vanityUrlCode = data.vanity_url_code ?? null;
2715
2778
  this.nsfwLevel = data.nsfw_level ?? 0;
2716
2779
  this.discoverySplash = data.discovery_splash ?? null;
2717
- const d = data;
2718
- this.rulesChannelId = d.rules_channel_id ?? null;
2719
- this.systemChannelId = d.system_channel_id ?? null;
2720
- this.systemChannelFlags = d.system_channel_flags ?? 0;
2721
- this.maxMembers = d.max_members ?? 0;
2722
- this.mfaLevel = d.mfa_level ?? 0;
2723
- this.explicitContentFilter = d.explicit_content_filter ?? 0;
2724
- this.defaultMessageNotifications = d.default_message_notifications ?? 0;
2780
+ this.rulesChannelId = data.rules_channel_id ?? null;
2781
+ this.systemChannelId = data.system_channel_id ?? null;
2782
+ this.systemChannelFlags = data.system_channel_flags ?? 0;
2783
+ this.maxMembers = data.max_members ?? 0;
2784
+ this.mfaLevel = data.mfa_level ?? 0;
2785
+ this.explicitContentFilter = data.explicit_content_filter ?? 0;
2786
+ this.defaultMessageNotifications = data.default_message_notifications ?? 0;
2787
+ this.afkChannelId = data.afk_channel_id ?? null;
2788
+ this.afkTimeout = data.afk_timeout;
2789
+ this.widgetEnabled = data.widget_enabled ?? false;
2790
+ this.widgetChannelId = data.widget_channel_id ?? null;
2791
+ this.applicationId = data.application_id ?? null;
2792
+ this.publicUpdatesChannelId = data.public_updates_channel_id ?? null;
2793
+ this.safetyAlertsChannelId = data.safety_alerts_channel_id ?? null;
2794
+ this.maxPresences = data.max_presences ?? null;
2795
+ this.maxVideoChannelUsers = data.max_video_channel_users;
2725
2796
  }
2726
2797
  iconURL(options = {}) {
2727
2798
  if (!this.icon)
@@ -3257,6 +3328,13 @@ var OptionType = {
3257
3328
  class CommandOptions {
3258
3329
  #options;
3259
3330
  #resolved;
3331
+ #lookup(kind, id) {
3332
+ const group = this.#resolved?.[kind];
3333
+ if (typeof group !== "object" || group === null)
3334
+ return;
3335
+ const entry = group[id];
3336
+ return typeof entry === "object" && entry !== null ? entry : undefined;
3337
+ }
3260
3338
  constructor(options, resolved = {}) {
3261
3339
  let currentOptions = options;
3262
3340
  let group = null;
@@ -3345,7 +3423,7 @@ class CommandOptions {
3345
3423
  return null;
3346
3424
  }
3347
3425
  const userId = String(opt.value);
3348
- const resolved = this.#resolved?.users?.[userId] ?? null;
3426
+ const resolved = this.#lookup("users", userId) ?? null;
3349
3427
  if (!resolved && required)
3350
3428
  throw new TypeError(`Resolved user for option "${name}" is missing.`);
3351
3429
  return resolved;
@@ -3358,7 +3436,7 @@ class CommandOptions {
3358
3436
  return null;
3359
3437
  }
3360
3438
  const channelId = String(opt.value);
3361
- const resolved = this.#resolved?.channels?.[channelId] ?? null;
3439
+ const resolved = this.#lookup("channels", channelId) ?? null;
3362
3440
  if (!resolved && required)
3363
3441
  throw new TypeError(`Resolved channel for option "${name}" is missing.`);
3364
3442
  return resolved;
@@ -3371,7 +3449,7 @@ class CommandOptions {
3371
3449
  return null;
3372
3450
  }
3373
3451
  const roleId = String(opt.value);
3374
- const resolved = this.#resolved?.roles?.[roleId] ?? null;
3452
+ const resolved = this.#lookup("roles", roleId) ?? null;
3375
3453
  if (!resolved && required)
3376
3454
  throw new TypeError(`Resolved role for option "${name}" is missing.`);
3377
3455
  return resolved;
@@ -3384,7 +3462,7 @@ class CommandOptions {
3384
3462
  return null;
3385
3463
  }
3386
3464
  const id = String(opt.value);
3387
- const resolved = this.#resolved?.users?.[id] ?? this.#resolved?.roles?.[id] ?? null;
3465
+ const resolved = this.#lookup("users", id) ?? this.#lookup("roles", id) ?? null;
3388
3466
  if (!resolved && required)
3389
3467
  throw new TypeError(`Resolved mentionable for option "${name}" is missing.`);
3390
3468
  return resolved;
@@ -3394,9 +3472,9 @@ class CommandOptions {
3394
3472
  if (!opt || opt.type !== OptionType.Mentionable)
3395
3473
  return null;
3396
3474
  const id = String(opt.value);
3397
- if (this.#resolved?.users?.[id])
3475
+ if (this.#lookup("users", id))
3398
3476
  return "user";
3399
- if (this.#resolved?.roles?.[id])
3477
+ if (this.#lookup("roles", id))
3400
3478
  return "role";
3401
3479
  return null;
3402
3480
  }
@@ -3408,7 +3486,7 @@ class CommandOptions {
3408
3486
  return null;
3409
3487
  }
3410
3488
  const attachmentId = String(opt.value);
3411
- const resolved = this.#resolved?.attachments?.[attachmentId] ?? null;
3489
+ const resolved = this.#lookup("attachments", attachmentId) ?? null;
3412
3490
  if (!resolved && required)
3413
3491
  throw new TypeError(`Resolved attachment for option "${name}" is missing.`);
3414
3492
  return resolved;
@@ -3712,16 +3790,19 @@ class ContextMenuCommandInteraction extends CommandInteraction {
3712
3790
 
3713
3791
  class ComponentInteraction extends Interaction {
3714
3792
  get customId() {
3715
- return this.data?.data?.custom_id ?? "";
3793
+ const id = this.data.data?.custom_id;
3794
+ return typeof id === "string" ? id : "";
3716
3795
  }
3717
3796
  get messageId() {
3718
- return this.data?.message?.id;
3797
+ return this.data.message?.id;
3719
3798
  }
3720
3799
  get componentType() {
3721
- return this.data?.data?.component_type ?? 0;
3800
+ const type = this.data.data?.component_type;
3801
+ return typeof type === "number" ? type : 0;
3722
3802
  }
3723
3803
  get values() {
3724
- return this.data?.data?.values ?? [];
3804
+ const values = this.data.data?.values;
3805
+ return Array.isArray(values) ? values : [];
3725
3806
  }
3726
3807
  async deferUpdate(options = {}) {
3727
3808
  const withResponse = options.withResponse === true;
@@ -3733,10 +3814,11 @@ class ComponentInteraction extends Interaction {
3733
3814
 
3734
3815
  class ModalSubmitInteraction extends Interaction {
3735
3816
  get customId() {
3736
- return this.data?.data?.custom_id ?? "";
3817
+ const id = this.data.data?.custom_id;
3818
+ return typeof id === "string" ? id : "";
3737
3819
  }
3738
3820
  getInputValue(customId) {
3739
- const rows = this.data?.data?.components ?? [];
3821
+ const rows = this.data.data?.components ?? [];
3740
3822
  for (const row of rows) {
3741
3823
  for (const comp of row.components ?? []) {
3742
3824
  if (comp.custom_id === customId)
@@ -3760,11 +3842,12 @@ class AutocompleteInteraction extends Interaction {
3760
3842
  this.options = new CommandOptions(data.data?.options ?? []);
3761
3843
  }
3762
3844
  get commandName() {
3763
- return this.data?.data?.name ?? "";
3845
+ const name = this.data.data?.name;
3846
+ return typeof name === "string" ? name : "";
3764
3847
  }
3765
3848
  get focusedOption() {
3766
- const options = this.data?.data?.options ?? [];
3767
- return findFocused(options);
3849
+ const options = this.data.data?.options;
3850
+ return findFocused(Array.isArray(options) ? options : []);
3768
3851
  }
3769
3852
  async respond(choices) {
3770
3853
  if (!Array.isArray(choices))
@@ -4048,10 +4131,10 @@ class Message extends BaseStructure {
4048
4131
  update(options) {
4049
4132
  return this.edit(options);
4050
4133
  }
4051
- delete() {
4134
+ delete(reason) {
4052
4135
  if (!this.#context)
4053
4136
  throw new Error("This message is not attached to a client.");
4054
- return this.#context.deleteMessage(this.channelId, this.id);
4137
+ return this.#context.deleteMessage(this.channelId, this.id, reason);
4055
4138
  }
4056
4139
  reply(options) {
4057
4140
  if (!this.#context)
@@ -4098,15 +4181,15 @@ class Message extends BaseStructure {
4098
4181
  throw new Error("This message is not attached to a client.");
4099
4182
  return this.#context.removeAllReactions(this.channelId, this.id);
4100
4183
  }
4101
- pin() {
4184
+ pin(reason) {
4102
4185
  if (!this.#context?.pinMessage)
4103
4186
  throw new Error("This message is not attached to a client.");
4104
- return this.#context.pinMessage(this.channelId, this.id);
4187
+ return this.#context.pinMessage(this.channelId, this.id, reason);
4105
4188
  }
4106
- unpin() {
4189
+ unpin(reason) {
4107
4190
  if (!this.#context?.unpinMessage)
4108
4191
  throw new Error("This message is not attached to a client.");
4109
- return this.#context.unpinMessage(this.channelId, this.id);
4192
+ return this.#context.unpinMessage(this.channelId, this.id, reason);
4110
4193
  }
4111
4194
  get isEphemeral() {
4112
4195
  return (this.flags & 64) !== 0;
@@ -4285,15 +4368,22 @@ class EmojiManager extends Manager {
4285
4368
  return data.map((item) => this.upsert(item));
4286
4369
  }
4287
4370
  async create(options) {
4288
- return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), options));
4371
+ const [payload, reason] = splitReason(options);
4372
+ return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), payload, { reason }));
4289
4373
  }
4290
4374
  async edit(emojiId, options) {
4291
- return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), options));
4375
+ const [payload, reason] = splitReason(options);
4376
+ return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), payload, { reason }));
4292
4377
  }
4293
- async deleteEmoji(emojiId) {
4294
- await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId));
4378
+ async remove(emojiId, reason) {
4379
+ await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId), {
4380
+ reason
4381
+ });
4295
4382
  this.delete(emojiId);
4296
4383
  }
4384
+ deleteEmoji(emojiId) {
4385
+ return this.remove(emojiId);
4386
+ }
4297
4387
  upsert(data) {
4298
4388
  const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
4299
4389
  return this.#merge(key, new Emoji(data));
@@ -4497,11 +4587,16 @@ class GuildMemberManager extends ResourceManager {
4497
4587
  await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
4498
4588
  this.delete(userId);
4499
4589
  }
4500
- async unban(userId) {
4501
- await this.#rest.delete(Routes.guildBan(this.guildId, userId));
4590
+ async unban(userId, reason) {
4591
+ await this.#rest.delete(Routes.guildBan(this.guildId, userId), {
4592
+ reason
4593
+ });
4502
4594
  }
4503
4595
  async edit(userId, options, reason) {
4504
- const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options, { reason });
4596
+ const [payload, optionsReason] = splitReason(options);
4597
+ const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), payload, {
4598
+ reason: optionsReason ?? reason
4599
+ });
4505
4600
  const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
4506
4601
  this.set(member.user.id, member);
4507
4602
  return member;
@@ -4540,7 +4635,7 @@ class RoleManager extends ResourceManager {
4540
4635
  const data = await this.#rest.post(Routes.guildRoles(this.guildId), {
4541
4636
  ...payload,
4542
4637
  permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
4543
- });
4638
+ }, { reason });
4544
4639
  const role = new Role(data);
4545
4640
  this.set(role.id, role);
4546
4641
  return role;
@@ -4550,15 +4645,28 @@ class RoleManager extends ResourceManager {
4550
4645
  const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), {
4551
4646
  ...payload,
4552
4647
  permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
4553
- });
4648
+ }, { reason });
4554
4649
  const role = new Role(data);
4555
4650
  this.set(role.id, role);
4556
4651
  return role;
4557
4652
  }
4558
- async deleteRole(roleId) {
4559
- await this.#rest.delete(Routes.guildRole(this.guildId, roleId));
4653
+ async remove(roleId, reason) {
4654
+ await this.#rest.delete(Routes.guildRole(this.guildId, roleId), {
4655
+ reason
4656
+ });
4560
4657
  this.delete(roleId);
4561
4658
  }
4659
+ async setPositions(positions, reason) {
4660
+ const data = await this.#rest.patch(Routes.guildRoles(this.guildId), positions.map(({ id, position }) => ({ id, position })), { reason });
4661
+ return data.map((item) => {
4662
+ const role = new Role(item);
4663
+ this.set(role.id, role);
4664
+ return role;
4665
+ });
4666
+ }
4667
+ deleteRole(roleId) {
4668
+ return this.remove(roleId);
4669
+ }
4562
4670
  }
4563
4671
 
4564
4672
  // packages/managers/src/guild-resources.ts
@@ -4630,13 +4738,15 @@ class GuildScheduledEventManager extends Manager {
4630
4738
  return events.map((event) => this.#store(event));
4631
4739
  }
4632
4740
  async create(options, reason) {
4633
- return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), options, { reason }));
4741
+ const [payload, optionsReason] = splitReason(options);
4742
+ return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), payload, { reason: optionsReason ?? reason }));
4634
4743
  }
4635
4744
  async edit(eventId, options, reason) {
4636
- return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), options, { reason }));
4745
+ const [payload, optionsReason] = splitReason(options);
4746
+ return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), payload, { reason: optionsReason ?? reason }));
4637
4747
  }
4638
- async remove(eventId) {
4639
- await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId));
4748
+ async remove(eventId, reason) {
4749
+ await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId), { reason });
4640
4750
  this.delete(eventId);
4641
4751
  }
4642
4752
  async fetchSubscribers(eventId, options = {}) {
@@ -4667,13 +4777,13 @@ class StageInstanceManager extends Manager {
4667
4777
  privacy_level: options.privacyLevel,
4668
4778
  send_start_notification: options.sendStartNotification,
4669
4779
  guild_scheduled_event_id: options.guildScheduledEventId
4670
- }, { reason }));
4780
+ }, { reason: options.reason ?? reason }));
4671
4781
  }
4672
4782
  async fetch(channelId) {
4673
4783
  return this.#store(await this.#rest.get(Routes.stageInstanceByChannel(channelId)));
4674
4784
  }
4675
4785
  async edit(channelId, options, reason) {
4676
- return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason }));
4786
+ return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason: options.reason ?? reason }));
4677
4787
  }
4678
4788
  async remove(channelId, reason) {
4679
4789
  await this.#rest.delete(Routes.stageInstanceByChannel(channelId), {
@@ -4710,7 +4820,7 @@ class PermissionOverwriteManager {
4710
4820
  type: options.type,
4711
4821
  allow: BigInt(options.allow ?? 0).toString(),
4712
4822
  deny: BigInt(options.deny ?? 0).toString()
4713
- }, { reason });
4823
+ }, { reason: options.reason ?? reason });
4714
4824
  }
4715
4825
  async remove(overwriteId, reason) {
4716
4826
  await this.#rest.delete(Routes.channelPermission(this.channelId, overwriteId), { reason });
@@ -4828,12 +4938,16 @@ class GuildManager extends ResourceManager {
4828
4938
  return this.upsert(new Guild(data));
4829
4939
  }
4830
4940
  async edit(id, options) {
4831
- const data = await this.#rest.patch(Routes.guild(id), options);
4941
+ const [payload, reason] = splitReason(options);
4942
+ const data = await this.#rest.patch(Routes.guild(id), payload, { reason });
4832
4943
  return this.upsert(new Guild(data));
4833
4944
  }
4834
- async deleteGuild(id) {
4945
+ async remove(id) {
4835
4946
  await this.#rest.delete(Routes.guild(id));
4836
4947
  }
4948
+ deleteGuild(id) {
4949
+ return this.remove(id);
4950
+ }
4837
4951
  async fetchPreview(id) {
4838
4952
  return this.#rest.get(Routes.guildPreview(id));
4839
4953
  }
@@ -4877,15 +4991,17 @@ class GuildManager extends ResourceManager {
4877
4991
  return new AutoModerationRule(rule);
4878
4992
  }
4879
4993
  async createAutoModerationRule(guildId, options) {
4880
- const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), options);
4994
+ const [payload, reason] = splitReason(options);
4995
+ const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), payload, { reason });
4881
4996
  return new AutoModerationRule(rule);
4882
4997
  }
4883
4998
  async editAutoModerationRule(guildId, ruleId, options) {
4884
- const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), options);
4999
+ const [payload, reason] = splitReason(options);
5000
+ const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), payload, { reason });
4885
5001
  return new AutoModerationRule(rule);
4886
5002
  }
4887
- async deleteAutoModerationRule(guildId, ruleId) {
4888
- await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId));
5003
+ async deleteAutoModerationRule(guildId, ruleId, reason) {
5004
+ await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId), { reason });
4889
5005
  }
4890
5006
  }
4891
5007
  var AuditLogEvent = {
@@ -5001,16 +5117,16 @@ class ChannelManager extends Manager {
5001
5117
  this.#context = {
5002
5118
  sendMessage: (channelId, options) => this.send(channelId, options),
5003
5119
  editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
5004
- deleteMessage: (channelId, messageId) => this.deleteMessage(channelId, messageId),
5120
+ deleteMessage: (channelId, messageId, reason) => this.deleteMessage(channelId, messageId, reason),
5005
5121
  crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId),
5006
5122
  editChannel: (channelId, options) => this.edit(channelId, options),
5007
- deleteChannel: (channelId) => this.deleteChannel(channelId),
5123
+ deleteChannel: (channelId, reason) => this.remove(channelId, reason),
5008
5124
  addReaction: (channelId, messageId, emoji) => this.addReaction(channelId, messageId, emoji),
5009
5125
  removeOwnReaction: (channelId, messageId, emoji) => this.removeOwnReaction(channelId, messageId, emoji),
5010
5126
  removeReaction: (channelId, messageId, emoji, userId) => this.removeReaction(channelId, messageId, emoji, userId),
5011
5127
  removeAllReactions: (channelId, messageId) => this.removeAllReactions(channelId, messageId),
5012
- pinMessage: (channelId, messageId) => this.pinMessage(channelId, messageId),
5013
- unpinMessage: (channelId, messageId) => this.unpinMessage(channelId, messageId)
5128
+ pinMessage: (channelId, messageId, reason) => this.pinMessage(channelId, messageId, reason),
5129
+ unpinMessage: (channelId, messageId, reason) => this.unpinMessage(channelId, messageId, reason)
5014
5130
  };
5015
5131
  }
5016
5132
  messages(channelId) {
@@ -5080,15 +5196,20 @@ class ChannelManager extends Manager {
5080
5196
  return this.#messageManagers.get(channelId);
5081
5197
  }
5082
5198
  async create(guildId, options) {
5083
- return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), options));
5199
+ const [payload, reason] = splitReason(options);
5200
+ return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), payload, { reason }));
5084
5201
  }
5085
5202
  async edit(channelId, options) {
5086
- return this.upsert(await this.#rest.patch(Routes.channel(channelId), options));
5203
+ const [payload, reason] = splitReason(options);
5204
+ return this.upsert(await this.#rest.patch(Routes.channel(channelId), payload, { reason }));
5087
5205
  }
5088
- async deleteChannel(channelId) {
5089
- await this.#rest.delete(Routes.channel(channelId));
5206
+ async remove(channelId, reason) {
5207
+ await this.#rest.delete(Routes.channel(channelId), { reason });
5090
5208
  this.delete(channelId);
5091
5209
  }
5210
+ deleteChannel(channelId) {
5211
+ return this.remove(channelId);
5212
+ }
5092
5213
  delete(channelId) {
5093
5214
  this.#messageManagers.delete(channelId);
5094
5215
  return super.delete(channelId);
@@ -5124,8 +5245,10 @@ class ChannelManager extends Manager {
5124
5245
  async editMessage(channelId, messageId, options) {
5125
5246
  return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), toRequest(options, this.#allowedMentions)));
5126
5247
  }
5127
- async deleteMessage(channelId, messageId) {
5128
- await this.#rest.delete(Routes.message(channelId, messageId));
5248
+ async deleteMessage(channelId, messageId, reason) {
5249
+ await this.#rest.delete(Routes.message(channelId, messageId), {
5250
+ reason
5251
+ });
5129
5252
  this.messages(channelId).delete(messageId);
5130
5253
  }
5131
5254
  deleteCachedMessage(channelId, messageId) {
@@ -5134,19 +5257,17 @@ class ChannelManager extends Manager {
5134
5257
  async crosspostMessage(channelId, messageId) {
5135
5258
  return this.messages(channelId).upsert(await this.#rest.post(Routes.crosspostMessage(channelId, messageId)));
5136
5259
  }
5137
- async bulkDeleteMessages(channelId, messageIds) {
5260
+ async bulkDeleteMessages(channelId, messageIds, reason) {
5138
5261
  const ids = [...new Set(messageIds)];
5139
5262
  if (ids.length < 1 || ids.length > 100)
5140
5263
  throw new RangeError("bulkDelete requires between 1 and 100 message IDs.");
5141
5264
  if (ids.length === 1)
5142
- return this.deleteMessage(channelId, ids[0]);
5265
+ return this.deleteMessage(channelId, ids[0], reason);
5143
5266
  const cutoff = Date.now() - BULK_DELETE_MAX_AGE_MS;
5144
5267
  const tooOld = ids.filter((id) => snowflakeTime(id) < cutoff);
5145
5268
  if (tooOld.length)
5146
5269
  throw new RangeError(`bulkDelete cannot delete messages older than 14 days: ${tooOld.join(", ")}`);
5147
- await this.#rest.post(Routes.channelBulkDelete(channelId), {
5148
- messages: ids
5149
- });
5270
+ await this.#rest.post(Routes.channelBulkDelete(channelId), { messages: ids }, { reason });
5150
5271
  for (const id of ids)
5151
5272
  this.messages(channelId).delete(id);
5152
5273
  }
@@ -5189,14 +5310,20 @@ class ChannelManager extends Manager {
5189
5310
  await this.#rest.delete(Routes.messageReactionsAll(channelId, messageId));
5190
5311
  }
5191
5312
  async fetchPinnedMessages(channelId) {
5192
- const data = await this.#rest.get(Routes.channelPins(channelId));
5193
- return data.map((item) => this.messages(channelId).upsert(item));
5313
+ const data = await this.#rest.get(Routes.channelMessagesPins(channelId));
5314
+ return data.items.map((item) => this.messages(channelId).upsert(item.message));
5194
5315
  }
5195
- async pinMessage(channelId, messageId) {
5196
- await this.#rest.put(Routes.channelPin(channelId, messageId));
5316
+ async pinMessage(channelId, messageId, reason) {
5317
+ await this.#rest.put(Routes.channelMessagesPin(channelId, messageId), undefined, { reason });
5197
5318
  }
5198
- async unpinMessage(channelId, messageId) {
5199
- await this.#rest.delete(Routes.channelPin(channelId, messageId));
5319
+ async unpinMessage(channelId, messageId, reason) {
5320
+ await this.#rest.delete(Routes.channelMessagesPin(channelId, messageId), { reason });
5321
+ }
5322
+ async createWebhook(channelId, options) {
5323
+ const [payload, reason] = splitReason(options);
5324
+ return this.#rest.post(Routes.channelWebhooks(channelId), payload, {
5325
+ reason
5326
+ });
5200
5327
  }
5201
5328
  createThreadFromMessage(channelId, messageId, options) {
5202
5329
  return this.threads(channelId).createFromMessage(messageId, options);
@@ -5214,7 +5341,7 @@ class ChannelManager extends Manager {
5214
5341
  hasMore: messages.length === limit
5215
5342
  };
5216
5343
  }
5217
- async bulkDelete(channelId, messageIds) {
5344
+ bulkDelete(channelId, messageIds) {
5218
5345
  return this.bulkDeleteMessages(channelId, messageIds);
5219
5346
  }
5220
5347
  clear() {
@@ -6369,18 +6496,31 @@ class EventEmitter2 {
6369
6496
  return true;
6370
6497
  }
6371
6498
  #handleError(event, error) {
6372
- if (event === "error" /* Error */)
6373
- return;
6374
6499
  const normalized = error instanceof Error ? error : new Error(String(error), { cause: error });
6375
- for (const listener of [
6500
+ const listeners = event === "error" /* Error */ ? [] : [
6376
6501
  ...this.#listeners.get("error" /* Error */) ?? []
6377
- ]) {
6502
+ ];
6503
+ if (listeners.length === 0)
6504
+ return warnListenerError(event, normalized);
6505
+ for (const listener of listeners) {
6378
6506
  try {
6379
- listener(normalized);
6380
- } catch {}
6507
+ const result = listener(normalized);
6508
+ if (result && typeof result.then === "function")
6509
+ Promise.resolve(result).catch((failure) => warnListenerError("error" /* Error */, failure));
6510
+ } catch (failure) {
6511
+ warnListenerError("error" /* Error */, failure);
6512
+ }
6381
6513
  }
6382
6514
  }
6383
6515
  }
6516
+ function warnListenerError(event, error) {
6517
+ const failure = error instanceof Error ? error : new Error(String(error));
6518
+ process.emitWarning(`A "${String(event)}" listener threw and no error listener handled it: ${failure.message}`, {
6519
+ type: "LunibeeWarning",
6520
+ code: "LUNIBEE_UNHANDLED_LISTENER_ERROR",
6521
+ detail: failure.stack
6522
+ });
6523
+ }
6384
6524
 
6385
6525
  class Client extends EventEmitter2 {
6386
6526
  options;
@@ -6449,16 +6589,16 @@ class Client extends EventEmitter2 {
6449
6589
  this.#resourceContext = {
6450
6590
  sendMessage: (channelId, options) => this.channels.send(channelId, options),
6451
6591
  editMessage: (channelId, messageId, options) => this.channels.editMessage(channelId, messageId, options),
6452
- deleteMessage: (channelId, messageId) => this.channels.deleteMessage(channelId, messageId),
6592
+ deleteMessage: (channelId, messageId, reason) => this.channels.deleteMessage(channelId, messageId, reason),
6453
6593
  crosspostMessage: (channelId, messageId) => this.channels.crosspostMessage(channelId, messageId),
6454
6594
  editChannel: (channelId, options) => this.channels.edit(channelId, options),
6455
- deleteChannel: (channelId) => this.channels.deleteChannel(channelId),
6595
+ deleteChannel: (channelId, reason) => this.channels.remove(channelId, reason),
6456
6596
  addReaction: (channelId, messageId, emoji) => this.channels.addReaction(channelId, messageId, emoji),
6457
6597
  removeOwnReaction: (channelId, messageId, emoji) => this.channels.removeOwnReaction(channelId, messageId, emoji),
6458
6598
  removeReaction: (channelId, messageId, emoji, userId) => this.channels.removeReaction(channelId, messageId, emoji, userId),
6459
6599
  removeAllReactions: (channelId, messageId) => this.channels.removeAllReactions(channelId, messageId),
6460
- pinMessage: (channelId, messageId) => this.channels.pinMessage(channelId, messageId),
6461
- unpinMessage: (channelId, messageId) => this.channels.unpinMessage(channelId, messageId),
6600
+ pinMessage: (channelId, messageId, reason) => this.channels.pinMessage(channelId, messageId, reason),
6601
+ unpinMessage: (channelId, messageId, reason) => this.channels.unpinMessage(channelId, messageId, reason),
6462
6602
  collectInteractions: (options) => this.createCollector("interactionCreate" /* InteractionCreate */, options),
6463
6603
  memberPermissions: (guildId, memberId, roleIds, channelId) => this.#memberPermissions(guildId, memberId, roleIds, channelId),
6464
6604
  kickMember: (guildId, userId, reason) => this.guilds.members(guildId).kick(userId, reason),
@@ -7011,8 +7151,6 @@ class Client extends EventEmitter2 {
7011
7151
  const query = new URLSearchParams;
7012
7152
  if (options?.withCounts)
7013
7153
  query.set("with_counts", "true");
7014
- if (options?.withExpiration)
7015
- query.set("with_expiration", "true");
7016
7154
  if (options?.guildScheduledEventId)
7017
7155
  query.set("guild_scheduled_event_id", options.guildScheduledEventId);
7018
7156
  const qs = query.toString();
@@ -7156,7 +7294,7 @@ class HandlerRegistry {
7156
7294
  // packages/sharding/package.json
7157
7295
  var package_default2 = {
7158
7296
  name: "@lunibee/sharding",
7159
- version: "0.2.2",
7297
+ version: "0.2.3",
7160
7298
  type: "module",
7161
7299
  module: "./src/index.ts",
7162
7300
  types: "./src/index.ts",
@@ -7369,12 +7507,12 @@ class ClusterManager {
7369
7507
  const clusterCount = this.#options.clusterCount ?? cpus().length;
7370
7508
  const chunks = Array.from({ length: clusterCount }, () => []);
7371
7509
  for (let i = 0;i < count; i++) {
7372
- chunks[i % clusterCount].push(i);
7510
+ chunks[i % clusterCount]?.push(i);
7373
7511
  }
7374
- for (let i = 0;i < clusterCount; i++) {
7375
- if (chunks[i].length === 0)
7512
+ for (const [i, chunk] of chunks.entries()) {
7513
+ if (chunk.length === 0)
7376
7514
  continue;
7377
- this.#launch(i, chunks[i], count);
7515
+ this.#launch(i, chunk, count);
7378
7516
  await sleep2(500);
7379
7517
  }
7380
7518
  if (this.#options.autoScaleInterval && this.#options.autoScaleInterval > 0) {
@@ -8224,9 +8362,10 @@ class VoiceReceiver {
8224
8362
  const controllers = this.#streams.get(userId);
8225
8363
  if (!controllers || controllers.size === 0)
8226
8364
  return;
8227
- const csrcCount = packet[0] & 15;
8365
+ const first = view.getUint8(0);
8366
+ const csrcCount = first & 15;
8228
8367
  let offset = 12 + csrcCount * 4;
8229
- const hasExtension = (packet[0] & 16) !== 0;
8368
+ const hasExtension = (first & 16) !== 0;
8230
8369
  if (hasExtension) {
8231
8370
  if (packet.length < offset + 4)
8232
8371
  return;
@@ -9028,6 +9167,10 @@ var ApplicationCommandOptionEnum2 = {
9028
9167
  Number: 10,
9029
9168
  Attachment: 11
9030
9169
  };
9170
+ function validateContexts(contexts) {
9171
+ if (contexts.some((context) => context !== 0 && context !== 1 && context !== 2))
9172
+ throw new RangeError("Command contexts must be 0, 1 or 2.");
9173
+ }
9031
9174
 
9032
9175
  class CreateSlashCommand {
9033
9176
  #data = { type: 1 };
@@ -9041,6 +9184,11 @@ class CreateSlashCommand {
9041
9184
  this.#data.description = description;
9042
9185
  return this;
9043
9186
  }
9187
+ setContexts(...contexts) {
9188
+ validateContexts(contexts);
9189
+ this.#data.contexts = [...contexts];
9190
+ return this;
9191
+ }
9044
9192
  setDMPermission(enabled) {
9045
9193
  this.#data.dm_permission = enabled;
9046
9194
  return this;
@@ -9400,8 +9548,7 @@ class CreateContextMenuCommand {
9400
9548
  return this;
9401
9549
  }
9402
9550
  setContexts(...contexts) {
9403
- if (contexts.some((context) => context !== 0 && context !== 1 && context !== 2))
9404
- throw new RangeError("Command contexts must be 0, 1 or 2.");
9551
+ validateContexts(contexts);
9405
9552
  this.data.contexts = [...contexts];
9406
9553
  return this;
9407
9554
  }
@@ -9544,6 +9691,7 @@ export {
9544
9691
  CreateButton,
9545
9692
  CreateChannelOption,
9546
9693
  CreateChannelSelectMenu,
9694
+ CreateCommandOption,
9547
9695
  CreateContainer,
9548
9696
  CreateContentInventoryEntry,
9549
9697
  CreateContextMenuCommand,
@@ -9646,6 +9794,7 @@ export {
9646
9794
  PremiumTier,
9647
9795
  REST,
9648
9796
  RESTError,
9797
+ RESTErrorCode,
9649
9798
  RateLimiter,
9650
9799
  RedisRateLimitStore,
9651
9800
  RequestScheduler,
@@ -9761,4 +9910,4 @@ export {
9761
9910
  userMention
9762
9911
  };
9763
9912
 
9764
- //# debugId=FC58C0F70BD3B2A964756E2164756E21
9913
+ //# debugId=97695754EB32311964756E2164756E21