@fluxerjs/core 1.1.1 → 1.1.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.
package/dist/index.js CHANGED
@@ -49,7 +49,8 @@ var init_ErrorCodes = __esm({
49
49
  ChannelNotFound: "CHANNEL_NOT_FOUND",
50
50
  MessageNotFound: "MESSAGE_NOT_FOUND",
51
51
  GuildNotFound: "GUILD_NOT_FOUND",
52
- MemberNotFound: "MEMBER_NOT_FOUND"
52
+ MemberNotFound: "MEMBER_NOT_FOUND",
53
+ RoleNotFound: "ROLE_NOT_FOUND"
53
54
  };
54
55
  }
55
56
  });
@@ -1148,6 +1149,50 @@ var init_Channel = __esm({
1148
1149
  }
1149
1150
  });
1150
1151
 
1152
+ // src/client/GuildMemberManager.ts
1153
+ var import_collection5, GuildMemberManager;
1154
+ var init_GuildMemberManager = __esm({
1155
+ "src/client/GuildMemberManager.ts"() {
1156
+ "use strict";
1157
+ import_collection5 = require("@fluxerjs/collection");
1158
+ GuildMemberManager = class extends import_collection5.Collection {
1159
+ constructor(guild) {
1160
+ super();
1161
+ this.guild = guild;
1162
+ }
1163
+ /**
1164
+ * The current bot user as a GuildMember in this guild.
1165
+ * Returns null if the bot's member is not cached or client.user is null.
1166
+ * Use fetchMe() to load the bot's member when not cached.
1167
+ *
1168
+ * @example
1169
+ * const perms = guild.members.me?.permissions;
1170
+ * if (perms?.has(PermissionFlags.BanMembers)) { ... }
1171
+ */
1172
+ get me() {
1173
+ const userId = this.guild.client.user?.id;
1174
+ return userId ? this.get(userId) ?? null : null;
1175
+ }
1176
+ /**
1177
+ * Fetch the current bot user as a GuildMember in this guild.
1178
+ * Caches the result in guild.members.
1179
+ *
1180
+ * @throws Error if client.user is null (client not ready)
1181
+ * @example
1182
+ * const me = await guild.members.fetchMe();
1183
+ * console.log(me.displayName);
1184
+ */
1185
+ async fetchMe() {
1186
+ const userId = this.guild.client.user?.id;
1187
+ if (!userId) {
1188
+ throw new Error("Cannot fetch me: client.user is null (client not ready)");
1189
+ }
1190
+ return this.guild.fetchMember(userId);
1191
+ }
1192
+ };
1193
+ }
1194
+ });
1195
+
1151
1196
  // src/util/permissions.ts
1152
1197
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
1153
1198
  if (isOwner) return import_util3.ALL_PERMISSIONS_BIGINT;
@@ -1332,11 +1377,12 @@ var Role_exports = {};
1332
1377
  __export(Role_exports, {
1333
1378
  Role: () => Role
1334
1379
  });
1335
- var import_util5, Role;
1380
+ var import_types9, import_util5, Role;
1336
1381
  var init_Role = __esm({
1337
1382
  "src/structures/Role.ts"() {
1338
1383
  "use strict";
1339
1384
  init_Base();
1385
+ import_types9 = require("@fluxerjs/types");
1340
1386
  import_util5 = require("@fluxerjs/util");
1341
1387
  Role = class extends Base {
1342
1388
  client;
@@ -1368,6 +1414,17 @@ var init_Role = __esm({
1368
1414
  this.unicodeEmoji = data.unicode_emoji ?? null;
1369
1415
  this.hoistPosition = data.hoist_position ?? null;
1370
1416
  }
1417
+ /** Update mutable fields from fresh API data. Used by edit and gateway events. */
1418
+ _patch(data) {
1419
+ if (data.name !== void 0) this.name = data.name;
1420
+ if (data.color !== void 0) this.color = data.color;
1421
+ if (data.position !== void 0) this.position = data.position;
1422
+ if (data.permissions !== void 0) this.permissions = data.permissions;
1423
+ if (data.hoist !== void 0) this.hoist = !!data.hoist;
1424
+ if (data.mentionable !== void 0) this.mentionable = !!data.mentionable;
1425
+ if (data.unicode_emoji !== void 0) this.unicodeEmoji = data.unicode_emoji ?? null;
1426
+ if (data.hoist_position !== void 0) this.hoistPosition = data.hoist_position ?? null;
1427
+ }
1371
1428
  /** Returns a mention string (e.g. `<@&123456>`). */
1372
1429
  toString() {
1373
1430
  return `<@&${this.id}>`;
@@ -1390,6 +1447,42 @@ var init_Role = __esm({
1390
1447
  if ((rolePerms & BigInt(import_util5.PermissionFlags.Administrator)) !== 0n) return true;
1391
1448
  return (rolePerms & permBig) === permBig;
1392
1449
  }
1450
+ /**
1451
+ * Edit this role.
1452
+ * Requires Manage Roles permission.
1453
+ * @param options - Role updates (permissions accepts PermissionResolvable for convenience)
1454
+ * @returns This role (updated in place)
1455
+ * @example
1456
+ * await role.edit({ name: 'Moderator', permissions: ['BanMembers', 'KickMembers'] });
1457
+ */
1458
+ async edit(options) {
1459
+ const body = {};
1460
+ if (options.name !== void 0) body.name = options.name;
1461
+ if (options.permissions !== void 0) {
1462
+ body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util5.resolvePermissionsToBitfield)(options.permissions);
1463
+ }
1464
+ if (options.color !== void 0) body.color = options.color;
1465
+ if (options.hoist !== void 0) body.hoist = options.hoist;
1466
+ if (options.mentionable !== void 0) body.mentionable = options.mentionable;
1467
+ if (options.unicode_emoji !== void 0) body.unicode_emoji = options.unicode_emoji;
1468
+ if (options.position !== void 0) body.position = options.position;
1469
+ if (options.hoist_position !== void 0) body.hoist_position = options.hoist_position;
1470
+ const data = await this.client.rest.patch(import_types9.Routes.guildRole(this.guildId, this.id), {
1471
+ body: Object.keys(body).length ? body : void 0,
1472
+ auth: true
1473
+ });
1474
+ this._patch(data);
1475
+ return this;
1476
+ }
1477
+ /**
1478
+ * Delete this role.
1479
+ * Requires Manage Roles permission.
1480
+ */
1481
+ async delete() {
1482
+ await this.client.rest.delete(import_types9.Routes.guildRole(this.guildId, this.id), { auth: true });
1483
+ const guild = this.client.guilds.get(this.guildId);
1484
+ if (guild) guild.roles.delete(this.id);
1485
+ }
1393
1486
  };
1394
1487
  }
1395
1488
  });
@@ -1399,12 +1492,12 @@ var GuildBan_exports = {};
1399
1492
  __export(GuildBan_exports, {
1400
1493
  GuildBan: () => GuildBan
1401
1494
  });
1402
- var import_types9, GuildBan;
1495
+ var import_types10, GuildBan;
1403
1496
  var init_GuildBan = __esm({
1404
1497
  "src/structures/GuildBan.ts"() {
1405
1498
  "use strict";
1406
1499
  init_Base();
1407
- import_types9 = require("@fluxerjs/types");
1500
+ import_types10 = require("@fluxerjs/types");
1408
1501
  GuildBan = class extends Base {
1409
1502
  client;
1410
1503
  guildId;
@@ -1426,7 +1519,7 @@ var init_GuildBan = __esm({
1426
1519
  * Requires Ban Members permission.
1427
1520
  */
1428
1521
  async unban() {
1429
- await this.client.rest.delete(import_types9.Routes.guildBan(this.guildId, this.user.id), {
1522
+ await this.client.rest.delete(import_types10.Routes.guildBan(this.guildId, this.user.id), {
1430
1523
  auth: true
1431
1524
  });
1432
1525
  }
@@ -1439,20 +1532,21 @@ var Guild_exports = {};
1439
1532
  __export(Guild_exports, {
1440
1533
  Guild: () => Guild
1441
1534
  });
1442
- var import_util6, import_rest3, import_collection5, import_types10, Guild;
1535
+ var import_util6, import_rest3, import_collection6, import_types11, Guild;
1443
1536
  var init_Guild = __esm({
1444
1537
  "src/structures/Guild.ts"() {
1445
1538
  "use strict";
1446
1539
  import_util6 = require("@fluxerjs/util");
1447
1540
  import_rest3 = require("@fluxerjs/rest");
1541
+ import_collection6 = require("@fluxerjs/collection");
1448
1542
  init_Base();
1449
1543
  init_FluxerError();
1450
1544
  init_ErrorCodes();
1451
- import_collection5 = require("@fluxerjs/collection");
1545
+ init_GuildMemberManager();
1452
1546
  init_GuildMember();
1453
1547
  init_Role();
1454
1548
  init_Constants();
1455
- import_types10 = require("@fluxerjs/types");
1549
+ import_types11 = require("@fluxerjs/types");
1456
1550
  Guild = class extends Base {
1457
1551
  client;
1458
1552
  id;
@@ -1487,14 +1581,15 @@ var init_Guild = __esm({
1487
1581
  splashWidth;
1488
1582
  /** Splash image height. Optional. */
1489
1583
  splashHeight;
1490
- members = new import_collection5.Collection();
1491
- channels = new import_collection5.Collection();
1492
- roles = new import_collection5.Collection();
1584
+ members;
1585
+ channels = new import_collection6.Collection();
1586
+ roles = new import_collection6.Collection();
1493
1587
  /** @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE */
1494
1588
  constructor(client, data) {
1495
1589
  super();
1496
1590
  this.client = client;
1497
1591
  this.id = data.id;
1592
+ this.members = new GuildMemberManager(this);
1498
1593
  this.name = data.name;
1499
1594
  this.icon = data.icon ?? null;
1500
1595
  this.banner = data.banner ?? null;
@@ -1544,7 +1639,7 @@ var init_Guild = __esm({
1544
1639
  * Requires Manage Roles permission.
1545
1640
  */
1546
1641
  async addRoleToMember(userId, roleId) {
1547
- await this.client.rest.put(import_types10.Routes.guildMemberRole(this.id, userId, roleId));
1642
+ await this.client.rest.put(import_types11.Routes.guildMemberRole(this.id, userId, roleId));
1548
1643
  }
1549
1644
  /**
1550
1645
  * Remove a role from a member by user ID. Does not require fetching the member first.
@@ -1553,7 +1648,75 @@ var init_Guild = __esm({
1553
1648
  * Requires Manage Roles permission.
1554
1649
  */
1555
1650
  async removeRoleFromMember(userId, roleId) {
1556
- await this.client.rest.delete(import_types10.Routes.guildMemberRole(this.id, userId, roleId));
1651
+ await this.client.rest.delete(import_types11.Routes.guildMemberRole(this.id, userId, roleId));
1652
+ }
1653
+ /**
1654
+ * Create a role in this guild.
1655
+ * Requires Manage Roles permission.
1656
+ * @param options - Role data (permissions accepts PermissionResolvable for convenience)
1657
+ * @returns The created role
1658
+ * @example
1659
+ * const role = await guild.createRole({ name: 'Mod', permissions: ['KickMembers', 'BanMembers'] });
1660
+ */
1661
+ async createRole(options) {
1662
+ const body = {};
1663
+ if (options.name !== void 0) body.name = options.name;
1664
+ if (options.permissions !== void 0) {
1665
+ body.permissions = typeof options.permissions === "string" ? options.permissions : (0, import_util6.resolvePermissionsToBitfield)(options.permissions);
1666
+ }
1667
+ if (options.color !== void 0) body.color = options.color;
1668
+ if (options.hoist !== void 0) body.hoist = options.hoist;
1669
+ if (options.mentionable !== void 0) body.mentionable = options.mentionable;
1670
+ if (options.unicode_emoji !== void 0) body.unicode_emoji = options.unicode_emoji;
1671
+ if (options.position !== void 0) body.position = options.position;
1672
+ if (options.hoist_position !== void 0) body.hoist_position = options.hoist_position;
1673
+ const data = await this.client.rest.post(import_types11.Routes.guildRoles(this.id), {
1674
+ body: Object.keys(body).length ? body : void 0,
1675
+ auth: true
1676
+ });
1677
+ const role = new Role(this.client, data, this.id);
1678
+ this.roles.set(role.id, role);
1679
+ return role;
1680
+ }
1681
+ /**
1682
+ * Fetch all roles in this guild.
1683
+ * @returns Array of Role objects (cached in guild.roles)
1684
+ */
1685
+ async fetchRoles() {
1686
+ const data = await this.client.rest.get(
1687
+ import_types11.Routes.guildRoles(this.id)
1688
+ );
1689
+ const list = Array.isArray(data) ? data : Object.values(data ?? {});
1690
+ const roles = [];
1691
+ for (const r of list) {
1692
+ const role = new Role(this.client, r, this.id);
1693
+ this.roles.set(role.id, role);
1694
+ roles.push(role);
1695
+ }
1696
+ return roles;
1697
+ }
1698
+ /**
1699
+ * Fetch a role by ID.
1700
+ * @param roleId - The role ID to fetch
1701
+ * @returns The role
1702
+ * @throws FluxerError with ROLE_NOT_FOUND if role does not exist (404)
1703
+ */
1704
+ async fetchRole(roleId) {
1705
+ try {
1706
+ const data = await this.client.rest.get(import_types11.Routes.guildRole(this.id, roleId));
1707
+ const role = new Role(this.client, data, this.id);
1708
+ this.roles.set(role.id, role);
1709
+ return role;
1710
+ } catch (err) {
1711
+ const statusCode = err instanceof import_rest3.FluxerAPIError ? err.statusCode : err?.statusCode;
1712
+ if (statusCode === 404) {
1713
+ throw new FluxerError(`Role ${roleId} not found in guild`, {
1714
+ code: ErrorCodes.RoleNotFound,
1715
+ cause: err
1716
+ });
1717
+ }
1718
+ throw err instanceof FluxerError ? err : new FluxerError("Failed to fetch guild role", { cause: err });
1719
+ }
1557
1720
  }
1558
1721
  /**
1559
1722
  * Resolve a role ID from an argument (role mention, raw ID, or name).
@@ -1569,7 +1732,7 @@ var init_Guild = __esm({
1569
1732
  (r) => !!(r.name && r.name.toLowerCase() === arg.trim().toLowerCase())
1570
1733
  );
1571
1734
  if (cached) return cached.id;
1572
- const roles = await this.client.rest.get(import_types10.Routes.guildRoles(this.id));
1735
+ const roles = await this.client.rest.get(import_types11.Routes.guildRoles(this.id));
1573
1736
  const list = Array.isArray(roles) ? roles : Object.values(roles ?? {});
1574
1737
  const role = list.find((r) => !!(r.name && r.name.toLowerCase() === arg.trim().toLowerCase()));
1575
1738
  if (role) {
@@ -1592,7 +1755,7 @@ var init_Guild = __esm({
1592
1755
  body.delete_message_days = options.delete_message_days;
1593
1756
  if (options?.ban_duration_seconds != null)
1594
1757
  body.ban_duration_seconds = options.ban_duration_seconds;
1595
- await this.client.rest.put(import_types10.Routes.guildBan(this.id, userId), {
1758
+ await this.client.rest.put(import_types11.Routes.guildBan(this.id, userId), {
1596
1759
  body: Object.keys(body).length ? body : void 0,
1597
1760
  auth: true
1598
1761
  });
@@ -1603,7 +1766,7 @@ var init_Guild = __esm({
1603
1766
  */
1604
1767
  async fetchBans() {
1605
1768
  const { GuildBan: GuildBan2 } = await Promise.resolve().then(() => (init_GuildBan(), GuildBan_exports));
1606
- const data = await this.client.rest.get(import_types10.Routes.guildBans(this.id));
1769
+ const data = await this.client.rest.get(import_types11.Routes.guildBans(this.id));
1607
1770
  const list = Array.isArray(data) ? data : data?.bans ?? [];
1608
1771
  return list.map((b) => new GuildBan2(this.client, { ...b, guild_id: this.id }, this.id));
1609
1772
  }
@@ -1613,7 +1776,7 @@ var init_Guild = __esm({
1613
1776
  * Requires Ban Members permission.
1614
1777
  */
1615
1778
  async unban(userId) {
1616
- await this.client.rest.delete(import_types10.Routes.guildBan(this.id, userId), { auth: true });
1779
+ await this.client.rest.delete(import_types11.Routes.guildBan(this.id, userId), { auth: true });
1617
1780
  }
1618
1781
  /**
1619
1782
  * Kick a member from this guild.
@@ -1621,7 +1784,7 @@ var init_Guild = __esm({
1621
1784
  * Requires Kick Members permission.
1622
1785
  */
1623
1786
  async kick(userId) {
1624
- await this.client.rest.delete(import_types10.Routes.guildMember(this.id, userId), { auth: true });
1787
+ await this.client.rest.delete(import_types11.Routes.guildMember(this.id, userId), { auth: true });
1625
1788
  }
1626
1789
  /**
1627
1790
  * Fetch a guild member by user ID.
@@ -1633,7 +1796,7 @@ var init_Guild = __esm({
1633
1796
  async fetchMember(userId) {
1634
1797
  try {
1635
1798
  const data = await this.client.rest.get(
1636
- import_types10.Routes.guildMember(this.id, userId)
1799
+ import_types11.Routes.guildMember(this.id, userId)
1637
1800
  );
1638
1801
  const member = new GuildMember(this.client, { ...data, guild_id: this.id }, this);
1639
1802
  this.members.set(member.id, member);
@@ -1661,13 +1824,13 @@ var init_Guild = __esm({
1661
1824
  if (options?.userId) params.set("user_id", options.userId);
1662
1825
  if (options?.actionType != null) params.set("action_type", String(options.actionType));
1663
1826
  const qs = params.toString();
1664
- const url = import_types10.Routes.guildAuditLogs(this.id) + (qs ? `?${qs}` : "");
1827
+ const url = import_types11.Routes.guildAuditLogs(this.id) + (qs ? `?${qs}` : "");
1665
1828
  return this.client.rest.get(url);
1666
1829
  }
1667
1830
  /** Fetch all webhooks in this guild. Returned webhooks do not include the token (cannot send). */
1668
1831
  async fetchWebhooks() {
1669
1832
  const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
1670
- const data = await this.client.rest.get(import_types10.Routes.guildWebhooks(this.id));
1833
+ const data = await this.client.rest.get(import_types11.Routes.guildWebhooks(this.id));
1671
1834
  const list = Array.isArray(data) ? data : Object.values(data ?? {});
1672
1835
  return list.map((w) => new Webhook2(this.client, w));
1673
1836
  }
@@ -1678,7 +1841,7 @@ var init_Guild = __esm({
1678
1841
  */
1679
1842
  async createChannel(data) {
1680
1843
  const { Channel: Channel2 } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
1681
- const created = await this.client.rest.post(import_types10.Routes.guildChannels(this.id), {
1844
+ const created = await this.client.rest.post(import_types11.Routes.guildChannels(this.id), {
1682
1845
  body: data,
1683
1846
  auth: true
1684
1847
  });
@@ -1695,7 +1858,7 @@ var init_Guild = __esm({
1695
1858
  */
1696
1859
  async fetchChannels() {
1697
1860
  const { Channel: Channel2 } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
1698
- const data = await this.client.rest.get(import_types10.Routes.guildChannels(this.id));
1861
+ const data = await this.client.rest.get(import_types11.Routes.guildChannels(this.id));
1699
1862
  const list = Array.isArray(data) ? data : Object.values(data ?? {});
1700
1863
  const channels = [];
1701
1864
  for (const ch of list) {
@@ -1714,7 +1877,7 @@ var init_Guild = __esm({
1714
1877
  * Requires Manage Channels permission.
1715
1878
  */
1716
1879
  async setChannelPositions(updates) {
1717
- await this.client.rest.patch(import_types10.Routes.guildChannels(this.id), {
1880
+ await this.client.rest.patch(import_types11.Routes.guildChannels(this.id), {
1718
1881
  body: updates,
1719
1882
  auth: true
1720
1883
  });
@@ -1724,12 +1887,12 @@ var init_Guild = __esm({
1724
1887
  });
1725
1888
 
1726
1889
  // src/structures/User.ts
1727
- var import_types12, User;
1890
+ var import_types13, User;
1728
1891
  var init_User = __esm({
1729
1892
  "src/structures/User.ts"() {
1730
1893
  "use strict";
1731
1894
  init_Base();
1732
- import_types12 = require("@fluxerjs/types");
1895
+ import_types13 = require("@fluxerjs/types");
1733
1896
  init_Constants();
1734
1897
  User = class extends Base {
1735
1898
  client;
@@ -1807,7 +1970,7 @@ var init_User = __esm({
1807
1970
  */
1808
1971
  async createDM() {
1809
1972
  const { DMChannel: DMChannelClass } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
1810
- const data = await this.client.rest.post(import_types12.Routes.userMeChannels(), {
1973
+ const data = await this.client.rest.post(import_types13.Routes.userMeChannels(), {
1811
1974
  body: { recipient_id: this.id },
1812
1975
  auth: true
1813
1976
  });
@@ -1830,11 +1993,11 @@ var MessageReaction_exports = {};
1830
1993
  __export(MessageReaction_exports, {
1831
1994
  MessageReaction: () => MessageReaction
1832
1995
  });
1833
- var import_types13, import_rest4, MessageReaction;
1996
+ var import_types15, import_rest4, MessageReaction;
1834
1997
  var init_MessageReaction = __esm({
1835
1998
  "src/structures/MessageReaction.ts"() {
1836
1999
  "use strict";
1837
- import_types13 = require("@fluxerjs/types");
2000
+ import_types15 = require("@fluxerjs/types");
1838
2001
  import_rest4 = require("@fluxerjs/rest");
1839
2002
  init_FluxerError();
1840
2003
  init_ErrorCodes();
@@ -1873,16 +2036,16 @@ var init_MessageReaction = __esm({
1873
2036
  try {
1874
2037
  const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
1875
2038
  const data = await this.client.rest.get(
1876
- import_types13.Routes.channelMessage(this.channelId, this.messageId)
2039
+ import_types15.Routes.channelMessage(this.channelId, this.messageId)
1877
2040
  );
1878
2041
  return new Message2(this.client, data);
1879
2042
  } catch (err) {
1880
2043
  if (err instanceof import_rest4.RateLimitError) throw err;
1881
2044
  if (err instanceof import_rest4.FluxerAPIError && err.statusCode === 404) {
1882
- throw new FluxerError(
1883
- `Message ${this.messageId} not found in channel ${this.channelId}`,
1884
- { code: ErrorCodes.MessageNotFound, cause: err }
1885
- );
2045
+ throw new FluxerError(`Message ${this.messageId} not found in channel ${this.channelId}`, {
2046
+ code: ErrorCodes.MessageNotFound,
2047
+ cause: err
2048
+ });
1886
2049
  }
1887
2050
  throw err instanceof FluxerError ? err : new FluxerError(String(err), { cause: err });
1888
2051
  }
@@ -1896,12 +2059,12 @@ var ClientUser_exports = {};
1896
2059
  __export(ClientUser_exports, {
1897
2060
  ClientUser: () => ClientUser
1898
2061
  });
1899
- var import_types14, ClientUser;
2062
+ var import_types16, ClientUser;
1900
2063
  var init_ClientUser = __esm({
1901
2064
  "src/client/ClientUser.ts"() {
1902
2065
  "use strict";
1903
2066
  init_User();
1904
- import_types14 = require("@fluxerjs/types");
2067
+ import_types16 = require("@fluxerjs/types");
1905
2068
  ClientUser = class extends User {
1906
2069
  constructor(client, data) {
1907
2070
  super(client, { ...data });
@@ -1912,7 +2075,7 @@ var init_ClientUser = __esm({
1912
2075
  */
1913
2076
  async fetchGuilds() {
1914
2077
  const { Guild: Guild2 } = await Promise.resolve().then(() => (init_Guild(), Guild_exports));
1915
- const data = await this.client.rest.get(import_types14.Routes.currentUserGuilds());
2078
+ const data = await this.client.rest.get(import_types16.Routes.currentUserGuilds());
1916
2079
  const list = Array.isArray(data) ? data : data?.guilds ?? [];
1917
2080
  const guilds = [];
1918
2081
  for (const g of list) {
@@ -1927,7 +2090,7 @@ var init_ClientUser = __esm({
1927
2090
  * @param guildId - The guild ID to leave
1928
2091
  */
1929
2092
  async leaveGuild(guildId) {
1930
- await this.client.rest.delete(import_types14.Routes.leaveGuild(guildId), { auth: true });
2093
+ await this.client.rest.delete(import_types16.Routes.leaveGuild(guildId), { auth: true });
1931
2094
  this.client.guilds.delete(guildId);
1932
2095
  }
1933
2096
  };
@@ -1949,17 +2112,18 @@ __export(index_exports, {
1949
2112
  ErrorCodes: () => ErrorCodes,
1950
2113
  Events: () => Events,
1951
2114
  FluxerError: () => FluxerError,
1952
- GatewayOpcodes: () => import_types18.GatewayOpcodes,
2115
+ GatewayOpcodes: () => import_types20.GatewayOpcodes,
1953
2116
  Guild: () => Guild,
1954
2117
  GuildBan: () => GuildBan,
1955
2118
  GuildChannel: () => GuildChannel,
1956
2119
  GuildEmoji: () => GuildEmoji,
1957
2120
  GuildMember: () => GuildMember,
2121
+ GuildMemberManager: () => GuildMemberManager,
1958
2122
  GuildSticker: () => GuildSticker,
1959
2123
  Invite: () => Invite,
1960
2124
  LinkChannel: () => LinkChannel,
1961
2125
  Message: () => Message,
1962
- MessageAttachmentFlags: () => import_types18.MessageAttachmentFlags,
2126
+ MessageAttachmentFlags: () => import_types20.MessageAttachmentFlags,
1963
2127
  MessageCollector: () => MessageCollector,
1964
2128
  MessageManager: () => MessageManager,
1965
2129
  MessagePayload: () => import_builders3.MessagePayload,
@@ -1968,9 +2132,12 @@ __export(index_exports, {
1968
2132
  PermissionsBitField: () => import_util9.PermissionsBitField,
1969
2133
  ReactionCollector: () => ReactionCollector,
1970
2134
  Role: () => Role,
1971
- Routes: () => import_types18.Routes,
2135
+ Routes: () => import_types20.Routes,
1972
2136
  TextChannel: () => TextChannel,
1973
2137
  User: () => User,
2138
+ UserFlagsBitField: () => import_util9.UserFlagsBitField,
2139
+ UserFlagsBits: () => import_util9.UserFlagsBits,
2140
+ UsersManager: () => UsersManager,
1974
2141
  VoiceChannel: () => VoiceChannel,
1975
2142
  Webhook: () => Webhook,
1976
2143
  cdnAvatarURL: () => cdnAvatarURL,
@@ -1979,6 +2146,7 @@ __export(index_exports, {
1979
2146
  cdnDisplayAvatarURL: () => cdnDisplayAvatarURL,
1980
2147
  cdnMemberAvatarURL: () => cdnMemberAvatarURL,
1981
2148
  cdnMemberBannerURL: () => cdnMemberBannerURL,
2149
+ resolvePermissionsToBitfield: () => import_util9.resolvePermissionsToBitfield,
1982
2150
  resolveTenorToImageUrl: () => import_util8.resolveTenorToImageUrl
1983
2151
  });
1984
2152
  module.exports = __toCommonJS(index_exports);
@@ -1987,8 +2155,7 @@ module.exports = __toCommonJS(index_exports);
1987
2155
  var import_events3 = require("events");
1988
2156
  var import_rest5 = require("@fluxerjs/rest");
1989
2157
  var import_ws = require("@fluxerjs/ws");
1990
- var import_types15 = require("@fluxerjs/types");
1991
- var import_collection7 = require("@fluxerjs/collection");
2158
+ var import_types17 = require("@fluxerjs/types");
1992
2159
 
1993
2160
  // src/client/ChannelManager.ts
1994
2161
  var import_collection4 = require("@fluxerjs/collection");
@@ -2094,9 +2261,9 @@ var ChannelManager = class extends import_collection4.Collection {
2094
2261
  };
2095
2262
 
2096
2263
  // src/client/GuildManager.ts
2097
- var import_collection6 = require("@fluxerjs/collection");
2098
- var import_types11 = require("@fluxerjs/types");
2099
- var GuildManager = class extends import_collection6.Collection {
2264
+ var import_collection7 = require("@fluxerjs/collection");
2265
+ var import_types12 = require("@fluxerjs/types");
2266
+ var GuildManager = class extends import_collection7.Collection {
2100
2267
  constructor(client) {
2101
2268
  super();
2102
2269
  this.client = client;
@@ -2115,7 +2282,7 @@ var GuildManager = class extends import_collection6.Collection {
2115
2282
  try {
2116
2283
  const { Guild: Guild2 } = await Promise.resolve().then(() => (init_Guild(), Guild_exports));
2117
2284
  const data = await this.client.rest.get(
2118
- import_types11.Routes.guild(guildId)
2285
+ import_types12.Routes.guild(guildId)
2119
2286
  );
2120
2287
  const guild = new Guild2(this.client, data);
2121
2288
  this.set(guild.id, guild);
@@ -2133,6 +2300,73 @@ init_Events();
2133
2300
  var import_util7 = require("@fluxerjs/util");
2134
2301
  init_User();
2135
2302
 
2303
+ // src/client/UsersManager.ts
2304
+ var import_collection8 = require("@fluxerjs/collection");
2305
+ var import_types14 = require("@fluxerjs/types");
2306
+ init_GuildMember();
2307
+ var UsersManager = class extends import_collection8.Collection {
2308
+ constructor(client) {
2309
+ super();
2310
+ this.client = client;
2311
+ }
2312
+ /**
2313
+ * Fetch a user by ID from the API.
2314
+ * Updates cache if user already exists.
2315
+ * @param userId - Snowflake of the user
2316
+ * @returns The user
2317
+ * @throws FluxerError (or REST error) if user not found
2318
+ * @example
2319
+ * const user = await client.users.fetch(userId);
2320
+ * console.log(user.username);
2321
+ */
2322
+ async fetch(userId) {
2323
+ const data = await this.client.rest.get(import_types14.Routes.user(userId));
2324
+ return this.client.getOrCreateUser(data);
2325
+ }
2326
+ /**
2327
+ * Fetch a user with full profile and optional guild context.
2328
+ * Returns user, global profile, server profile (when guildId), and member (when guildId).
2329
+ * Ideal for userinfo commands.
2330
+ * @param userId - Snowflake of the user
2331
+ * @param options - Optional guildId for server profile and member data
2332
+ * @returns User, raw data, profiles, and member (when in guild)
2333
+ * @throws FluxerError (or REST error) if user not found
2334
+ * @example
2335
+ * const { user, globalProfile, serverProfile, member } = await client.users.fetchWithProfile(
2336
+ * userId,
2337
+ * { guildId: message.guildId ?? undefined },
2338
+ * );
2339
+ */
2340
+ async fetchWithProfile(userId, options) {
2341
+ const guildId = options?.guildId ?? void 0;
2342
+ const [userData, globalProfileData, serverProfileData, memberData] = await Promise.all([
2343
+ this.client.rest.get(import_types14.Routes.user(userId)),
2344
+ this.client.rest.get(import_types14.Routes.userProfile(userId)).catch(() => null),
2345
+ guildId ? this.client.rest.get(import_types14.Routes.userProfile(userId, guildId)).catch(() => null) : Promise.resolve(null),
2346
+ guildId ? this.client.rest.get(import_types14.Routes.guildMember(guildId, userId)).catch(() => null) : Promise.resolve(null)
2347
+ ]);
2348
+ const user = this.client.getOrCreateUser(userData);
2349
+ const globalProfile = globalProfileData && typeof globalProfileData === "object" ? globalProfileData : null;
2350
+ const serverProfile = serverProfileData && typeof serverProfileData === "object" ? serverProfileData : null;
2351
+ let member = null;
2352
+ if (memberData && guildId) {
2353
+ const guild = this.client.guilds.get(guildId) ?? await this.client.guilds.fetch(guildId);
2354
+ if (guild) {
2355
+ member = new GuildMember(this.client, { ...memberData, guild_id: guildId }, guild);
2356
+ guild.members.set(member.id, member);
2357
+ }
2358
+ }
2359
+ return {
2360
+ user,
2361
+ userData,
2362
+ globalProfile,
2363
+ serverProfile,
2364
+ member,
2365
+ memberData
2366
+ };
2367
+ }
2368
+ };
2369
+
2136
2370
  // src/client/EventHandlerRegistry.ts
2137
2371
  init_Events();
2138
2372
  var handlers = /* @__PURE__ */ new Map();
@@ -2213,6 +2447,7 @@ handlers.set("MESSAGE_REACTION_REMOVE_EMOJI", async (client, d) => {
2213
2447
  handlers.set("GUILD_CREATE", async (client, d) => {
2214
2448
  const { Guild: Guild2 } = await Promise.resolve().then(() => (init_Guild(), Guild_exports));
2215
2449
  const { Channel: Channel2 } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
2450
+ const { GuildMember: GuildMember2 } = await Promise.resolve().then(() => (init_GuildMember(), GuildMember_exports));
2216
2451
  const raw = d;
2217
2452
  const guildData = raw?.properties != null ? { ...raw.properties, roles: raw.roles } : raw;
2218
2453
  const guild = new Guild2(client, guildData);
@@ -2222,6 +2457,13 @@ handlers.set("GUILD_CREATE", async (client, d) => {
2222
2457
  const channel = Channel2.from(client, ch);
2223
2458
  if (channel) client.channels.set(channel.id, channel);
2224
2459
  }
2460
+ for (const m of g.members ?? []) {
2461
+ if (m?.user?.id) {
2462
+ const memberData = { ...m, guild_id: guild.id };
2463
+ const member = new GuildMember2(client, memberData, guild);
2464
+ guild.members.set(member.id, member);
2465
+ }
2466
+ }
2225
2467
  client.emit(Events.GuildCreate, guild);
2226
2468
  if (g.voice_states?.length) {
2227
2469
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
@@ -2348,8 +2590,13 @@ handlers.set("GUILD_ROLE_UPDATE", async (client, d) => {
2348
2590
  const data = d;
2349
2591
  const guild = client.guilds.get(data.guild_id);
2350
2592
  if (guild) {
2351
- const { Role: Role2 } = await Promise.resolve().then(() => (init_Role(), Role_exports));
2352
- guild.roles.set(data.role.id, new Role2(client, data.role, guild.id));
2593
+ const existing = guild.roles.get(data.role.id);
2594
+ if (existing) {
2595
+ existing._patch(data.role);
2596
+ } else {
2597
+ const { Role: Role2 } = await Promise.resolve().then(() => (init_Role(), Role_exports));
2598
+ guild.roles.set(data.role.id, new Role2(client, data.role, guild.id));
2599
+ }
2353
2600
  }
2354
2601
  client.emit(Events.GuildRoleUpdate, data);
2355
2602
  });
@@ -2426,6 +2673,10 @@ var Client = class extends import_events3.EventEmitter {
2426
2673
  get: () => this.guilds,
2427
2674
  configurable: true
2428
2675
  });
2676
+ Object.defineProperty(this.users, "cache", {
2677
+ get: () => this.users,
2678
+ configurable: true
2679
+ });
2429
2680
  this.rest = new import_rest5.REST({
2430
2681
  api: options.rest?.api ?? "https://api.fluxer.app",
2431
2682
  version: options.rest?.version ?? "1",
@@ -2435,7 +2686,7 @@ var Client = class extends import_events3.EventEmitter {
2435
2686
  rest;
2436
2687
  guilds = new GuildManager(this);
2437
2688
  channels = new ChannelManager(this);
2438
- users = new import_collection7.Collection();
2689
+ users = new UsersManager(this);
2439
2690
  /** Typed event handlers. Use client.events.MessageReactionAdd((reaction, user, messageId, channelId, emoji, userId) => {...}) or client.on(Events.MessageReactionAdd, ...). */
2440
2691
  events;
2441
2692
  /** The authenticated bot user. Null until READY is received. */
@@ -2462,7 +2713,7 @@ var Client = class extends import_events3.EventEmitter {
2462
2713
  if (parsed.id) return (0, import_util7.formatEmoji)(parsed);
2463
2714
  if (!/^\w+$/.test(parsed.name)) return encodeURIComponent(parsed.name);
2464
2715
  if (guildId) {
2465
- const emojis = await this.rest.get(import_types15.Routes.guildEmojis(guildId));
2716
+ const emojis = await this.rest.get(import_types17.Routes.guildEmojis(guildId));
2466
2717
  const list = Array.isArray(emojis) ? emojis : Object.values(emojis ?? {});
2467
2718
  const found = list.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
2468
2719
  if (found) return (0, import_util7.formatEmoji)({ ...parsed, id: found.id, animated: found.animated });
@@ -2629,11 +2880,12 @@ var Client = class extends import_events3.EventEmitter {
2629
2880
  return this.readyAt !== null && this.user !== null;
2630
2881
  }
2631
2882
  static get Routes() {
2632
- return import_types15.Routes;
2883
+ return import_types17.Routes;
2633
2884
  }
2634
2885
  };
2635
2886
 
2636
2887
  // src/index.ts
2888
+ init_GuildMemberManager();
2637
2889
  init_MessageManager();
2638
2890
  init_ClientUser();
2639
2891
  init_Base();
@@ -2650,7 +2902,7 @@ init_GuildBan();
2650
2902
 
2651
2903
  // src/structures/GuildEmoji.ts
2652
2904
  init_Base();
2653
- var import_types16 = require("@fluxerjs/types");
2905
+ var import_types18 = require("@fluxerjs/types");
2654
2906
  init_Constants();
2655
2907
  var GuildEmoji = class extends Base {
2656
2908
  client;
@@ -2678,7 +2930,7 @@ var GuildEmoji = class extends Base {
2678
2930
  }
2679
2931
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
2680
2932
  async delete() {
2681
- await this.client.rest.delete(import_types16.Routes.guildEmoji(this.guildId, this.id), {
2933
+ await this.client.rest.delete(import_types18.Routes.guildEmoji(this.guildId, this.id), {
2682
2934
  auth: true
2683
2935
  });
2684
2936
  }
@@ -2687,7 +2939,7 @@ var GuildEmoji = class extends Base {
2687
2939
  * Requires Manage Emojis and Stickers permission.
2688
2940
  */
2689
2941
  async edit(options) {
2690
- const data = await this.client.rest.patch(import_types16.Routes.guildEmoji(this.guildId, this.id), {
2942
+ const data = await this.client.rest.patch(import_types18.Routes.guildEmoji(this.guildId, this.id), {
2691
2943
  body: options,
2692
2944
  auth: true
2693
2945
  });
@@ -2698,7 +2950,7 @@ var GuildEmoji = class extends Base {
2698
2950
 
2699
2951
  // src/structures/GuildSticker.ts
2700
2952
  init_Base();
2701
- var import_types17 = require("@fluxerjs/types");
2953
+ var import_types19 = require("@fluxerjs/types");
2702
2954
  init_Constants();
2703
2955
  var GuildSticker = class extends Base {
2704
2956
  client;
@@ -2726,7 +2978,7 @@ var GuildSticker = class extends Base {
2726
2978
  }
2727
2979
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
2728
2980
  async delete() {
2729
- await this.client.rest.delete(import_types17.Routes.guildSticker(this.guildId, this.id), {
2981
+ await this.client.rest.delete(import_types19.Routes.guildSticker(this.guildId, this.id), {
2730
2982
  auth: true
2731
2983
  });
2732
2984
  }
@@ -2735,7 +2987,7 @@ var GuildSticker = class extends Base {
2735
2987
  * Requires Manage Emojis and Stickers permission.
2736
2988
  */
2737
2989
  async edit(options) {
2738
- const data = await this.client.rest.patch(import_types17.Routes.guildSticker(this.guildId, this.id), {
2990
+ const data = await this.client.rest.patch(import_types19.Routes.guildSticker(this.guildId, this.id), {
2739
2991
  body: options,
2740
2992
  auth: true
2741
2993
  });
@@ -2753,7 +3005,7 @@ init_ReactionCollector();
2753
3005
  init_FluxerError();
2754
3006
  init_ErrorCodes();
2755
3007
  var import_builders3 = require("@fluxerjs/builders");
2756
- var import_types18 = require("@fluxerjs/types");
3008
+ var import_types20 = require("@fluxerjs/types");
2757
3009
  var import_util8 = require("@fluxerjs/util");
2758
3010
  var import_util9 = require("@fluxerjs/util");
2759
3011
  init_cdn();
@@ -2777,6 +3029,7 @@ init_cdn();
2777
3029
  GuildChannel,
2778
3030
  GuildEmoji,
2779
3031
  GuildMember,
3032
+ GuildMemberManager,
2780
3033
  GuildSticker,
2781
3034
  Invite,
2782
3035
  LinkChannel,
@@ -2793,6 +3046,9 @@ init_cdn();
2793
3046
  Routes,
2794
3047
  TextChannel,
2795
3048
  User,
3049
+ UserFlagsBitField,
3050
+ UserFlagsBits,
3051
+ UsersManager,
2796
3052
  VoiceChannel,
2797
3053
  Webhook,
2798
3054
  cdnAvatarURL,
@@ -2801,5 +3057,6 @@ init_cdn();
2801
3057
  cdnDisplayAvatarURL,
2802
3058
  cdnMemberAvatarURL,
2803
3059
  cdnMemberBannerURL,
3060
+ resolvePermissionsToBitfield,
2804
3061
  resolveTenorToImageUrl
2805
3062
  });