@impulsedev/chameleon 3.5.0 → 3.6.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/index.js CHANGED
@@ -33,7 +33,7 @@ import {
33
33
  serializeComponent,
34
34
  toCamelCase,
35
35
  toSnakeCase
36
- } from "./chunk-G4SUOXGV.js";
36
+ } from "./chunk-SEC6DGVP.js";
37
37
 
38
38
  // src/types/user/index.ts
39
39
  var UserFlag = {
@@ -887,6 +887,7 @@ var ChameleonREST = class {
887
887
  ok: false,
888
888
  status: response.status,
889
889
  ...typeof errData?.code === "number" ? { code: errData.code } : {},
890
+ error: typeof errData?.message === "string" ? errData.message : response.statusText,
890
891
  message: typeof errData?.message === "string" ? errData.message : response.statusText,
891
892
  raw: data
892
893
  };
@@ -894,6 +895,7 @@ var ChameleonREST = class {
894
895
  return {
895
896
  ok: false,
896
897
  status: 0,
898
+ error: error instanceof Error ? error.message : "Unknown network error",
897
899
  message: error instanceof Error ? error.message : "Unknown network error"
898
900
  };
899
901
  }
@@ -958,6 +960,7 @@ var ChameleonREST = class {
958
960
  ok: false,
959
961
  status: response.status,
960
962
  ...typeof errData?.code === "number" ? { code: errData.code } : {},
963
+ error: typeof errData?.message === "string" ? errData.message : response.statusText,
961
964
  message: typeof errData?.message === "string" ? errData.message : response.statusText,
962
965
  raw: data
963
966
  };
@@ -965,6 +968,7 @@ var ChameleonREST = class {
965
968
  return {
966
969
  ok: false,
967
970
  status: 0,
971
+ error: error instanceof Error ? error.message : "Unknown network error",
968
972
  message: error instanceof Error ? error.message : "Unknown network error"
969
973
  };
970
974
  }
@@ -1338,7 +1342,7 @@ var ChameleonGateway = class {
1338
1342
  // package.json
1339
1343
  var package_default = {
1340
1344
  name: "@impulsedev/chameleon",
1341
- version: "3.0.0",
1345
+ version: "3.6.0",
1342
1346
  description: "highly optimized, memory-efficient, and fully type-safe Discord API library",
1343
1347
  main: "dist/index.js",
1344
1348
  types: "dist/index.d.ts",
@@ -1414,6 +1418,12 @@ var CHAMELEON_VERSION = package_default.version;
1414
1418
  var CHAMELEON = package_default.name;
1415
1419
 
1416
1420
  // src/commands/options.ts
1421
+ function choice(name, value) {
1422
+ return { name, value };
1423
+ }
1424
+ function choices(...items) {
1425
+ return items;
1426
+ }
1417
1427
  var opt = {
1418
1428
  string: (description, options) => ({
1419
1429
  type: "string",
@@ -1446,12 +1456,317 @@ var opt = {
1446
1456
  channel: (description, options) => ({
1447
1457
  type: "channel",
1448
1458
  description,
1449
- required: options?.required ?? false
1459
+ required: options?.required ?? false,
1460
+ ...options
1450
1461
  }),
1451
1462
  role: (description, options) => ({
1452
1463
  type: "role",
1453
1464
  description,
1454
1465
  required: options?.required ?? false
1466
+ }),
1467
+ mentionable: (description, options) => ({
1468
+ type: "mentionable",
1469
+ description,
1470
+ required: options?.required ?? false
1471
+ }),
1472
+ attachment: (description, options) => ({
1473
+ type: "attachment",
1474
+ description,
1475
+ required: options?.required ?? false
1476
+ })
1477
+ };
1478
+
1479
+ // src/components/define.ts
1480
+ function resolveButtonStyle(style) {
1481
+ if (typeof style === "number") return style;
1482
+ const map = { primary: 1, secondary: 2, success: 3, danger: 4, link: 5, premium: 6 };
1483
+ return map[style] ?? 1;
1484
+ }
1485
+ function defineButton(def) {
1486
+ return { ...def, type: "button" };
1487
+ }
1488
+ var Button = {
1489
+ /** Build a reusable button definition that can be used in both V1 action rows and V2 accessories */
1490
+ of: (def) => defineButton(def),
1491
+ /** @param customId Component custom ID sent back in the interaction payload @param label Visible button text */
1492
+ primary: (customId, label) => defineButton({ customId, label, style: "primary" }),
1493
+ /** @param customId Component custom ID sent back in the interaction payload @param label Visible button text */
1494
+ secondary: (customId, label) => defineButton({ customId, label, style: "secondary" }),
1495
+ /** @param customId Component custom ID sent back in the interaction payload @param label Visible button text */
1496
+ success: (customId, label) => defineButton({ customId, label, style: "success" }),
1497
+ /** @param customId Component custom ID sent back in the interaction payload @param label Visible button text */
1498
+ danger: (customId, label) => defineButton({ customId, label, style: "danger" }),
1499
+ /** @param url Destination URL opened by the button @param label Visible button text */
1500
+ link: (url, label) => defineButton({ url, label, style: "link" }),
1501
+ /** @param skuId Premium SKU ID used by Discord premium buttons @param label Visible button text */
1502
+ premium: (skuId, label) => defineButton({ skuId, label, style: "premium" })
1503
+ };
1504
+ function defineStringSelect(def) {
1505
+ return { ...def, type: "string_select" };
1506
+ }
1507
+ function defineUserSelect(def) {
1508
+ return { ...def, type: "user_select" };
1509
+ }
1510
+ function defineRoleSelect(def) {
1511
+ return { ...def, type: "role_select" };
1512
+ }
1513
+ function defineChannelSelect(def) {
1514
+ return { ...def, type: "channel_select" };
1515
+ }
1516
+ function defineMentionableSelect(def) {
1517
+ return { ...def, type: "mentionable_select" };
1518
+ }
1519
+ var field = {
1520
+ /**
1521
+ * Create a single-line text input field for a modal
1522
+ * @param id Field ID used as the key inside `ctx.fields`
1523
+ * @param label Visible field label shown in the modal
1524
+ * @param options Extra validation and UX settings for the text input
1525
+ */
1526
+ short: (id, label, options) => ({
1527
+ id,
1528
+ type: 1 /* SHORT */,
1529
+ label,
1530
+ required: options?.required ?? true,
1531
+ ...options
1532
+ }),
1533
+ /**
1534
+ * Create a multi-line text input field for a modal
1535
+ * @param id Field ID used as the key inside `ctx.fields`
1536
+ * @param label Visible field label shown in the modal
1537
+ * @param options Extra validation and UX settings for the paragraph input
1538
+ */
1539
+ paragraph: (id, label, options) => ({
1540
+ id,
1541
+ type: 2 /* PARAGRAPH */,
1542
+ label,
1543
+ required: options?.required ?? true,
1544
+ ...options
1545
+ }),
1546
+ /**
1547
+ * Create a boolean checkbox field for a modal
1548
+ * @param id Field ID used as the key inside `ctx.fields`
1549
+ * @param label Visible field label shown in the modal
1550
+ * @param options Checkbox settings such as `required` and default `value`
1551
+ */
1552
+ checkbox: (id, label, options) => ({
1553
+ id,
1554
+ type: 23,
1555
+ label,
1556
+ required: options?.required ?? true,
1557
+ ...options
1558
+ }),
1559
+ /**
1560
+ * Create a multi-select checkbox group field for a modal
1561
+ * @param id Field ID used as the key inside `ctx.fields`
1562
+ * @param label Visible field label shown in the modal
1563
+ * @param options Available choices and selection limits
1564
+ */
1565
+ checkboxGroup: (id, label, options) => ({
1566
+ id,
1567
+ type: 22,
1568
+ label,
1569
+ required: options?.required ?? true,
1570
+ ...options
1571
+ }),
1572
+ /**
1573
+ * Create a single-choice radio group field for a modal
1574
+ * @param id Field ID used as the key inside `ctx.fields`
1575
+ * @param label Visible field label shown in the modal
1576
+ * @param options Available choices for the radio group
1577
+ */
1578
+ radioGroup: (id, label, options) => ({
1579
+ id,
1580
+ type: 21,
1581
+ label,
1582
+ required: options?.required ?? true,
1583
+ ...options
1584
+ }),
1585
+ /**
1586
+ * Create a file upload field for a modal
1587
+ * Submitted files are available in `ctx.attachments[id]`
1588
+ * @param id Field ID used as the key inside `ctx.fields` and `ctx.attachments`
1589
+ * @param label Visible field label shown in the modal
1590
+ * @param options Upload field settings such as `required`
1591
+ */
1592
+ fileUpload: (id, label, options) => ({
1593
+ id,
1594
+ type: 19,
1595
+ label,
1596
+ required: options?.required ?? true,
1597
+ ...options
1598
+ })
1599
+ };
1600
+ function defineModal(def) {
1601
+ return { ...def, type: "modal" };
1602
+ }
1603
+ var ModalDefinitionBuilder = class _ModalDefinitionBuilder {
1604
+ constructor(customId, title, fieldsDef = []) {
1605
+ this.customId = customId;
1606
+ this.title = title;
1607
+ this.fieldsDef = fieldsDef;
1608
+ }
1609
+ customId;
1610
+ title;
1611
+ fieldsDef;
1612
+ /**
1613
+ * Append one or more fields to the modal definition
1614
+ * The resulting builder keeps full type information, so added field IDs become available in `ctx.fields`
1615
+ * @param fields Fields to add to the modal
1616
+ */
1617
+ add(...fields) {
1618
+ return new _ModalDefinitionBuilder(
1619
+ this.customId,
1620
+ this.title,
1621
+ [...this.fieldsDef, ...fields]
1622
+ );
1623
+ }
1624
+ /**
1625
+ * Finalize the modal definition and attach its submit handler
1626
+ * The handler receives a strongly-typed `ctx.fields` object derived from the fields added to this builder
1627
+ * @param execute Modal submit handler
1628
+ */
1629
+ execute(execute) {
1630
+ return defineModal({
1631
+ customId: this.customId,
1632
+ title: this.title,
1633
+ fields: this.fieldsDef,
1634
+ execute
1635
+ });
1636
+ }
1637
+ handle(execute) {
1638
+ return this.execute(execute);
1639
+ }
1640
+ };
1641
+ function modal(customId, title) {
1642
+ return new ModalDefinitionBuilder(customId, title);
1643
+ }
1644
+
1645
+ // src/components/v2.ts
1646
+ function serializeV2Button(button) {
1647
+ const obj = {
1648
+ type: 2 /* BUTTON */,
1649
+ custom_id: button.customId,
1650
+ url: button.url,
1651
+ label: button.label,
1652
+ style: resolveButtonStyle(button.style),
1653
+ disabled: button.disabled,
1654
+ emoji: button.emoji,
1655
+ sku_id: button.skuId
1656
+ };
1657
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== void 0));
1658
+ }
1659
+ function normalizeV2Component(component) {
1660
+ if (component && typeof component === "object" && "type" in component && component.type === "button") {
1661
+ return serializeV2Button(component);
1662
+ }
1663
+ if (component && typeof component.toJSON === "function") {
1664
+ return component.toJSON();
1665
+ }
1666
+ return component;
1667
+ }
1668
+ function serializeModalFieldComponent(field2) {
1669
+ return {
1670
+ type: field2.type === 1 /* SHORT */ || field2.type === 2 /* PARAGRAPH */ ? 4 /* TEXT_INPUT */ : field2.type,
1671
+ custom_id: field2.id,
1672
+ required: field2.required,
1673
+ style: field2.type === 1 /* SHORT */ || field2.type === 2 /* PARAGRAPH */ ? field2.type : void 0,
1674
+ min_length: field2.minLength,
1675
+ max_length: field2.maxLength,
1676
+ placeholder: field2.placeholder,
1677
+ value: field2.value,
1678
+ options: field2.options,
1679
+ min_values: field2.minValues,
1680
+ max_values: field2.maxValues
1681
+ };
1682
+ }
1683
+ var SectionBuilder = class {
1684
+ data;
1685
+ constructor(components, accessory) {
1686
+ this.data = {
1687
+ type: 9 /* SECTION */,
1688
+ components
1689
+ };
1690
+ if (accessory) {
1691
+ this.data.accessory = accessory;
1692
+ }
1693
+ }
1694
+ accessory(accessory) {
1695
+ this.data.accessory = accessory;
1696
+ return this;
1697
+ }
1698
+ toJSON() {
1699
+ return {
1700
+ ...this.data,
1701
+ components: this.data.components.map((component) => normalizeV2Component(component)),
1702
+ ...this.data.accessory ? { accessory: normalizeV2Component(this.data.accessory) } : {}
1703
+ };
1704
+ }
1705
+ };
1706
+ var TextDisplay = {
1707
+ of: (content) => ({
1708
+ type: 10 /* TEXT_DISPLAY */,
1709
+ content
1710
+ })
1711
+ };
1712
+ var Thumbnail = {
1713
+ of: (url, description, spoiler) => ({
1714
+ type: 11 /* THUMBNAIL */,
1715
+ media: { url },
1716
+ description,
1717
+ spoiler
1718
+ })
1719
+ };
1720
+ var Separator = {
1721
+ of: (spacing, divider) => ({
1722
+ type: 14 /* SEPARATOR */,
1723
+ spacing,
1724
+ divider
1725
+ })
1726
+ };
1727
+ var Section = {
1728
+ /**
1729
+ * Section builder
1730
+ * @param components Child components rendered inside the section body
1731
+ * @param accessory Optional accessory rendered on the side of the section
1732
+ */
1733
+ of: (components, accessory) => {
1734
+ return new SectionBuilder(components, accessory);
1735
+ },
1736
+ /** @param content Text rendered as a single TextDisplay inside the section */
1737
+ text: (content) => {
1738
+ return Section.of([TextDisplay.of(content)]);
1739
+ }
1740
+ };
1741
+ var Container = {
1742
+ /**
1743
+ * Container builder
1744
+ * @param components Child components rendered inside the container
1745
+ * @param spoiler Whether the container should be hidden behind a spoiler
1746
+ */
1747
+ of: (components, spoiler) => {
1748
+ const obj = {
1749
+ type: 17 /* CONTAINER */,
1750
+ components
1751
+ };
1752
+ if (spoiler !== void 0) {
1753
+ obj.spoiler = spoiler;
1754
+ }
1755
+ return obj;
1756
+ },
1757
+ /** Helper for stacking V2 components vertically without manually creating an array */
1758
+ stack: (...components) => {
1759
+ return Container.of(components);
1760
+ }
1761
+ };
1762
+ var Label = {
1763
+ /** Wrap a modal field component in a V2 label container */
1764
+ of: (field2) => ({
1765
+ type: 18 /* LABEL */,
1766
+ label: field2.label,
1767
+ component: Object.fromEntries(
1768
+ Object.entries(serializeModalFieldComponent(field2)).filter(([, value]) => value !== void 0)
1769
+ )
1455
1770
  })
1456
1771
  };
1457
1772
 
@@ -1473,12 +1788,21 @@ var BaseInteractionContext = class {
1473
1788
  this.guild = guild;
1474
1789
  this.channel = channel;
1475
1790
  }
1791
+ get client() {
1792
+ return this._client;
1793
+ }
1476
1794
  get replied() {
1477
1795
  return this._replied;
1478
1796
  }
1479
1797
  get deferred() {
1480
1798
  return this._deferred;
1481
1799
  }
1800
+ _assertOk(result, action) {
1801
+ if (result.ok) return;
1802
+ const details = result.message ? `: ${result.message}` : "";
1803
+ const raw = result.raw !== void 0 ? ` | raw=${JSON.stringify(result.raw)}` : "";
1804
+ throw new Error(`Discord rejected interaction ${action}${details}${raw}`);
1805
+ }
1482
1806
  _resolvePayload(payload) {
1483
1807
  const data = typeof payload === "string" ? { content: payload } : { ...payload };
1484
1808
  if (typeof payload === "object") {
@@ -1497,52 +1821,46 @@ var BaseInteractionContext = class {
1497
1821
  }
1498
1822
  return data;
1499
1823
  }
1824
+ _serializeModalField(field2) {
1825
+ return Label.of(field2);
1826
+ }
1500
1827
  async reply(payload) {
1501
1828
  if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
1502
1829
  const data = this._resolvePayload(payload);
1503
- await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1830
+ const result = await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1504
1831
  type: 4 /* CHANNEL_MESSAGE_WITH_SOURCE */,
1505
1832
  data
1506
1833
  });
1834
+ this._assertOk(result, "reply");
1507
1835
  this._replied = true;
1508
1836
  }
1509
1837
  async defer(options) {
1510
1838
  if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
1511
- await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1839
+ const result = await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1512
1840
  type: 5 /* DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE */,
1513
1841
  data: { flags: options?.ephemeral ? MESSAGE_FLAGS.EPHEMERAL : 0 }
1514
1842
  });
1843
+ this._assertOk(result, "defer");
1515
1844
  this._deferred = true;
1516
1845
  }
1517
1846
  async followUp(payload) {
1518
1847
  if (!this._deferred && !this._replied) throw new Error("Interaction not acknowledged.");
1519
1848
  const data = this._resolvePayload(payload);
1520
- await this._client.rest.post(`/webhooks/${this._client.user?.id}/${this.interactionToken}`, data);
1849
+ const result = await this._client.rest.post(`/webhooks/${this._client.user?.id}/${this.interactionToken}`, data);
1850
+ this._assertOk(result, "followUp");
1521
1851
  }
1522
- async showModal(modal) {
1852
+ async showModal(modal2) {
1523
1853
  if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
1524
- const payload = modal.type === "modal" ? {
1525
- custom_id: modal.customId,
1526
- title: modal.title,
1527
- components: Array.isArray(modal.fields) ? modal.fields.map((f) => ({
1528
- type: 1 /* ACTION_ROW */,
1529
- components: [{
1530
- type: 4 /* TEXT_INPUT */,
1531
- custom_id: f.id,
1532
- style: f.type,
1533
- label: f.label,
1534
- required: f.required,
1535
- min_length: f.minLength,
1536
- max_length: f.maxLength,
1537
- placeholder: f.placeholder,
1538
- value: f.value
1539
- }]
1540
- })) : []
1541
- } : modal;
1542
- await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1854
+ const payload = modal2.type === "modal" ? {
1855
+ custom_id: modal2.customId,
1856
+ title: modal2.title,
1857
+ components: Array.isArray(modal2.fields) ? modal2.fields.map((f) => this._serializeModalField(f)) : []
1858
+ } : modal2;
1859
+ const result = await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1543
1860
  type: 9 /* MODAL */,
1544
1861
  data: payload
1545
1862
  });
1863
+ this._assertOk(result, "showModal");
1546
1864
  this._replied = true;
1547
1865
  }
1548
1866
  };
@@ -1554,32 +1872,457 @@ var CommandContext = class extends BaseInteractionContext {
1554
1872
  }
1555
1873
  };
1556
1874
 
1875
+ // src/utils/bitfield.ts
1876
+ var BitField = class _BitField {
1877
+ static FLAGS = {};
1878
+ bitfield;
1879
+ constructor(bits = 0n) {
1880
+ this.bitfield = this.constructor.resolve(bits);
1881
+ }
1882
+ has(bit) {
1883
+ const resolved = this.constructor.resolve(bit);
1884
+ return (this.bitfield & resolved) === resolved;
1885
+ }
1886
+ any(bit) {
1887
+ const resolved = this.constructor.resolve(bit);
1888
+ return (this.bitfield & resolved) !== 0n;
1889
+ }
1890
+ add(...bits) {
1891
+ let total = 0n;
1892
+ for (const bit of bits) {
1893
+ total |= this.constructor.resolve(bit);
1894
+ }
1895
+ this.bitfield |= total;
1896
+ return this;
1897
+ }
1898
+ remove(...bits) {
1899
+ let total = 0n;
1900
+ for (const bit of bits) {
1901
+ total |= this.constructor.resolve(bit);
1902
+ }
1903
+ this.bitfield &= ~total;
1904
+ return this;
1905
+ }
1906
+ toArray() {
1907
+ const flags = this.constructor.FLAGS;
1908
+ return Object.keys(flags).filter((flag) => this.has(flags[flag]));
1909
+ }
1910
+ serialize() {
1911
+ const flags = this.constructor.FLAGS;
1912
+ const result = {};
1913
+ for (const [flag, value] of Object.entries(flags)) {
1914
+ result[flag] = this.has(value);
1915
+ }
1916
+ return result;
1917
+ }
1918
+ equals(other) {
1919
+ return this.bitfield === this.constructor.resolve(other);
1920
+ }
1921
+ freeze() {
1922
+ return Object.freeze(this);
1923
+ }
1924
+ toString() {
1925
+ return this.bitfield.toString();
1926
+ }
1927
+ toJSON() {
1928
+ return this.toString();
1929
+ }
1930
+ static resolve(bit) {
1931
+ if (typeof bit === "bigint") return bit;
1932
+ if (typeof bit === "number") return BigInt(bit);
1933
+ if (bit instanceof _BitField) return bit.bitfield;
1934
+ if (typeof bit === "string") {
1935
+ const flag = this.FLAGS[bit];
1936
+ if (flag !== void 0) return flag;
1937
+ const parsed = BigInt(bit);
1938
+ return parsed;
1939
+ }
1940
+ if (Array.isArray(bit)) {
1941
+ return bit.reduce((acc, b) => acc | this.resolve(b), 0n);
1942
+ }
1943
+ throw new TypeError(`Cannot resolve BitField from: ${bit}`);
1944
+ }
1945
+ };
1946
+
1947
+ // src/types/permissions.ts
1948
+ var PermissionsBitField = class _PermissionsBitField extends BitField {
1949
+ static FLAGS = { ...DISCORD_PERMISSIONS };
1950
+ static ALL = Object.values(DISCORD_PERMISSIONS).reduce((a, b) => a | b, 0n);
1951
+ get isAdmin() {
1952
+ return this.has("ADMINISTRATOR");
1953
+ }
1954
+ static from(bits) {
1955
+ return new _PermissionsBitField(bits);
1956
+ }
1957
+ };
1958
+ var UserFlagsBitField = class extends BitField {
1959
+ static FLAGS = {
1960
+ STAFF: 1n << 0n,
1961
+ PARTNER: 1n << 1n,
1962
+ HYPESQUAD: 1n << 2n,
1963
+ BUG_HUNTER_LEVEL_1: 1n << 3n,
1964
+ HYPESQUAD_ONLINE_HOUSE_1: 1n << 6n,
1965
+ HYPESQUAD_ONLINE_HOUSE_2: 1n << 7n,
1966
+ HYPESQUAD_ONLINE_HOUSE_3: 1n << 8n,
1967
+ PREMIUM_EARLY_SUPPORTER: 1n << 9n,
1968
+ TEAM_PSEUDO_USER: 1n << 10n,
1969
+ BUG_HUNTER_LEVEL_2: 1n << 14n,
1970
+ VERIFIED_BOT: 1n << 16n,
1971
+ VERIFIED_DEVELOPER: 1n << 17n,
1972
+ CERTIFIED_MODERATOR: 1n << 18n,
1973
+ BOT_HTTP_INTERACTIONS: 1n << 19n,
1974
+ ACTIVE_DEVELOPER: 1n << 22n
1975
+ };
1976
+ };
1977
+ var IntentsBitField = class extends BitField {
1978
+ static FLAGS = {
1979
+ Guilds: 1n << 0n,
1980
+ GuildMembers: 1n << 1n,
1981
+ GuildModeration: 1n << 2n,
1982
+ GuildEmojisAndStickers: 1n << 3n,
1983
+ GuildIntegrations: 1n << 4n,
1984
+ GuildWebhooks: 1n << 5n,
1985
+ GuildInvites: 1n << 6n,
1986
+ GuildVoiceStates: 1n << 7n,
1987
+ GuildPresences: 1n << 8n,
1988
+ GuildMessages: 1n << 9n,
1989
+ GuildMessageReactions: 1n << 10n,
1990
+ GuildMessageTyping: 1n << 11n,
1991
+ DirectMessages: 1n << 12n,
1992
+ DirectMessageReactions: 1n << 13n,
1993
+ DirectMessageTyping: 1n << 14n,
1994
+ MessageContent: 1n << 15n,
1995
+ GuildScheduledEvents: 1n << 16n,
1996
+ AutoModerationConfiguration: 1n << 20n,
1997
+ AutoModerationExecution: 1n << 21n,
1998
+ GuildMessagePolls: 1n << 24n,
1999
+ DirectMessagePolls: 1n << 25n
2000
+ };
2001
+ };
2002
+ function computeBasePermissions(member, guild) {
2003
+ if (member.roles === void 0) return 0n;
2004
+ const userId = member.user?.id;
2005
+ if (userId && userId === guild.ownerId) return PermissionsBitField.ALL;
2006
+ const everyoneRole = guild.roles.find((r) => r.id === guild.id);
2007
+ let permissions = everyoneRole ? BigInt(everyoneRole.permissions) : 0n;
2008
+ for (const roleId of member.roles) {
2009
+ const role = guild.roles.find((r) => r.id === roleId);
2010
+ if (role) permissions |= BigInt(role.permissions);
2011
+ }
2012
+ if ((permissions & DISCORD_PERMISSIONS.ADMINISTRATOR) === DISCORD_PERMISSIONS.ADMINISTRATOR) {
2013
+ return PermissionsBitField.ALL;
2014
+ }
2015
+ return permissions;
2016
+ }
2017
+ function computeChannelPermissions(basePermissions, overwrites, memberRoles, memberId) {
2018
+ if ((basePermissions & DISCORD_PERMISSIONS.ADMINISTRATOR) === DISCORD_PERMISSIONS.ADMINISTRATOR) {
2019
+ return PermissionsBitField.ALL;
2020
+ }
2021
+ let permissions = basePermissions;
2022
+ let allow = 0n;
2023
+ let deny = 0n;
2024
+ for (const overwrite of overwrites) {
2025
+ if (overwrite.type === 0) {
2026
+ if (memberRoles.includes(overwrite.id) || overwrites.indexOf(overwrite) === 0) {
2027
+ if (overwrites.indexOf(overwrite) === 0 && !memberRoles.includes(overwrite.id)) {
2028
+ permissions &= ~BigInt(overwrite.deny);
2029
+ permissions |= BigInt(overwrite.allow);
2030
+ } else {
2031
+ allow |= BigInt(overwrite.allow);
2032
+ deny |= BigInt(overwrite.deny);
2033
+ }
2034
+ }
2035
+ }
2036
+ }
2037
+ permissions &= ~deny;
2038
+ permissions |= allow;
2039
+ if (memberId) {
2040
+ const memberOverwrite = overwrites.find((ow) => ow.type === 1 && ow.id === memberId);
2041
+ if (memberOverwrite) {
2042
+ permissions &= ~BigInt(memberOverwrite.deny);
2043
+ permissions |= BigInt(memberOverwrite.allow);
2044
+ }
2045
+ }
2046
+ return permissions;
2047
+ }
2048
+
1557
2049
  // src/commands/command.ts
1558
2050
  function defineSubcommand(def) {
1559
2051
  return def;
1560
2052
  }
2053
+ function defineSubcommandGroup(def) {
2054
+ return def;
2055
+ }
1561
2056
  function defineCommand(def) {
1562
2057
  if (!def.execute && (!def.subcommands || Object.keys(def.subcommands).length === 0)) {
1563
2058
  throw new Error(`Command ${def.name} must have an execute function or subcommands.`);
1564
2059
  }
1565
2060
  return def;
1566
2061
  }
2062
+ function appendOption(optionsDef, name, definition) {
2063
+ return {
2064
+ ...optionsDef ?? {},
2065
+ [name]: definition
2066
+ };
2067
+ }
2068
+ function normalizeChoicesOptions(choicesOrOptions, maybeOptions) {
2069
+ if (Array.isArray(choicesOrOptions)) {
2070
+ return {
2071
+ ...maybeOptions ?? {},
2072
+ choices: choicesOrOptions
2073
+ };
2074
+ }
2075
+ if (choicesOrOptions) {
2076
+ return choicesOrOptions;
2077
+ }
2078
+ return void 0;
2079
+ }
2080
+ var SubcommandDefinitionBuilder = class _SubcommandDefinitionBuilder {
2081
+ constructor(description, optionsDef) {
2082
+ this.description = description;
2083
+ this.optionsDef = optionsDef;
2084
+ }
2085
+ description;
2086
+ optionsDef;
2087
+ options(options) {
2088
+ return new _SubcommandDefinitionBuilder(this.description, options);
2089
+ }
2090
+ option(name, definition) {
2091
+ return new _SubcommandDefinitionBuilder(
2092
+ this.description,
2093
+ appendOption(this.optionsDef, name, definition)
2094
+ );
2095
+ }
2096
+ string(name, description, choicesOrOptions, maybeOptions) {
2097
+ return this.option(name, opt.string(description, normalizeChoicesOptions(choicesOrOptions, maybeOptions)));
2098
+ }
2099
+ integer(name, description, choicesOrOptions, maybeOptions) {
2100
+ return this.option(name, opt.integer(description, normalizeChoicesOptions(choicesOrOptions, maybeOptions)));
2101
+ }
2102
+ number(name, description, choicesOrOptions, maybeOptions) {
2103
+ return this.option(name, opt.number(description, normalizeChoicesOptions(choicesOrOptions, maybeOptions)));
2104
+ }
2105
+ boolean(name, description, options) {
2106
+ return this.option(name, opt.boolean(description, options));
2107
+ }
2108
+ user(name, description, options) {
2109
+ return this.option(name, opt.user(description, options));
2110
+ }
2111
+ channel(name, description, options) {
2112
+ return this.option(name, opt.channel(description, options));
2113
+ }
2114
+ role(name, description, options) {
2115
+ return this.option(name, opt.role(description, options));
2116
+ }
2117
+ mentionable(name, description, options) {
2118
+ return this.option(name, opt.mentionable(description, options));
2119
+ }
2120
+ attachment(name, description, options) {
2121
+ return this.option(name, opt.attachment(description, options));
2122
+ }
2123
+ execute(execute) {
2124
+ return defineSubcommand({
2125
+ description: this.description,
2126
+ ...this.optionsDef ? { options: this.optionsDef } : {},
2127
+ execute
2128
+ });
2129
+ }
2130
+ handle(execute) {
2131
+ return this.execute(execute);
2132
+ }
2133
+ };
2134
+ var SubcommandGroupDefinitionBuilder = class _SubcommandGroupDefinitionBuilder {
2135
+ constructor(description, subcommandsDef) {
2136
+ this.description = description;
2137
+ this.subcommandsDef = subcommandsDef;
2138
+ }
2139
+ description;
2140
+ subcommandsDef;
2141
+ subcommands(subcommands) {
2142
+ return new _SubcommandGroupDefinitionBuilder(this.description, subcommands);
2143
+ }
2144
+ subcommand(name, subcommand2) {
2145
+ return new _SubcommandGroupDefinitionBuilder(
2146
+ this.description,
2147
+ {
2148
+ ...this.subcommandsDef ?? {},
2149
+ [name]: subcommand2
2150
+ }
2151
+ );
2152
+ }
2153
+ toGroup() {
2154
+ return defineSubcommandGroup({
2155
+ description: this.description,
2156
+ subcommands: this.subcommandsDef ?? {}
2157
+ });
2158
+ }
2159
+ build() {
2160
+ return this.toGroup();
2161
+ }
2162
+ };
2163
+ var CommandDefinitionBuilder = class _CommandDefinitionBuilder {
2164
+ constructor(name, description, optionsDef, subcommandsDef, metadata = {}) {
2165
+ this.name = name;
2166
+ this.description = description;
2167
+ this.optionsDef = optionsDef;
2168
+ this.subcommandsDef = subcommandsDef;
2169
+ this.metadata = metadata;
2170
+ }
2171
+ name;
2172
+ description;
2173
+ optionsDef;
2174
+ subcommandsDef;
2175
+ metadata;
2176
+ options(options) {
2177
+ return new _CommandDefinitionBuilder(this.name, this.description, options, this.subcommandsDef, this.metadata);
2178
+ }
2179
+ option(name, definition) {
2180
+ return new _CommandDefinitionBuilder(
2181
+ this.name,
2182
+ this.description,
2183
+ appendOption(this.optionsDef, name, definition),
2184
+ this.subcommandsDef,
2185
+ this.metadata
2186
+ );
2187
+ }
2188
+ string(name, description, choicesOrOptions, maybeOptions) {
2189
+ return this.option(name, opt.string(description, normalizeChoicesOptions(choicesOrOptions, maybeOptions)));
2190
+ }
2191
+ integer(name, description, choicesOrOptions, maybeOptions) {
2192
+ return this.option(name, opt.integer(description, normalizeChoicesOptions(choicesOrOptions, maybeOptions)));
2193
+ }
2194
+ number(name, description, choicesOrOptions, maybeOptions) {
2195
+ return this.option(name, opt.number(description, normalizeChoicesOptions(choicesOrOptions, maybeOptions)));
2196
+ }
2197
+ boolean(name, description, options) {
2198
+ return this.option(name, opt.boolean(description, options));
2199
+ }
2200
+ user(name, description, options) {
2201
+ return this.option(name, opt.user(description, options));
2202
+ }
2203
+ channel(name, description, options) {
2204
+ return this.option(name, opt.channel(description, options));
2205
+ }
2206
+ role(name, description, options) {
2207
+ return this.option(name, opt.role(description, options));
2208
+ }
2209
+ mentionable(name, description, options) {
2210
+ return this.option(name, opt.mentionable(description, options));
2211
+ }
2212
+ attachment(name, description, options) {
2213
+ return this.option(name, opt.attachment(description, options));
2214
+ }
2215
+ subcommands(subcommands) {
2216
+ return new _CommandDefinitionBuilder(this.name, this.description, this.optionsDef, subcommands, this.metadata);
2217
+ }
2218
+ subcommand(name, subcommand2) {
2219
+ return new _CommandDefinitionBuilder(
2220
+ this.name,
2221
+ this.description,
2222
+ this.optionsDef,
2223
+ {
2224
+ ...this.subcommandsDef ?? {},
2225
+ [name]: subcommand2
2226
+ },
2227
+ this.metadata
2228
+ );
2229
+ }
2230
+ group(name, group) {
2231
+ const normalized = typeof group.toGroup === "function" ? group.toGroup() : group;
2232
+ return new _CommandDefinitionBuilder(
2233
+ this.name,
2234
+ this.description,
2235
+ this.optionsDef,
2236
+ {
2237
+ ...this.subcommandsDef ?? {},
2238
+ [name]: normalized
2239
+ },
2240
+ this.metadata
2241
+ );
2242
+ }
2243
+ setPermissions(permissions) {
2244
+ return new _CommandDefinitionBuilder(
2245
+ this.name,
2246
+ this.description,
2247
+ this.optionsDef,
2248
+ this.subcommandsDef,
2249
+ {
2250
+ ...this.metadata,
2251
+ defaultMemberPermissions: permissions === null ? null : PermissionsBitField.resolve(permissions).toString()
2252
+ }
2253
+ );
2254
+ }
2255
+ setDefaultMemberPermissions(permissions) {
2256
+ return this.setPermissions(permissions);
2257
+ }
2258
+ execute(execute) {
2259
+ return defineCommand({
2260
+ name: this.name,
2261
+ description: this.description,
2262
+ ...this.optionsDef ? { options: this.optionsDef } : {},
2263
+ ...this.subcommandsDef ? { subcommands: this.subcommandsDef } : {},
2264
+ ...this.metadata.defaultMemberPermissions !== void 0 ? { defaultMemberPermissions: this.metadata.defaultMemberPermissions } : {},
2265
+ execute
2266
+ });
2267
+ }
2268
+ handle(execute) {
2269
+ return this.execute(execute);
2270
+ }
2271
+ toCommand() {
2272
+ return defineCommand({
2273
+ name: this.name,
2274
+ description: this.description,
2275
+ ...this.optionsDef ? { options: this.optionsDef } : {},
2276
+ ...this.subcommandsDef ? { subcommands: this.subcommandsDef } : {},
2277
+ ...this.metadata.defaultMemberPermissions !== void 0 ? { defaultMemberPermissions: this.metadata.defaultMemberPermissions } : {}
2278
+ });
2279
+ }
2280
+ build() {
2281
+ return this.toCommand();
2282
+ }
2283
+ };
2284
+ function command(name, description) {
2285
+ return new CommandDefinitionBuilder(name, description);
2286
+ }
2287
+ function subcommand(description) {
2288
+ return new SubcommandDefinitionBuilder(description);
2289
+ }
2290
+ function subcommandGroup(description) {
2291
+ return new SubcommandGroupDefinitionBuilder(description);
2292
+ }
1567
2293
 
1568
2294
  // src/commands/interactions.ts
1569
2295
  var ModalContext = class extends BaseInteractionContext {
1570
2296
  customId;
2297
+ attachments = {};
1571
2298
  _fields = /* @__PURE__ */ new Map();
1572
2299
  constructor(client, raw, user, guild, channel) {
1573
2300
  super(client, raw, user, guild, channel);
1574
- this.customId = raw.data?.custom_id ?? "";
1575
- const rows = raw.data?.components ?? [];
1576
- for (const row of rows) {
1577
- for (const comp of row.components ?? []) {
1578
- if (comp.custom_id && comp.value !== void 0) {
1579
- this._fields.set(comp.custom_id, comp.value);
2301
+ const data = raw.data ?? {};
2302
+ this.customId = data.custom_id ?? "";
2303
+ const rows = data.components ?? [];
2304
+ const resolvedAttachments = data.resolved?.attachments ?? {};
2305
+ const extractFields = (components) => {
2306
+ for (const comp of components) {
2307
+ if (comp.custom_id) {
2308
+ if (comp.values !== void 0) {
2309
+ this._fields.set(comp.custom_id, comp.values);
2310
+ if (Array.isArray(comp.values)) {
2311
+ this.attachments[comp.custom_id] = comp.values.map((id) => resolvedAttachments[id]).filter((attachment) => attachment !== void 0);
2312
+ }
2313
+ } else if (comp.value !== void 0) {
2314
+ this._fields.set(comp.custom_id, comp.value);
2315
+ }
2316
+ }
2317
+ if (Array.isArray(comp.components)) {
2318
+ extractFields(comp.components);
2319
+ }
2320
+ if (comp.component && typeof comp.component === "object") {
2321
+ extractFields([comp.component]);
1580
2322
  }
1581
2323
  }
1582
- }
2324
+ };
2325
+ extractFields(rows);
1583
2326
  }
1584
2327
  // Get a text input value by its customId
1585
2328
  // values from a select menu interaction
@@ -1608,28 +2351,43 @@ var ComponentContext = class extends BaseInteractionContext {
1608
2351
  this.values = data?.values ?? [];
1609
2352
  const fields = {};
1610
2353
  if (data?.components) {
1611
- for (const row of data.components) {
1612
- for (const comp of row.components) {
1613
- fields[comp.custom_id] = comp.value;
2354
+ const extractFields = (components) => {
2355
+ for (const comp of components) {
2356
+ if (comp.custom_id !== void 0) {
2357
+ if (comp.values !== void 0) {
2358
+ fields[comp.custom_id] = comp.values;
2359
+ } else if (comp.value !== void 0) {
2360
+ fields[comp.custom_id] = comp.value;
2361
+ }
2362
+ }
2363
+ if (comp.components) {
2364
+ extractFields(comp.components);
2365
+ }
2366
+ if (comp.component) {
2367
+ extractFields([comp.component]);
2368
+ }
1614
2369
  }
1615
- }
2370
+ };
2371
+ extractFields(data.components);
1616
2372
  }
1617
2373
  this.fields = fields;
1618
2374
  }
1619
2375
  async deferUpdate() {
1620
2376
  if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
1621
- await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
2377
+ const result = await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1622
2378
  type: 6 /* DEFERRED_UPDATE_MESSAGE */
1623
2379
  });
2380
+ this._assertOk(result, "deferUpdate");
1624
2381
  this._deferred = true;
1625
2382
  }
1626
2383
  async update(payload) {
1627
2384
  if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
1628
2385
  const data = this._resolvePayload(payload);
1629
- await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
2386
+ const result = await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
1630
2387
  type: 7 /* UPDATE_MESSAGE */,
1631
2388
  data
1632
2389
  });
2390
+ this._assertOk(result, "update");
1633
2391
  this._replied = true;
1634
2392
  }
1635
2393
  };
@@ -1637,6 +2395,9 @@ var ComponentContext = class extends BaseInteractionContext {
1637
2395
  // src/commands/manager.ts
1638
2396
  import * as fs from "fs";
1639
2397
  import * as path from "path";
2398
+ function isSubcommandGroup(candidate) {
2399
+ return "subcommands" in candidate;
2400
+ }
1640
2401
  var CommandManager = class {
1641
2402
  _commands = /* @__PURE__ */ new Map();
1642
2403
  _components = [];
@@ -1646,16 +2407,18 @@ var CommandManager = class {
1646
2407
  this._client = client;
1647
2408
  }
1648
2409
  register(...commands) {
1649
- for (const cmd of commands) {
2410
+ const normalized = commands.map((cmd) => this._normalizeCommand(cmd));
2411
+ for (const cmd of normalized) {
1650
2412
  this._commands.set(cmd.name, cmd);
1651
2413
  }
1652
- this._deployCommands(commands).catch(console.error);
2414
+ this._deployCommands(normalized).catch(console.error);
1653
2415
  }
1654
2416
  registerGuild(guildId, ...commands) {
1655
- for (const cmd of commands) {
2417
+ const normalized = commands.map((cmd) => this._normalizeCommand(cmd));
2418
+ for (const cmd of normalized) {
1656
2419
  this._commands.set(cmd.name, cmd);
1657
2420
  }
1658
- this._deployCommands(commands, guildId).catch(console.error);
2421
+ this._deployCommands(normalized, guildId).catch(console.error);
1659
2422
  }
1660
2423
  registerComponent(handler) {
1661
2424
  this._components.push(handler);
@@ -1675,9 +2438,9 @@ var CommandManager = class {
1675
2438
  const filePath = path.join(fullPath, file);
1676
2439
  try {
1677
2440
  const module = await import(`file://${filePath}`);
1678
- const command = module.default;
1679
- if (command && typeof command.name === "string") {
1680
- commands.push(command);
2441
+ const command2 = module.default;
2442
+ if (command2 && (typeof command2.name === "string" || typeof command2.toCommand === "function")) {
2443
+ commands.push(command2);
1681
2444
  }
1682
2445
  } catch (err) {
1683
2446
  console.error(`[Chameleon] Failed to load command from ${file}:`, err);
@@ -1714,15 +2477,54 @@ var CommandManager = class {
1714
2477
  return 7;
1715
2478
  case "role":
1716
2479
  return 8;
2480
+ case "mentionable":
2481
+ return 9;
1717
2482
  case "number":
1718
2483
  return 10;
2484
+ case "attachment":
2485
+ return 11;
1719
2486
  default:
1720
2487
  return 3;
1721
2488
  }
1722
2489
  };
1723
2490
  const options = [];
1724
2491
  if (cmd.subcommands) {
1725
- for (const [subName, subDef] of Object.entries(cmd.subcommands)) {
2492
+ for (const [subName, subDefRaw] of Object.entries(cmd.subcommands)) {
2493
+ const candidate = subDefRaw;
2494
+ if (isSubcommandGroup(candidate)) {
2495
+ const nested = Object.entries(candidate.subcommands).map(([nestedName, nestedDefRaw]) => {
2496
+ const nestedDef = nestedDefRaw;
2497
+ const nestedOptions = nestedDef.options ? Object.entries(nestedDef.options).map(([optName, optDefRaw]) => {
2498
+ const optDef = optDefRaw;
2499
+ return {
2500
+ type: mapType(optDef.type),
2501
+ name: optName,
2502
+ description: optDef.description,
2503
+ required: optDef.required,
2504
+ choices: optDef.choices,
2505
+ channel_types: optDef.channelTypes,
2506
+ min_value: optDef.min,
2507
+ max_value: optDef.max,
2508
+ min_length: optDef.minLength,
2509
+ max_length: optDef.maxLength
2510
+ };
2511
+ }) : [];
2512
+ return {
2513
+ type: 1 /* SUB_COMMAND */,
2514
+ name: nestedName,
2515
+ description: nestedDef.description,
2516
+ options: nestedOptions
2517
+ };
2518
+ });
2519
+ options.push({
2520
+ type: 2 /* SUB_COMMAND_GROUP */,
2521
+ name: subName,
2522
+ description: candidate.description,
2523
+ options: nested
2524
+ });
2525
+ continue;
2526
+ }
2527
+ const subDef = candidate;
1726
2528
  const subOpts = [];
1727
2529
  if (subDef.options) {
1728
2530
  for (const [optName, optDefRaw] of Object.entries(subDef.options)) {
@@ -1733,8 +2535,11 @@ var CommandManager = class {
1733
2535
  description: optDef.description,
1734
2536
  required: optDef.required,
1735
2537
  choices: optDef.choices,
2538
+ channel_types: optDef.channelTypes,
1736
2539
  min_value: optDef.min,
1737
- max_value: optDef.max
2540
+ max_value: optDef.max,
2541
+ min_length: optDef.minLength,
2542
+ max_length: optDef.maxLength
1738
2543
  });
1739
2544
  }
1740
2545
  }
@@ -1754,17 +2559,27 @@ var CommandManager = class {
1754
2559
  description: optDef.description,
1755
2560
  required: optDef.required,
1756
2561
  choices: optDef.choices,
2562
+ channel_types: optDef.channelTypes,
1757
2563
  min_value: optDef.min,
1758
- max_value: optDef.max
2564
+ max_value: optDef.max,
2565
+ min_length: optDef.minLength,
2566
+ max_length: optDef.maxLength
1759
2567
  });
1760
2568
  }
1761
2569
  }
1762
2570
  return {
1763
2571
  name: cmd.name,
1764
2572
  description: cmd.description,
2573
+ default_member_permissions: cmd.defaultMemberPermissions ?? void 0,
1765
2574
  options: options.length ? options : void 0
1766
2575
  };
1767
2576
  }
2577
+ _normalizeCommand(command2) {
2578
+ if (typeof command2.toCommand === "function") {
2579
+ return command2.toCommand();
2580
+ }
2581
+ return command2;
2582
+ }
1768
2583
  async handleInteraction(raw) {
1769
2584
  const data = raw.data;
1770
2585
  if (!data) return;
@@ -1773,17 +2588,29 @@ var CommandManager = class {
1773
2588
  if (raw.type !== 2 /* APPLICATION_COMMAND */) return;
1774
2589
  const name = data.name;
1775
2590
  if (!name) return;
1776
- const command = this._commands.get(name);
1777
- if (!command) return;
2591
+ const command2 = this._commands.get(name);
2592
+ if (!command2) return;
1778
2593
  const parsedOptions = {};
1779
- let targetExecute = command.execute;
2594
+ let targetExecute = command2.execute;
1780
2595
  const rawOptions = data.options || [];
1781
2596
  let actualOptions = rawOptions;
1782
- if (rawOptions.length > 0 && rawOptions[0].type === 1 /* SUB_COMMAND */) {
2597
+ if (rawOptions.length > 0 && rawOptions[0].type === 2 /* SUB_COMMAND_GROUP */) {
2598
+ const groupName = rawOptions[0].name;
2599
+ const groupOption = rawOptions[0];
2600
+ const nestedSubcommand = groupOption.options?.[0];
2601
+ if (nestedSubcommand) {
2602
+ actualOptions = nestedSubcommand.options || [];
2603
+ const group = command2.subcommands?.[groupName];
2604
+ const targetSubcommand = group?.subcommands?.[nestedSubcommand.name];
2605
+ if (targetSubcommand) {
2606
+ targetExecute = targetSubcommand.execute;
2607
+ }
2608
+ }
2609
+ } else if (rawOptions.length > 0 && rawOptions[0].type === 1 /* SUB_COMMAND */) {
1783
2610
  const subcommandName = rawOptions[0].name;
1784
2611
  actualOptions = rawOptions[0].options || [];
1785
- if (command.subcommands && command.subcommands[subcommandName]) {
1786
- targetExecute = command.subcommands[subcommandName].execute;
2612
+ if (command2.subcommands && command2.subcommands[subcommandName]) {
2613
+ targetExecute = command2.subcommands[subcommandName].execute;
1787
2614
  }
1788
2615
  }
1789
2616
  for (const opt2 of actualOptions) {
@@ -1793,6 +2620,16 @@ var CommandManager = class {
1793
2620
  parsedOptions[opt2.name] = resolveChannel(opt2.value, this._client);
1794
2621
  } else if (opt2.type === 8 /* ROLE */ && data.resolved?.roles?.[opt2.value]) {
1795
2622
  parsedOptions[opt2.name] = resolveRole(opt2.value, this._client, raw.guild_id);
2623
+ } else if (opt2.type === 9 /* MENTIONABLE */) {
2624
+ if (data.resolved?.users?.[opt2.value]) {
2625
+ parsedOptions[opt2.name] = resolveUser(opt2.value, this._client);
2626
+ } else if (data.resolved?.roles?.[opt2.value]) {
2627
+ parsedOptions[opt2.name] = resolveRole(opt2.value, this._client, raw.guild_id);
2628
+ } else {
2629
+ parsedOptions[opt2.name] = opt2.value;
2630
+ }
2631
+ } else if (opt2.type === 11 /* ATTACHMENT */ && data.resolved?.attachments?.[opt2.value]) {
2632
+ parsedOptions[opt2.name] = data.resolved.attachments[opt2.value];
1796
2633
  } else {
1797
2634
  parsedOptions[opt2.name] = opt2.value;
1798
2635
  }
@@ -1863,50 +2700,6 @@ var CommandManager = class {
1863
2700
  }
1864
2701
  };
1865
2702
 
1866
- // src/components/define.ts
1867
- function resolveButtonStyle(style) {
1868
- if (typeof style === "number") return style;
1869
- const map = { primary: 1, secondary: 2, success: 3, danger: 4, link: 5, premium: 6 };
1870
- return map[style] ?? 1;
1871
- }
1872
- function defineButton(def) {
1873
- return { ...def, type: "button" };
1874
- }
1875
- function defineStringSelect(def) {
1876
- return { ...def, type: "string_select" };
1877
- }
1878
- function defineUserSelect(def) {
1879
- return { ...def, type: "user_select" };
1880
- }
1881
- function defineRoleSelect(def) {
1882
- return { ...def, type: "role_select" };
1883
- }
1884
- function defineChannelSelect(def) {
1885
- return { ...def, type: "channel_select" };
1886
- }
1887
- function defineMentionableSelect(def) {
1888
- return { ...def, type: "mentionable_select" };
1889
- }
1890
- var field = {
1891
- short: (id, label, options) => ({
1892
- id,
1893
- type: 1 /* SHORT */,
1894
- label,
1895
- required: options?.required ?? true,
1896
- ...options
1897
- }),
1898
- paragraph: (id, label, options) => ({
1899
- id,
1900
- type: 2 /* PARAGRAPH */,
1901
- label,
1902
- required: options?.required ?? true,
1903
- ...options
1904
- })
1905
- };
1906
- function defineModal(def) {
1907
- return { ...def, type: "modal" };
1908
- }
1909
-
1910
2703
  // src/components/actionRow.ts
1911
2704
  var ActionRow = {
1912
2705
  of: (...components) => {
@@ -1968,6 +2761,38 @@ var ActionRow = {
1968
2761
  value: field2.value
1969
2762
  };
1970
2763
  }
2764
+ if ("type" in c && c.type === 23 /* CHECKBOX */) {
2765
+ const field2 = c;
2766
+ return {
2767
+ type: 23 /* CHECKBOX */,
2768
+ custom_id: field2.id,
2769
+ label: field2.label,
2770
+ required: field2.required,
2771
+ value: field2.value
2772
+ };
2773
+ }
2774
+ if ("type" in c && c.type === 21 /* RADIO_GROUP */) {
2775
+ const field2 = c;
2776
+ return {
2777
+ type: 21 /* RADIO_GROUP */,
2778
+ custom_id: field2.id,
2779
+ label: field2.label,
2780
+ required: field2.required,
2781
+ options: field2.options
2782
+ };
2783
+ }
2784
+ if ("type" in c && c.type === 22 /* CHECKBOX_GROUP */) {
2785
+ const field2 = c;
2786
+ return {
2787
+ type: 22 /* CHECKBOX_GROUP */,
2788
+ custom_id: field2.id,
2789
+ label: field2.label,
2790
+ required: field2.required,
2791
+ min_values: field2.minValues,
2792
+ max_values: field2.maxValues,
2793
+ options: field2.options
2794
+ };
2795
+ }
1971
2796
  return c;
1972
2797
  }).map((obj) => {
1973
2798
  const clean = {};
@@ -2074,7 +2899,7 @@ var UserManager = class extends BaseManager {
2074
2899
  async createDM(userId) {
2075
2900
  const result = await this.rest.post("/users/@me/channels", { recipient_id: userId });
2076
2901
  if (!result.ok) return result;
2077
- return { ok: true, data: (await import("./builders-WHD6LQWX.js")).buildChannel(result.data) };
2902
+ return { ok: true, data: (await import("./builders-X4JJZ6M2.js")).buildChannel(result.data) };
2078
2903
  }
2079
2904
  async editCurrent(payload) {
2080
2905
  const result = await this.rest.patch("/users/@me", toSnakeCase(payload));
@@ -2108,7 +2933,7 @@ var RoleManager = class {
2108
2933
  }
2109
2934
  const target = roles.find((r) => r.id === roleId);
2110
2935
  if (target) return { ok: true, data: target };
2111
- return { ok: false, status: 404, message: "Role not found" };
2936
+ return { ok: false, status: 404, error: "Role not found", message: "Role not found" };
2112
2937
  }
2113
2938
  async list() {
2114
2939
  const result = await this.rest.get(`/guilds/${this.guildId}/roles`);
@@ -2467,7 +3292,7 @@ var ChannelManager = class extends BaseManager {
2467
3292
  }
2468
3293
  async clone(channelId, options, reason) {
2469
3294
  const cached = this.store.channels.get(channelId);
2470
- if (!cached) return { ok: false, status: 404, message: "Channel not found in cache" };
3295
+ if (!cached) return { ok: false, status: 404, error: "Channel not found in cache", message: "Channel not found in cache" };
2471
3296
  const payload = { ...options };
2472
3297
  if (cached.name !== void 0) payload.name = cached.name;
2473
3298
  if (cached.type !== void 0) payload.type = cached.type;
@@ -2479,7 +3304,7 @@ var ChannelManager = class extends BaseManager {
2479
3304
  if (cached.position !== void 0) payload.position = cached.position;
2480
3305
  if (cached.parentId !== void 0) payload.parentId = cached.parentId;
2481
3306
  if (cached.permissionOverwrites !== void 0) payload.permissionOverwrites = cached.permissionOverwrites;
2482
- if (!cached.guildId) return { ok: false, status: 400, message: "Cannot clone a DM channel" };
3307
+ if (!cached.guildId) return { ok: false, status: 400, error: "Cannot clone a DM channel", message: "Cannot clone a DM channel" };
2483
3308
  return this.create(cached.guildId, payload, reason);
2484
3309
  }
2485
3310
  async setPositions(guildId, positions, reason) {
@@ -3331,7 +4156,7 @@ var ApplicationManager = class {
3331
4156
  }
3332
4157
  async fetchRoleConnectionMetadata() {
3333
4158
  if (!this._client.user?.id) {
3334
- return { ok: false, status: 400, message: "Client not ready" };
4159
+ return { ok: false, status: 400, error: "Client not ready", message: "Client not ready" };
3335
4160
  }
3336
4161
  const result = await this.rest.get(`/applications/${this._client.user.id}/role-connections/metadata`);
3337
4162
  if (!result.ok) return result;
@@ -3339,7 +4164,7 @@ var ApplicationManager = class {
3339
4164
  }
3340
4165
  async editRoleConnectionMetadata(records) {
3341
4166
  if (!this._client.user?.id) {
3342
- return { ok: false, status: 400, message: "Client not ready" };
4167
+ return { ok: false, status: 400, error: "Client not ready", message: "Client not ready" };
3343
4168
  }
3344
4169
  const result = await this.rest.put(`/applications/${this._client.user.id}/role-connections/metadata`, records);
3345
4170
  if (!result.ok) return result;
@@ -4042,8 +4867,10 @@ var Client = class {
4042
4867
  case "INTERACTION_CREATE": {
4043
4868
  if (d.type === 2 /* APPLICATION_COMMAND */ || d.type === 4 /* APPLICATION_COMMAND_AUTOCOMPLETE */) {
4044
4869
  this.commands.handleInteraction(d).catch(console.error);
4045
- } else if (d.type === 3 /* MESSAGE_COMPONENT */ || d.type === 5 /* MODAL_SUBMIT */) {
4870
+ } else if (d.type === 3 /* MESSAGE_COMPONENT */) {
4046
4871
  this.components.handleInteraction(d).catch(console.error);
4872
+ } else if (d.type === 5 /* MODAL_SUBMIT */) {
4873
+ this.commands.handleInteraction(d).catch(console.error);
4047
4874
  }
4048
4875
  this.dispatch("INTERACTION_CREATE", {
4049
4876
  type: "INTERACTION_CREATE",
@@ -4428,180 +5255,6 @@ var Chameleon = class {
4428
5255
  }
4429
5256
  };
4430
5257
 
4431
- // src/utils/bitfield.ts
4432
- var BitField = class _BitField {
4433
- static FLAGS = {};
4434
- bitfield;
4435
- constructor(bits = 0n) {
4436
- this.bitfield = this.constructor.resolve(bits);
4437
- }
4438
- has(bit) {
4439
- const resolved = this.constructor.resolve(bit);
4440
- return (this.bitfield & resolved) === resolved;
4441
- }
4442
- any(bit) {
4443
- const resolved = this.constructor.resolve(bit);
4444
- return (this.bitfield & resolved) !== 0n;
4445
- }
4446
- add(...bits) {
4447
- let total = 0n;
4448
- for (const bit of bits) {
4449
- total |= this.constructor.resolve(bit);
4450
- }
4451
- this.bitfield |= total;
4452
- return this;
4453
- }
4454
- remove(...bits) {
4455
- let total = 0n;
4456
- for (const bit of bits) {
4457
- total |= this.constructor.resolve(bit);
4458
- }
4459
- this.bitfield &= ~total;
4460
- return this;
4461
- }
4462
- toArray() {
4463
- const flags = this.constructor.FLAGS;
4464
- return Object.keys(flags).filter((flag) => this.has(flags[flag]));
4465
- }
4466
- serialize() {
4467
- const flags = this.constructor.FLAGS;
4468
- const result = {};
4469
- for (const [flag, value] of Object.entries(flags)) {
4470
- result[flag] = this.has(value);
4471
- }
4472
- return result;
4473
- }
4474
- equals(other) {
4475
- return this.bitfield === this.constructor.resolve(other);
4476
- }
4477
- freeze() {
4478
- return Object.freeze(this);
4479
- }
4480
- toString() {
4481
- return this.bitfield.toString();
4482
- }
4483
- toJSON() {
4484
- return this.toString();
4485
- }
4486
- static resolve(bit) {
4487
- if (typeof bit === "bigint") return bit;
4488
- if (typeof bit === "number") return BigInt(bit);
4489
- if (bit instanceof _BitField) return bit.bitfield;
4490
- if (typeof bit === "string") {
4491
- const flag = this.FLAGS[bit];
4492
- if (flag !== void 0) return flag;
4493
- const parsed = BigInt(bit);
4494
- return parsed;
4495
- }
4496
- if (Array.isArray(bit)) {
4497
- return bit.reduce((acc, b) => acc | this.resolve(b), 0n);
4498
- }
4499
- throw new TypeError(`Cannot resolve BitField from: ${bit}`);
4500
- }
4501
- };
4502
-
4503
- // src/types/permissions.ts
4504
- var PermissionsBitField = class _PermissionsBitField extends BitField {
4505
- static FLAGS = { ...DISCORD_PERMISSIONS };
4506
- static ALL = Object.values(DISCORD_PERMISSIONS).reduce((a, b) => a | b, 0n);
4507
- get isAdmin() {
4508
- return this.has("ADMINISTRATOR");
4509
- }
4510
- static from(bits) {
4511
- return new _PermissionsBitField(bits);
4512
- }
4513
- };
4514
- var UserFlagsBitField = class extends BitField {
4515
- static FLAGS = {
4516
- STAFF: 1n << 0n,
4517
- PARTNER: 1n << 1n,
4518
- HYPESQUAD: 1n << 2n,
4519
- BUG_HUNTER_LEVEL_1: 1n << 3n,
4520
- HYPESQUAD_ONLINE_HOUSE_1: 1n << 6n,
4521
- HYPESQUAD_ONLINE_HOUSE_2: 1n << 7n,
4522
- HYPESQUAD_ONLINE_HOUSE_3: 1n << 8n,
4523
- PREMIUM_EARLY_SUPPORTER: 1n << 9n,
4524
- TEAM_PSEUDO_USER: 1n << 10n,
4525
- BUG_HUNTER_LEVEL_2: 1n << 14n,
4526
- VERIFIED_BOT: 1n << 16n,
4527
- VERIFIED_DEVELOPER: 1n << 17n,
4528
- CERTIFIED_MODERATOR: 1n << 18n,
4529
- BOT_HTTP_INTERACTIONS: 1n << 19n,
4530
- ACTIVE_DEVELOPER: 1n << 22n
4531
- };
4532
- };
4533
- var IntentsBitField = class extends BitField {
4534
- static FLAGS = {
4535
- Guilds: 1n << 0n,
4536
- GuildMembers: 1n << 1n,
4537
- GuildModeration: 1n << 2n,
4538
- GuildEmojisAndStickers: 1n << 3n,
4539
- GuildIntegrations: 1n << 4n,
4540
- GuildWebhooks: 1n << 5n,
4541
- GuildInvites: 1n << 6n,
4542
- GuildVoiceStates: 1n << 7n,
4543
- GuildPresences: 1n << 8n,
4544
- GuildMessages: 1n << 9n,
4545
- GuildMessageReactions: 1n << 10n,
4546
- GuildMessageTyping: 1n << 11n,
4547
- DirectMessages: 1n << 12n,
4548
- DirectMessageReactions: 1n << 13n,
4549
- DirectMessageTyping: 1n << 14n,
4550
- MessageContent: 1n << 15n,
4551
- GuildScheduledEvents: 1n << 16n,
4552
- AutoModerationConfiguration: 1n << 20n,
4553
- AutoModerationExecution: 1n << 21n,
4554
- GuildMessagePolls: 1n << 24n,
4555
- DirectMessagePolls: 1n << 25n
4556
- };
4557
- };
4558
- function computeBasePermissions(member, guild) {
4559
- if (member.roles === void 0) return 0n;
4560
- const userId = member.user?.id;
4561
- if (userId && userId === guild.ownerId) return PermissionsBitField.ALL;
4562
- const everyoneRole = guild.roles.find((r) => r.id === guild.id);
4563
- let permissions = everyoneRole ? BigInt(everyoneRole.permissions) : 0n;
4564
- for (const roleId of member.roles) {
4565
- const role = guild.roles.find((r) => r.id === roleId);
4566
- if (role) permissions |= BigInt(role.permissions);
4567
- }
4568
- if ((permissions & DISCORD_PERMISSIONS.ADMINISTRATOR) === DISCORD_PERMISSIONS.ADMINISTRATOR) {
4569
- return PermissionsBitField.ALL;
4570
- }
4571
- return permissions;
4572
- }
4573
- function computeChannelPermissions(basePermissions, overwrites, memberRoles, memberId) {
4574
- if ((basePermissions & DISCORD_PERMISSIONS.ADMINISTRATOR) === DISCORD_PERMISSIONS.ADMINISTRATOR) {
4575
- return PermissionsBitField.ALL;
4576
- }
4577
- let permissions = basePermissions;
4578
- let allow = 0n;
4579
- let deny = 0n;
4580
- for (const overwrite of overwrites) {
4581
- if (overwrite.type === 0) {
4582
- if (memberRoles.includes(overwrite.id) || overwrites.indexOf(overwrite) === 0) {
4583
- if (overwrites.indexOf(overwrite) === 0 && !memberRoles.includes(overwrite.id)) {
4584
- permissions &= ~BigInt(overwrite.deny);
4585
- permissions |= BigInt(overwrite.allow);
4586
- } else {
4587
- allow |= BigInt(overwrite.allow);
4588
- deny |= BigInt(overwrite.deny);
4589
- }
4590
- }
4591
- }
4592
- }
4593
- permissions &= ~deny;
4594
- permissions |= allow;
4595
- if (memberId) {
4596
- const memberOverwrite = overwrites.find((ow) => ow.type === 1 && ow.id === memberId);
4597
- if (memberOverwrite) {
4598
- permissions &= ~BigInt(memberOverwrite.deny);
4599
- permissions |= BigInt(memberOverwrite.allow);
4600
- }
4601
- }
4602
- return permissions;
4603
- }
4604
-
4605
5258
  // src/sharding/manager.ts
4606
5259
  import { EventEmitter } from "events";
4607
5260
  import { fork } from "child_process";
@@ -4745,6 +5398,7 @@ export {
4745
5398
  BaseInteractionContext,
4746
5399
  BaseManager,
4747
5400
  BitField,
5401
+ Button,
4748
5402
  ButtonBuilder,
4749
5403
  ButtonStyle,
4750
5404
  CHAMELEON_SELF_MAP,
@@ -4760,10 +5414,12 @@ export {
4760
5414
  CollectorManager,
4761
5415
  Colors,
4762
5416
  CommandContext,
5417
+ CommandDefinitionBuilder,
4763
5418
  CommandManager,
4764
5419
  ComponentContext,
4765
5420
  ComponentManager,
4766
5421
  ComponentType,
5422
+ Container,
4767
5423
  DISCORD_GATEWAY_OPCODES,
4768
5424
  DISCORD_PERMISSIONS,
4769
5425
  DefaultMessageNotificationLevel,
@@ -4787,6 +5443,7 @@ export {
4787
5443
  InviteManager,
4788
5444
  InviteTargetType,
4789
5445
  InviteType,
5446
+ Label,
4790
5447
  LobbyMemberFlag,
4791
5448
  MFALevel,
4792
5449
  MemberManager,
@@ -4796,12 +5453,16 @@ export {
4796
5453
  MessageReferenceType,
4797
5454
  MessageType,
4798
5455
  ModalBuilder,
5456
+ ModalContext,
5457
+ ModalDefinitionBuilder,
4799
5458
  PermissionsBitField,
4800
5459
  PremiumTier,
4801
5460
  PremiumType,
4802
5461
  RoleManager,
4803
5462
  ScheduledEventManager,
5463
+ Section,
4804
5464
  SelectMenuBuilder,
5465
+ Separator,
4805
5466
  Shard,
4806
5467
  SkuFlag,
4807
5468
  SkuType,
@@ -4811,10 +5472,14 @@ export {
4811
5472
  StagePrivacyLevel,
4812
5473
  StickerFormatType,
4813
5474
  StickerType,
5475
+ SubcommandDefinitionBuilder,
5476
+ SubcommandGroupDefinitionBuilder,
4814
5477
  SubscriptionStatus,
4815
5478
  SystemChannelFlag,
4816
5479
  TemplateManager,
5480
+ TextDisplay,
4817
5481
  TextInputBuilder,
5482
+ Thumbnail,
4818
5483
  Tongue,
4819
5484
  TongueStore,
4820
5485
  UserFlag,
@@ -4843,7 +5508,10 @@ export {
4843
5508
  buildUser,
4844
5509
  buildVoiceState,
4845
5510
  buildWebhook,
5511
+ choice,
5512
+ choices,
4846
5513
  combinePermissions,
5514
+ command,
4847
5515
  computeBasePermissions,
4848
5516
  computeChannelPermissions,
4849
5517
  defineButton,
@@ -4854,17 +5522,21 @@ export {
4854
5522
  defineRoleSelect,
4855
5523
  defineStringSelect,
4856
5524
  defineSubcommand,
5525
+ defineSubcommandGroup,
4857
5526
  defineUserSelect,
4858
5527
  field,
4859
5528
  hasAllPermissions,
4860
5529
  hasAnyPermission,
4861
5530
  hasPermission,
4862
5531
  listPermissions,
5532
+ modal,
4863
5533
  opt,
4864
5534
  resolveButtonStyle,
4865
5535
  resolveChannel,
4866
5536
  resolveGuild,
4867
5537
  resolveRole,
4868
5538
  resolveUser,
4869
- serializeComponent
5539
+ serializeComponent,
5540
+ subcommand,
5541
+ subcommandGroup
4870
5542
  };