@stoatx/client 0.4.0 → 0.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
@@ -40,7 +40,7 @@ var Base = class _Base {
40
40
  };
41
41
 
42
42
  // src/structures/Message.ts
43
- import * as util2 from "util";
43
+ import * as util3 from "util";
44
44
 
45
45
  // src/structures/Attachment.ts
46
46
  var Attachment = class extends Base {
@@ -57,7 +57,7 @@ var Attachment = class extends Base {
57
57
  serverId;
58
58
  objectId;
59
59
  constructor(client, data) {
60
- super(client, { ...data, id: data._id });
60
+ super(client, { ...data, _id: data._id });
61
61
  this.id = data._id;
62
62
  this.tag = data.tag;
63
63
  this.filename = data.filename;
@@ -386,6 +386,82 @@ var ReactionCollector = class extends Collector {
386
386
  }
387
387
  };
388
388
 
389
+ // src/structures/MessageMentions.ts
390
+ import util2 from "util";
391
+ var MessageMentions = class _MessageMentions {
392
+ constructor(client, message, userIds, roleIds) {
393
+ this.client = client;
394
+ this.message = message;
395
+ this.userIds = userIds ?? [];
396
+ this.roleIds = roleIds ?? [];
397
+ this.channelIds = message.content ? _MessageMentions.parseChannelIds(message.content) : [];
398
+ }
399
+ /** Raw user IDs from the API */
400
+ userIds;
401
+ /** Raw role IDs from the API */
402
+ roleIds;
403
+ /** Raw channel IDs parsed from message content */
404
+ channelIds;
405
+ /** Mentioned users resolved from cache */
406
+ get users() {
407
+ const col = new Collection();
408
+ for (const id of this.userIds) {
409
+ const user = this.client.users.cache.get(id);
410
+ if (user) col.set(id, user);
411
+ }
412
+ return col;
413
+ }
414
+ /** Mentioned members resolved from cache (only in server channels) */
415
+ get members() {
416
+ const col = new Collection();
417
+ const server = this.message.server;
418
+ if (!server) return col;
419
+ for (const id of this.userIds) {
420
+ const member = server.members.cache.get(id);
421
+ if (member) col.set(id, member);
422
+ }
423
+ return col;
424
+ }
425
+ /** Mentioned roles resolved from cache */
426
+ get roles() {
427
+ const col = new Collection();
428
+ const server = this.message.server;
429
+ if (!server) return col;
430
+ for (const id of this.roleIds) {
431
+ const role = server.roles.cache.get(id);
432
+ if (role) col.set(id, role);
433
+ }
434
+ return col;
435
+ }
436
+ /** Mentioned channels resolved from cache */
437
+ get channels() {
438
+ const col = new Collection();
439
+ for (const id of this.channelIds) {
440
+ const channel = this.client.channels.cache.get(id);
441
+ if (channel) col.set(id, channel);
442
+ }
443
+ return col;
444
+ }
445
+ /** Whether the given user ID is mentioned */
446
+ has(userId) {
447
+ return this.userIds.includes(userId);
448
+ }
449
+ static parseChannelIds(content) {
450
+ return [...content.matchAll(/<#([A-Z0-9]+)>/g)].flatMap((m) => m[1] ? [m[1]] : []);
451
+ }
452
+ [util2.inspect.custom](depth, options, inspect12) {
453
+ const { client, message, ...props } = this;
454
+ const data = {
455
+ ...props,
456
+ members: this.members,
457
+ channels: this.channels,
458
+ users: this.users,
459
+ roles: this.roles
460
+ };
461
+ return `${this.constructor.name} ${inspect12(data, { ...options, depth: depth ?? options.depth })}`;
462
+ }
463
+ };
464
+
389
465
  // src/structures/Message.ts
390
466
  var Message = class extends Base {
391
467
  content = null;
@@ -398,11 +474,10 @@ var Message = class extends Base {
398
474
  flags = 0;
399
475
  interactions = null;
400
476
  masquerade = null;
401
- mentions = [];
477
+ mentions;
402
478
  pinned = false;
403
479
  reactions = {};
404
480
  replies = [];
405
- role_mentions = [];
406
481
  constructor(client, data) {
407
482
  super(client, data);
408
483
  this.authorId = data.author;
@@ -415,10 +490,9 @@ var Message = class extends Base {
415
490
  this.attachments = data.attachments.map((fileData) => new Attachment(this.client, fileData));
416
491
  }
417
492
  if (data.masquerade !== void 0) this.masquerade = data.masquerade;
418
- if (data.mentions !== void 0) this.mentions = data.mentions;
419
493
  if (data.replies !== void 0) this.replies = data.replies;
420
- if (data.role_mentions !== void 0) this.role_mentions = data.role_mentions;
421
494
  this._patch(data);
495
+ this.mentions = new MessageMentions(client, this, data.mentions ?? null, data.role_mentions ?? null);
422
496
  }
423
497
  async reply(contentOrOptions) {
424
498
  let channel = this.channel;
@@ -573,7 +647,7 @@ var Message = class extends Base {
573
647
  }
574
648
  _patch(data) {
575
649
  if (data.content !== void 0) this.content = data.content;
576
- if (data.edited !== void 0) this.editedAt = new Date(data.edited);
650
+ if (data.edited !== void 0) this.editedAt = new Date(data.edited ?? 0);
577
651
  if (data.pinned !== void 0) this.pinned = data.pinned;
578
652
  if (data.embeds !== void 0) this.embeds = data.embeds;
579
653
  if (data.flags !== void 0) this.flags = data.flags;
@@ -592,7 +666,7 @@ var Message = class extends Base {
592
666
  }
593
667
  }
594
668
  // This tells Node.js exactly how to print this object in console.log()
595
- [util2.inspect.custom](depth, options, inspect12) {
669
+ [util3.inspect.custom](depth, options, inspect12) {
596
670
  const { client, authorId, channelId, ...props } = this;
597
671
  const data = {
598
672
  ...props,
@@ -606,24 +680,6 @@ var Message = class extends Base {
606
680
  };
607
681
 
608
682
  // src/structures/User.ts
609
- var UserRelationship = /* @__PURE__ */ ((UserRelationship2) => {
610
- UserRelationship2["None"] = "None";
611
- UserRelationship2["User"] = "User";
612
- UserRelationship2["Friend"] = "Friend";
613
- UserRelationship2["Outgoing"] = "Outgoing";
614
- UserRelationship2["Incoming"] = "Incoming";
615
- UserRelationship2["Blocked"] = "Blocked";
616
- UserRelationship2["BlockedOther"] = "BlockedOther";
617
- return UserRelationship2;
618
- })(UserRelationship || {});
619
- var UserPresence = /* @__PURE__ */ ((UserPresence2) => {
620
- UserPresence2["Online"] = "Online";
621
- UserPresence2["Idle"] = "Idle";
622
- UserPresence2["Focus"] = "Focus";
623
- UserPresence2["Busy"] = "Busy";
624
- UserPresence2["Invisible"] = "Invisible";
625
- return UserPresence2;
626
- })(UserPresence || {});
627
683
  var User = class extends Base {
628
684
  discriminator;
629
685
  online;
@@ -657,7 +713,7 @@ var User = class extends Base {
657
713
  this.bot = data.bot ? { owner: data.bot.owner } : false;
658
714
  }
659
715
  if (data.avatar !== void 0) {
660
- this.avatar = new Attachment(this.client, data.avatar);
716
+ this.avatar = data.avatar ? new Attachment(this.client, data.avatar) : null;
661
717
  }
662
718
  if (clear && Array.isArray(clear)) {
663
719
  for (const field of clear) {
@@ -737,6 +793,7 @@ var GatewayManager = class {
737
793
  handleMessage(rawData) {
738
794
  const payload = JSON.parse(rawData.toString());
739
795
  const eventType = payload.type;
796
+ this.client.emit("raw", payload);
740
797
  switch (eventType) {
741
798
  case "Error":
742
799
  this.client.emit("error", new Error(`Gateway Error: ${payload.error || JSON.stringify(payload)}`));
@@ -763,6 +820,15 @@ var GatewayManager = class {
763
820
  }
764
821
  }
765
822
  }
823
+ if (payload.members) {
824
+ for (const rawMember of payload.members) {
825
+ const server = this.client.servers.cache.get(rawMember._id.server);
826
+ const user = this.client.users.cache.get(rawMember._id.user);
827
+ if (server && user) {
828
+ server.members._add({ ...rawMember, user });
829
+ }
830
+ }
831
+ }
766
832
  if (payload.emojis) {
767
833
  for (const rawEmoji of payload.emojis) {
768
834
  const emoji = this.client.emojis._add(rawEmoji);
@@ -814,7 +880,7 @@ var GatewayManager = class {
814
880
  const message = channel?.messages.cache.get(payload.id);
815
881
  if (message && payload.append.embeds) {
816
882
  const oldMessage = message._clone();
817
- message.embeds.push(...payload.append.embeds);
883
+ message.embeds = [...message.embeds || [], ...payload.append.embeds];
818
884
  this.client.emit("messageUpdate", oldMessage, message);
819
885
  }
820
886
  break;
@@ -954,13 +1020,28 @@ var GatewayManager = class {
954
1020
  }
955
1021
  case "ServerMemberLeave": {
956
1022
  const server = this.client.servers.cache.get(payload.id);
1023
+ let member = null;
957
1024
  if (server) {
958
- const member = server.members.cache.get(payload.user);
1025
+ member = server.members.cache.get(payload.user);
959
1026
  if (member) {
960
1027
  server.members.cache.delete(payload.user);
961
- this.client.emit("serverMemberLeave", member);
962
1028
  }
963
1029
  }
1030
+ const emitData = member || { serverId: payload.id, userId: payload.user };
1031
+ if (payload.reason === "Ban") {
1032
+ if (server) {
1033
+ const dummyBanPayload = {
1034
+ id: payload.user,
1035
+ reason: null
1036
+ };
1037
+ server.bans._add(dummyBanPayload);
1038
+ }
1039
+ this.client.emit("serverBanAdd", emitData);
1040
+ } else if (payload.reason === "Kick") {
1041
+ this.client.emit("serverMemberKick", emitData);
1042
+ } else {
1043
+ this.client.emit("serverMemberLeave", emitData);
1044
+ }
964
1045
  break;
965
1046
  }
966
1047
  case "EmojiCreate": {
@@ -994,7 +1075,8 @@ var GatewayManager = class {
994
1075
  break;
995
1076
  }
996
1077
  default:
997
- this.client.emit("raw", payload);
1078
+ this.client.emit("debug", `Unhandled Gateway Event Type: ${eventType}`);
1079
+ break;
998
1080
  }
999
1081
  }
1000
1082
  startPingLoop() {
@@ -1040,6 +1122,96 @@ var GatewayManager = class {
1040
1122
 
1041
1123
  // src/rest/RESTManager.ts
1042
1124
  import { request } from "undici";
1125
+
1126
+ // src/utils/schema.ts
1127
+ var queryParams = {
1128
+ "/": { get: [] },
1129
+ "/users/@me": { get: [] },
1130
+ "/users/{target}": { get: [], patch: [] },
1131
+ "/users/{target}/flags": { get: [] },
1132
+ "/users/@me/username": { patch: [] },
1133
+ "/users/{target}/default_avatar": { get: [] },
1134
+ "/users/{target}/profile": { get: [] },
1135
+ "/users/dms": { get: [] },
1136
+ "/users/{target}/dm": { get: [] },
1137
+ "/users/{target}/mutual": { get: [] },
1138
+ "/users/{target}/friend": { put: [], delete: [] },
1139
+ "/users/{target}/block": { put: [], delete: [] },
1140
+ "/users/friend": { post: [] },
1141
+ "/bots/create": { post: [] },
1142
+ "/bots/{target}/invite": { get: [], post: [] },
1143
+ "/bots/{bot_id}": { get: [], delete: [], patch: [] },
1144
+ "/bots/@me": { get: [] },
1145
+ "/channels/{target}/ack/{message}": { put: [] },
1146
+ "/channels/{target}": { get: [], delete: ["leave_silently"], patch: [] },
1147
+ "/channels/{target}/members": { get: [] },
1148
+ "/channels/{target}/invites": { post: [] },
1149
+ "/channels/{target}/messages": { get: ["limit", "before", "after", "sort", "nearby", "include_users"], post: [] },
1150
+ "/channels/{target}/search": { post: [] },
1151
+ "/channels/{target}/messages/{msg}/pin": { post: [], delete: [] },
1152
+ "/channels/{target}/messages/{msg}": { get: [], delete: [], patch: [] },
1153
+ "/channels/{target}/messages/bulk": { delete: [] },
1154
+ "/channels/create": { post: [] },
1155
+ "/channels/{group_id}/recipients/{member_id}": { put: [], delete: [] },
1156
+ "/channels/{target}/join_call": { post: [] },
1157
+ "/channels/{target}/end_ring/{target_user}": { put: [] },
1158
+ "/channels/{target}/permissions/{role_id}": { put: [] },
1159
+ "/channels/{target}/permissions/default": { put: [] },
1160
+ "/channels/{target}/messages/{msg}/reactions/{emoji}": { put: [], delete: ["user_id", "remove_all"] },
1161
+ "/channels/{target}/messages/{msg}/reactions": { delete: [] },
1162
+ "/channels/{channel_id}/webhooks": { get: [], post: [] },
1163
+ "/servers/create": { post: [] },
1164
+ "/servers/{target}": { get: ["include_channels"], delete: ["leave_silently"], patch: [] },
1165
+ "/servers/{target}/ack": { put: [] },
1166
+ "/servers/{server}/channels": { post: [] },
1167
+ "/servers/{target}/members": { get: ["exclude_offline"] },
1168
+ "/servers/{server_id}/members/{member_id}": { get: ["roles"], delete: [], patch: [] },
1169
+ "/servers/{target}/members_experimental_query": { get: ["query", "experimental_api"] },
1170
+ "/servers/{server}/bans/{target}": { put: [], delete: [] },
1171
+ "/servers/{target}/bans": { get: [] },
1172
+ "/servers/{target}/invites": { get: [] },
1173
+ "/servers/{target}/roles": { post: [] },
1174
+ "/servers/{target}/roles/{role_id}": { get: [], delete: [], patch: [] },
1175
+ "/servers/{target}/permissions/{role_id}": { put: [] },
1176
+ "/servers/{target}/permissions/default": { put: [] },
1177
+ "/servers/{target}/emojis": { get: [] },
1178
+ "/servers/{target}/roles/ranks": { patch: [] },
1179
+ "/invites/{target}": { get: [], post: [], delete: [] },
1180
+ "/custom/emoji/{emoji_id}": { get: [], put: [], delete: [], patch: [] },
1181
+ "/safety/report": { post: [] },
1182
+ "/auth/account/create": { post: [] },
1183
+ "/auth/account/reverify": { post: [] },
1184
+ "/auth/account/delete": { put: [], post: [] },
1185
+ "/auth/account/": { get: [] },
1186
+ "/auth/account/disable": { post: [] },
1187
+ "/auth/account/change/password": { patch: [] },
1188
+ "/auth/account/change/email": { patch: [] },
1189
+ "/auth/account/verify/{code}": { post: [] },
1190
+ "/auth/account/reset_password": { post: [], patch: [] },
1191
+ "/auth/session/login": { post: [] },
1192
+ "/auth/session/logout": { post: [] },
1193
+ "/auth/session/all": { get: [], delete: ["revoke_self"] },
1194
+ "/auth/session/{id}": { delete: [], patch: [] },
1195
+ "/auth/mfa/ticket": { put: [] },
1196
+ "/auth/mfa/": { get: [] },
1197
+ "/auth/mfa/recovery": { post: [], patch: [] },
1198
+ "/auth/mfa/methods": { get: [] },
1199
+ "/auth/mfa/totp": { put: [], post: [], delete: [] },
1200
+ "/onboard/hello": { get: [] },
1201
+ "/onboard/complete": { post: [] },
1202
+ "/policy/acknowledge": { post: [] },
1203
+ "/push/subscribe": { post: [] },
1204
+ "/push/unsubscribe": { post: [] },
1205
+ "/sync/settings/fetch": { post: [] },
1206
+ "/sync/settings/set": { post: ["timestamp"] },
1207
+ "/sync/unreads": { get: [] },
1208
+ "/webhooks/{webhook_id}/{token}/{message_id}": { delete: [], patch: [] },
1209
+ "/webhooks/{webhook_id}/{token}": { get: [], post: [], delete: [], patch: [] },
1210
+ "/webhooks/{webhook_id}": { get: [], delete: [], patch: [] },
1211
+ "/webhooks/{webhook_id}/{token}/github": { post: [] }
1212
+ };
1213
+
1214
+ // src/rest/RESTManager.ts
1043
1215
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1044
1216
  var AsyncBucket = class {
1045
1217
  remaining = 1;
@@ -1086,9 +1258,25 @@ var StoatAPIError = class _StoatAPIError extends Error {
1086
1258
  Object.setPrototypeOf(this, _StoatAPIError.prototype);
1087
1259
  }
1088
1260
  };
1261
+ var ALL_QUERY_KEYS = /* @__PURE__ */ new Set();
1262
+ for (const routes of Object.values(queryParams)) {
1263
+ for (const keys of Object.values(routes)) {
1264
+ for (const key of keys) {
1265
+ ALL_QUERY_KEYS.add(key);
1266
+ }
1267
+ }
1268
+ }
1089
1269
  var RESTManager = class {
1090
1270
  constructor(client) {
1091
1271
  this.client = client;
1272
+ setInterval(() => {
1273
+ const now = Date.now();
1274
+ for (const [key, bucket] of this.buckets.entries()) {
1275
+ if (now > bucket.resetAt && bucket.remaining > 0) {
1276
+ this.buckets.delete(key);
1277
+ }
1278
+ }
1279
+ }, 3e5).unref();
1092
1280
  }
1093
1281
  baseURL = "https://stoat.chat/api";
1094
1282
  token = null;
@@ -1102,17 +1290,35 @@ var RESTManager = class {
1102
1290
  getRouteKey(method, endpoint) {
1103
1291
  return `${method}:${endpoint}`;
1104
1292
  }
1105
- makeRequest(method, endpoint, body) {
1106
- const routeKey = this.getRouteKey(method, endpoint);
1107
- let bucket = this.buckets.get(routeKey);
1108
- if (!bucket) {
1109
- bucket = new AsyncBucket();
1110
- this.buckets.set(routeKey, bucket);
1293
+ makeRequest(method, endpoint, params) {
1294
+ let finalEndpoint = endpoint;
1295
+ let finalBody = void 0;
1296
+ if (params && typeof params === "object") {
1297
+ const query = new URLSearchParams();
1298
+ finalBody = {};
1299
+ for (const [key, value] of Object.entries(params)) {
1300
+ if (value !== void 0) {
1301
+ if (ALL_QUERY_KEYS.has(key)) {
1302
+ query.append(key, String(value));
1303
+ } else {
1304
+ finalBody[key] = value;
1305
+ }
1306
+ }
1307
+ }
1308
+ const qs = query.toString();
1309
+ if (qs) finalEndpoint += `?${qs}`;
1310
+ if (Object.keys(finalBody).length === 0) finalBody = void 0;
1111
1311
  }
1312
+ const routeKey = this.getRouteKey(method, finalEndpoint);
1112
1313
  return new Promise((resolve, reject) => {
1314
+ let bucket = this.buckets.get(routeKey);
1315
+ if (!bucket) {
1316
+ bucket = new AsyncBucket();
1317
+ this.buckets.set(routeKey, bucket);
1318
+ }
1113
1319
  bucket.queue = bucket.queue.then(async () => {
1114
1320
  try {
1115
- const result = await this.execute(method, endpoint, body, bucket);
1321
+ const result = await this.execute(method, finalEndpoint, finalBody, bucket);
1116
1322
  resolve(result);
1117
1323
  } catch (error) {
1118
1324
  reject(error);
@@ -1193,25 +1399,25 @@ var RESTManager = class {
1193
1399
  const data = await response.json();
1194
1400
  return data.id;
1195
1401
  }
1196
- get(endpoint) {
1197
- return this.makeRequest("GET", endpoint);
1402
+ get(endpoint, params) {
1403
+ return this.makeRequest("get", endpoint, params);
1198
1404
  }
1199
- post(endpoint, body) {
1200
- return this.makeRequest("POST", endpoint, body);
1405
+ post(endpoint, params) {
1406
+ return this.makeRequest("post", endpoint, params);
1201
1407
  }
1202
- patch(endpoint, body) {
1203
- return this.makeRequest("PATCH", endpoint, body);
1408
+ patch(endpoint, params) {
1409
+ return this.makeRequest("patch", endpoint, params);
1204
1410
  }
1205
- delete(endpoint, body) {
1206
- return this.makeRequest("DELETE", endpoint, body);
1411
+ delete(endpoint, params) {
1412
+ return this.makeRequest("delete", endpoint, params);
1207
1413
  }
1208
- async put(endpoint, body) {
1209
- return this.makeRequest("PUT", endpoint, body);
1414
+ put(endpoint, params) {
1415
+ return this.makeRequest("put", endpoint, params);
1210
1416
  }
1211
1417
  };
1212
1418
 
1213
1419
  // src/managers/MessageManager.ts
1214
- import * as util3 from "util";
1420
+ import * as util4 from "util";
1215
1421
 
1216
1422
  // src/managers/BaseManager.ts
1217
1423
  var BaseManager = class {
@@ -1284,7 +1490,7 @@ var MessageManager = class extends BaseManager {
1284
1490
  * Tell BaseManager how to find the ID for Messages
1285
1491
  */
1286
1492
  extractId(data) {
1287
- return data._id ?? data.id;
1493
+ return data._id;
1288
1494
  }
1289
1495
  /**
1290
1496
  * Tell BaseManager how to build a Message
@@ -1309,20 +1515,31 @@ var MessageManager = class extends BaseManager {
1309
1515
  * const history = await channel.messages.fetchMany({ limit: 20, before: "01H..." });
1310
1516
  */
1311
1517
  async fetchMany(options = {}) {
1312
- const params = new URLSearchParams();
1313
- if (options.limit !== void 0) params.append("limit", options.limit.toString());
1314
- if (options.before !== void 0) params.append("before", options.before);
1315
- if (options.after !== void 0) params.append("after", options.after);
1316
- if (options.sort !== void 0) params.append("sort", options.sort);
1317
- if (options.nearby !== void 0) params.append("nearby", options.nearby);
1318
- if (options.includeUsers !== void 0) params.append("include_users", options.includeUsers.toString());
1319
- const queryString = params.toString();
1320
- const endpoint = `/channels/${this.channel.id}/messages${queryString ? `?${queryString}` : ""}`;
1321
- const data = await this.client.rest.get(endpoint);
1322
- const rawMessages = Array.isArray(data) ? data : data.messages || [];
1323
- if (!Array.isArray(data) && data.users) {
1324
- for (const userData of data.users) {
1325
- this.client.users._add(userData);
1518
+ const endpoint = `/channels/${this.channel.id}/messages`;
1519
+ const query = {};
1520
+ if (options.limit !== void 0) query.limit = options.limit;
1521
+ if (options.before !== void 0) query.before = options.before;
1522
+ if (options.after !== void 0) query.after = options.after;
1523
+ if (options.sort !== void 0) query.sort = options.sort;
1524
+ if (options.nearby !== void 0) query.nearby = options.nearby;
1525
+ if (options.includeUsers !== void 0) query.include_users = options.includeUsers;
1526
+ const data = await this.client.rest.get(endpoint, query);
1527
+ let rawMessages;
1528
+ if (Array.isArray(data)) {
1529
+ rawMessages = data;
1530
+ } else {
1531
+ rawMessages = data.messages;
1532
+ if (data.users) {
1533
+ for (const userData of data.users) {
1534
+ this.client.users._add(userData);
1535
+ }
1536
+ }
1537
+ if (data.members && this.channel.isText()) {
1538
+ const serverId = this.channel.serverId;
1539
+ const server = await this.client.servers.fetch(serverId);
1540
+ for (const memberData of data.members) {
1541
+ server.members._add(memberData);
1542
+ }
1326
1543
  }
1327
1544
  }
1328
1545
  const fetched = new Collection();
@@ -1343,18 +1560,19 @@ var MessageManager = class extends BaseManager {
1343
1560
  * @returns A promise that resolves to the sent Message.
1344
1561
  */
1345
1562
  async send(contentOrOptions) {
1346
- const payload = typeof contentOrOptions === "string" ? { content: contentOrOptions } : { ...contentOrOptions };
1347
- if (payload.embeds) {
1348
- payload.embeds = payload.embeds.map(
1349
- (embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed
1350
- );
1563
+ const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
1564
+ const payload = {};
1565
+ if (opts.embeds && opts.embeds.length) {
1566
+ payload.embeds = opts.embeds.map((embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed);
1351
1567
  }
1352
- if (payload.attachments) {
1353
- payload.attachments = await Promise.all(
1354
- payload.attachments.map(
1355
- (attachment) => resolveAttachment(this.client.rest, attachment, "attachments")
1356
- )
1568
+ if (opts.attachments && opts.attachments.length > 0) {
1569
+ const resolved = await Promise.all(
1570
+ opts.attachments.map((attachment) => resolveAttachment(this.client.rest, attachment, "attachments"))
1357
1571
  );
1572
+ const validAttachments = resolved.filter((id) => id !== void 0);
1573
+ if (validAttachments.length > 0) {
1574
+ payload.attachments = validAttachments;
1575
+ }
1358
1576
  }
1359
1577
  const data = await this.client.rest.post(`/channels/${this.channel.id}/messages`, payload);
1360
1578
  return new Message(this.client, data);
@@ -1367,19 +1585,20 @@ var MessageManager = class extends BaseManager {
1367
1585
  */
1368
1586
  async edit(message, contentOrOptions) {
1369
1587
  const id = this.resolveId(message);
1370
- const payload = typeof contentOrOptions === "string" ? { content: contentOrOptions } : { ...contentOrOptions };
1371
- if (payload.embeds) {
1372
- payload.embeds = payload.embeds.map(
1373
- (embed) => typeof embed.toJSON === "function" ? embed.toJSON() : embed
1374
- );
1588
+ const opts = typeof contentOrOptions === "string" ? { content: contentOrOptions } : contentOrOptions;
1589
+ const payload = {};
1590
+ if (opts.content !== void 0) {
1591
+ payload.content = opts.content;
1375
1592
  }
1376
- const data = await this.client.rest.patch(`/channels/${this.channel.id}/messages/${id}`, payload);
1377
- const existing = this.cache.get(id);
1378
- if (existing) {
1379
- existing._patch(data);
1380
- return existing;
1593
+ if (opts.embeds !== void 0) {
1594
+ if (opts.embeds === null) {
1595
+ payload.embeds = [];
1596
+ } else {
1597
+ payload.embeds = opts.embeds.map((embed) => "toJSON" in embed ? embed.toJSON() : embed);
1598
+ }
1381
1599
  }
1382
- return new Message(this.client, data);
1600
+ const data = await this.client.rest.patch(`/channels/${this.channel.id}/messages/${id}`, payload);
1601
+ return this._add(data);
1383
1602
  }
1384
1603
  /**
1385
1604
  * Deletes a message from the channel.
@@ -1396,7 +1615,7 @@ var MessageManager = class extends BaseManager {
1396
1615
  */
1397
1616
  async pin(message) {
1398
1617
  const id = this.resolveId(message);
1399
- await this.client.rest.post(`/channels/${this.channel.id}/messages/${id}/pin`, {});
1618
+ await this.client.rest.post(`/channels/${this.channel.id}/messages/${id}/pin`);
1400
1619
  const existing = this.cache.get(id);
1401
1620
  if (existing) existing.pinned = true;
1402
1621
  }
@@ -1442,12 +1661,14 @@ var MessageManager = class extends BaseManager {
1442
1661
  async removeReaction(message, reaction, userId, removeAll) {
1443
1662
  const id = this.resolveId(message);
1444
1663
  const targetUser = userId ? this.client.users.resolveId(userId) : void 0;
1445
- const params = new URLSearchParams();
1446
- if (targetUser) params.append("user_id", targetUser);
1447
- if (removeAll) params.append("remove_all", "true");
1448
- const queryString = params.toString();
1449
- const endpoint = `/channels/${this.channel.id}/messages/${id}/reactions/${encodeURIComponent(reaction)}${queryString ? `?${queryString}` : ""}`;
1450
- await this.client.rest.delete(endpoint);
1664
+ const endpoint = `/channels/${this.channel.id}/messages/${id}/reactions/${reaction}`;
1665
+ const query = {};
1666
+ if (targetUser) {
1667
+ query.user_id = targetUser;
1668
+ } else if (removeAll) {
1669
+ query.remove_all = true;
1670
+ }
1671
+ await this.client.rest.delete(endpoint, query);
1451
1672
  }
1452
1673
  /**
1453
1674
  * Remove all reactions from a message
@@ -1461,7 +1682,7 @@ var MessageManager = class extends BaseManager {
1461
1682
  const id = this.resolveId(message);
1462
1683
  await this.client.rest.delete(`/channels/${this.channel.id}/messages/${id}/reactions`);
1463
1684
  }
1464
- [util3.inspect.custom]() {
1685
+ [util4.inspect.custom]() {
1465
1686
  return this.cache;
1466
1687
  }
1467
1688
  };
@@ -1498,6 +1719,8 @@ var MessageCollector = class extends Collector {
1498
1719
  super.handleCollect(message);
1499
1720
  if (!this.ended && this.collected.has(message.id)) {
1500
1721
  this.total++;
1722
+ }
1723
+ if (!this.ended) {
1501
1724
  this.checkEnd();
1502
1725
  }
1503
1726
  }
@@ -1510,12 +1733,6 @@ var MessageCollector = class extends Collector {
1510
1733
  };
1511
1734
 
1512
1735
  // src/structures/BaseChannel.ts
1513
- var ChannelType = /* @__PURE__ */ ((ChannelType2) => {
1514
- ChannelType2["TEXT"] = "TextChannel";
1515
- ChannelType2["DM"] = "DirectMessage";
1516
- ChannelType2["GROUP"] = "Group";
1517
- return ChannelType2;
1518
- })(ChannelType || {});
1519
1736
  var BaseChannel = class extends Base {
1520
1737
  type;
1521
1738
  messages;
@@ -1639,13 +1856,13 @@ var BaseChannel = class extends Base {
1639
1856
  });
1640
1857
  }
1641
1858
  isText() {
1642
- return this.type === "TextChannel" /* TEXT */;
1859
+ return this.type === "TextChannel";
1643
1860
  }
1644
1861
  isDM() {
1645
- return this.type === "DirectMessage" /* DM */;
1862
+ return this.type === "DirectMessage";
1646
1863
  }
1647
1864
  isGroup() {
1648
- return this.type === "Group" /* GROUP */;
1865
+ return this.type === "Group";
1649
1866
  }
1650
1867
  };
1651
1868
 
@@ -1665,7 +1882,9 @@ var TextChannel = class extends BaseChannel {
1665
1882
  this.serverId = data.server;
1666
1883
  this.defaultPermissions = data.default_permissions;
1667
1884
  this.description = data.description;
1668
- this.icon = data.icon;
1885
+ if (data.icon !== void 0) {
1886
+ this.icon = data.icon ? new Attachment(this.client, data.icon) : null;
1887
+ }
1669
1888
  this.lastMessageId = data.last_message_id;
1670
1889
  this.nsfw = data.nsfw ?? false;
1671
1890
  this.slowmode = data.slowmode ?? 0;
@@ -1735,6 +1954,9 @@ var TextChannel = class extends BaseChannel {
1735
1954
  async setCategory(category) {
1736
1955
  const serverId = this.serverId;
1737
1956
  const server = await this.client.servers.fetch(serverId);
1957
+ if (!server.categories || server.categories.length === 0) {
1958
+ throw new Error("This server has no categories to move the channel into.");
1959
+ }
1738
1960
  const categories = server.categories.map((c) => ({
1739
1961
  id: c.id,
1740
1962
  title: c.title,
@@ -1765,6 +1987,9 @@ var TextChannel = class extends BaseChannel {
1765
1987
  async setPosition(position) {
1766
1988
  const serverId = this.serverId;
1767
1989
  const server = await this.client.servers.fetch(serverId);
1990
+ if (!server.categories || server.categories.length === 0) {
1991
+ throw new Error("This server has no categories to move the channel into.");
1992
+ }
1768
1993
  const categories = server.categories.map((c) => ({
1769
1994
  id: c.id,
1770
1995
  title: c.title,
@@ -1876,7 +2101,7 @@ var DMChannel = class extends BaseChannel {
1876
2101
  };
1877
2102
 
1878
2103
  // src/structures/GroupChannel.ts
1879
- import * as util4 from "util";
2104
+ import * as util5 from "util";
1880
2105
  var GroupChannel = class extends BaseChannel {
1881
2106
  name;
1882
2107
  ownerId;
@@ -1936,7 +2161,7 @@ var GroupChannel = class extends BaseChannel {
1936
2161
  async setDefaultPermissions(permissions) {
1937
2162
  return await this.client.channels.setDefaultPermissions(this.id, permissions);
1938
2163
  }
1939
- [util4.inspect.custom](_depth, options, inspect12) {
2164
+ [util5.inspect.custom](_depth, options, inspect12) {
1940
2165
  const { client, ...props } = this;
1941
2166
  return `${this.constructor.name} ${inspect12(
1942
2167
  {
@@ -1952,14 +2177,14 @@ var GroupChannel = class extends BaseChannel {
1952
2177
  // src/utils/ChannelFactory.ts
1953
2178
  function createChannel(client, data) {
1954
2179
  switch (data.channel_type) {
1955
- case "TextChannel" /* TEXT */:
2180
+ case "TextChannel":
1956
2181
  return new TextChannel(client, data);
1957
- case "DirectMessage" /* DM */:
2182
+ case "DirectMessage":
1958
2183
  return new DMChannel(client, data);
1959
- case "Group" /* GROUP */:
2184
+ case "Group":
1960
2185
  return new GroupChannel(client, data);
1961
2186
  default:
1962
- client.emit("debug", `Received unknown channel type: ${data.type}`);
2187
+ client.emit("debug", `Received unknown channel type: ${data.channel_type}`);
1963
2188
  return new UnknownChannel(client, data);
1964
2189
  }
1965
2190
  }
@@ -2268,7 +2493,7 @@ var ChannelManager = class extends BaseManager {
2268
2493
  super(client, limit);
2269
2494
  }
2270
2495
  extractId(data) {
2271
- return data._id ?? data.id;
2496
+ return data._id;
2272
2497
  }
2273
2498
  construct(data) {
2274
2499
  return createChannel(this.client, data);
@@ -2361,8 +2586,14 @@ var ChannelManager = class extends BaseManager {
2361
2586
  else payload.description = options.description;
2362
2587
  }
2363
2588
  if (options.icon !== void 0) {
2364
- if (options.icon === null) remove.push("Icon");
2365
- else payload.icon = await resolveAttachment(this.client.rest, options.icon, "icons");
2589
+ if (options.icon === null) {
2590
+ remove.push("Icon");
2591
+ } else {
2592
+ const resolvedIcon = await resolveAttachment(this.client.rest, options.icon, "icons");
2593
+ if (resolvedIcon !== void 0) {
2594
+ payload.icon = resolvedIcon;
2595
+ }
2596
+ }
2366
2597
  }
2367
2598
  if (remove.length > 0) payload.remove = remove;
2368
2599
  if (Object.keys(payload).length === 0) return this.fetch(channel);
@@ -2447,7 +2678,7 @@ var ChannelManager = class extends BaseManager {
2447
2678
  * await client.channels.pin("CHANNEL_ID", "MESSAGE_ID");
2448
2679
  */
2449
2680
  async pin(id, messageId) {
2450
- await this.client.rest.post(`/channels/${id}/pins/${messageId}`);
2681
+ await this.client.rest.post(`/channels/${id}/messages/${messageId}/pin`);
2451
2682
  }
2452
2683
  /**
2453
2684
  * Unpin a message
@@ -2477,12 +2708,12 @@ var ChannelManager = class extends BaseManager {
2477
2708
  if ("id" in msg) return msg.id;
2478
2709
  throw new TypeError("Invalid MessageResolvable provided. Expected a Message object or a string ID/Mention.");
2479
2710
  });
2480
- await this.client.rest.delete(`/channels/${id}/messages/bulk`, { messages: messageIds });
2711
+ await this.client.rest.delete(`/channels/${id}/messages/bulk`, { ids: messageIds });
2481
2712
  }
2482
2713
  };
2483
2714
 
2484
2715
  // src/structures/Member.ts
2485
- import * as util5 from "util";
2716
+ import * as util6 from "util";
2486
2717
 
2487
2718
  // src/managers/MemberRoleManager.ts
2488
2719
  var MemberRoleManager = class {
@@ -2576,20 +2807,20 @@ var Member = class extends Base {
2576
2807
  canRecieve = false;
2577
2808
  // Member roles manager
2578
2809
  roles;
2579
- constructor(client, data) {
2580
- super(client, { _id: data.user._id });
2581
- this.serverId = data.serverId || data.server_id;
2582
- this.joinedAt = new Date(data.joinedAt || data.joined_at);
2810
+ constructor(client, data, serverId) {
2811
+ super(client, { _id: data._id?.user });
2812
+ this.serverId = data._id?.server ?? serverId;
2813
+ this.joinedAt = new Date(data.joined_at);
2583
2814
  this.roles = new MemberRoleManager(this);
2584
2815
  this._patch(data);
2585
2816
  }
2586
2817
  _patch(data) {
2587
2818
  if (data.nickname !== void 0) this.nickname = data.nickname;
2588
- if (data.avatar !== void 0) this.avatar = data.avatar;
2819
+ if (data.avatar !== void 0) this.avatar = data.avatar ? new Attachment(this.client, data.avatar) : null;
2589
2820
  if (data.roles !== void 0) this._roles = data.roles;
2590
2821
  if (data.timeout !== void 0) this.timeout = data.timeout ? new Date(data.timeout) : null;
2591
- if (data.can_publish !== void 0) this.canPublish = data.canPublish;
2592
- if (data.can_recieve !== void 0) this.canRecieve = data.canRecieve;
2822
+ if (data.can_publish !== void 0) this.canPublish = data.can_publish;
2823
+ if (data.can_receive !== void 0) this.canRecieve = data.can_receive;
2593
2824
  }
2594
2825
  /**
2595
2826
  * Get member role IDs
@@ -2709,7 +2940,7 @@ var Member = class extends Base {
2709
2940
  await server.members.kick(this.id);
2710
2941
  }
2711
2942
  /** @internal */
2712
- [util5.inspect.custom](depth, options, inspect12) {
2943
+ [util6.inspect.custom](depth, options, inspect12) {
2713
2944
  const { client, serverId, ...props } = this;
2714
2945
  return `${this.constructor.name} ${inspect12(
2715
2946
  {
@@ -2723,7 +2954,7 @@ var Member = class extends Base {
2723
2954
  };
2724
2955
 
2725
2956
  // src/managers/MemberManager.ts
2726
- import * as util6 from "util";
2957
+ import * as util7 from "util";
2727
2958
  var MemberManager = class extends BaseManager {
2728
2959
  constructor(client, server, limit = Infinity) {
2729
2960
  super(client, limit);
@@ -2734,17 +2965,14 @@ var MemberManager = class extends BaseManager {
2734
2965
  * @internal
2735
2966
  */
2736
2967
  extractId(data) {
2737
- return data.user_id ?? data.id ?? (typeof data._id === "string" ? data._id : data._id?.user);
2968
+ return data._id?.user;
2738
2969
  }
2739
2970
  /**
2740
2971
  * Tell BaseManager how to build a Member
2741
2972
  * @internal
2742
2973
  */
2743
2974
  construct(data) {
2744
- if (!data.server_id && !data.serverId) {
2745
- data.serverId = this.server.id;
2746
- }
2747
- return new Member(this.client, data);
2975
+ return new Member(this.client, data, this.server.id);
2748
2976
  }
2749
2977
  /**
2750
2978
  * Resolve a string or mention to Member
@@ -2803,23 +3031,22 @@ var MemberManager = class extends BaseManager {
2803
3031
  * const onlineMembers = await server.members.fetchMany({ exclude_offline: true });
2804
3032
  */
2805
3033
  async fetchMany(options = {}) {
2806
- const params = new URLSearchParams();
2807
- if (options.exclude_offline !== void 0) {
2808
- params.append("exclude_offline", options.exclude_offline.toString());
3034
+ const query = {};
3035
+ if (options.excludeOffline !== void 0) {
3036
+ query.exclude_offline = options.excludeOffline;
2809
3037
  }
2810
- const queryString = params.toString();
2811
- const endpoint = `/servers/${this.server.id}/members${queryString ? `?${queryString}` : ""}`;
2812
- const data = await this.client.rest.get(endpoint);
2813
- if (data.users && Array.isArray(data.users)) {
3038
+ const data = await this.client.rest.get(`/servers/${this.server.id}/members`, query);
3039
+ if (data.users) {
2814
3040
  for (const userData of data.users) {
2815
3041
  this.client.users._add(userData);
2816
3042
  }
2817
3043
  }
2818
3044
  const fetched = new Collection();
2819
- const rawMembers = data.members || (Array.isArray(data) ? data : []);
2820
- for (const rawMember of rawMembers) {
2821
- const member = this._add(rawMember);
2822
- fetched.set(member.id, member);
3045
+ if (data.members) {
3046
+ for (const rawMember of data.members) {
3047
+ const member = this._add(rawMember);
3048
+ fetched.set(member.id, member);
3049
+ }
2823
3050
  }
2824
3051
  return fetched;
2825
3052
  }
@@ -2897,13 +3124,13 @@ var MemberManager = class extends BaseManager {
2897
3124
  const id = this.resolveId(member);
2898
3125
  await this.client.rest.delete(`/servers/${this.server.id}/bans/${id}`);
2899
3126
  }
2900
- [util6.inspect.custom]() {
3127
+ [util7.inspect.custom]() {
2901
3128
  return this.cache;
2902
3129
  }
2903
3130
  };
2904
3131
 
2905
3132
  // src/managers/ServerChannelManager.ts
2906
- import * as util7 from "util";
3133
+ import * as util8 from "util";
2907
3134
  var ServerChannelManager = class {
2908
3135
  client;
2909
3136
  server;
@@ -2922,24 +3149,30 @@ var ServerChannelManager = class {
2922
3149
  async create(options) {
2923
3150
  if (!options.name) throw new Error("A channel name must be provided.");
2924
3151
  const payload = {
2925
- name: options.name,
2926
- type: options.type ?? "Text",
2927
- description: options.description,
2928
- nsfw: options.nsfw ?? false
3152
+ name: options.name
2929
3153
  };
3154
+ if (options.nsfw !== void 0) {
3155
+ payload.nsfw = options.nsfw;
3156
+ }
3157
+ if (options.type !== void 0) {
3158
+ payload.type = options.type;
3159
+ }
3160
+ if (options.description !== void 0) {
3161
+ payload.description = options.description;
3162
+ }
2930
3163
  if (options.type === "Voice" && options.voice?.max_users) {
2931
3164
  payload.voice = { max_users: options.voice.max_users };
2932
3165
  }
2933
3166
  const data = await this.client.rest.post(`/servers/${this.server.id}/channels`, payload);
2934
3167
  return this.client.channels._add(data);
2935
3168
  }
2936
- [util7.inspect.custom]() {
3169
+ [util8.inspect.custom]() {
2937
3170
  return this.cache;
2938
3171
  }
2939
3172
  };
2940
3173
 
2941
3174
  // src/structures/Role.ts
2942
- import * as util8 from "util";
3175
+ import * as util9 from "util";
2943
3176
  var Role = class extends Base {
2944
3177
  serverId;
2945
3178
  name;
@@ -2959,14 +3192,14 @@ var Role = class extends Base {
2959
3192
  */
2960
3193
  _patch(data) {
2961
3194
  if (data.name !== void 0) this.name = data.name;
2962
- if (data.color !== void 0) this.color = data.color;
3195
+ if (data.colour !== void 0) this.color = data.colour;
2963
3196
  if (data.hoist !== void 0) this.hoist = data.hoist;
2964
3197
  if (data.rank !== void 0) this.rank = data.rank;
2965
- if (data.icon !== void 0) this.icon = new Attachment(this.client, data.icon);
3198
+ if (data.icon !== void 0) this.icon = data.icon !== null ? new Attachment(this.client, data.icon) : null;
2966
3199
  if (data.permissions !== void 0) {
2967
3200
  try {
2968
3201
  if (typeof data.permissions === "object" && data.permissions !== null) {
2969
- const allowPerms = data.permissions.a ?? data.permissions[0] ?? 0;
3202
+ const allowPerms = data.permissions.a ?? 0;
2970
3203
  this._permissions = BigInt(allowPerms);
2971
3204
  } else {
2972
3205
  this._permissions = BigInt(data.permissions);
@@ -3149,14 +3382,14 @@ var Role = class extends Base {
3149
3382
  * Hides the cyclic client reference and raw serverId for a cleaner output.
3150
3383
  * @internal
3151
3384
  */
3152
- [util8.inspect.custom]() {
3385
+ [util9.inspect.custom]() {
3153
3386
  const { client, serverId, ...props } = this;
3154
- return `${this.constructor.name} ${util8.inspect(props)}`;
3387
+ return `${this.constructor.name} ${util9.inspect(props)}`;
3155
3388
  }
3156
3389
  };
3157
3390
 
3158
3391
  // src/managers/RoleManager.ts
3159
- import * as util9 from "util";
3392
+ import * as util10 from "util";
3160
3393
  var RoleManager = class extends BaseManager {
3161
3394
  /**
3162
3395
  * Manages API methods and caching for server roles.
@@ -3169,7 +3402,7 @@ var RoleManager = class extends BaseManager {
3169
3402
  * Tell BaseManager how to find the ID for Roles
3170
3403
  */
3171
3404
  extractId(data) {
3172
- return data._id ?? data.id;
3405
+ return data._id;
3173
3406
  }
3174
3407
  /**
3175
3408
  * Tell BaseManager how to build a Role
@@ -3185,7 +3418,7 @@ var RoleManager = class extends BaseManager {
3185
3418
  * @returns The newly created or updated Role object.
3186
3419
  */
3187
3420
  _add(data, idParam) {
3188
- const id = idParam ?? data._id ?? data.id;
3421
+ const id = idParam ?? data._id;
3189
3422
  const existing = this.cache.get(id);
3190
3423
  if (existing) {
3191
3424
  existing._patch(data);
@@ -3195,7 +3428,7 @@ var RoleManager = class extends BaseManager {
3195
3428
  this.cache.set(role.id, role);
3196
3429
  return role;
3197
3430
  }
3198
- [util9.inspect.custom]() {
3431
+ [util10.inspect.custom]() {
3199
3432
  return this.cache;
3200
3433
  }
3201
3434
  /**
@@ -3248,7 +3481,7 @@ var RoleManager = class extends BaseManager {
3248
3481
  name: options.name
3249
3482
  };
3250
3483
  const data = await this.client.rest.post(`/servers/${this.server.id}/roles`, payload);
3251
- return this._add(data);
3484
+ return this._add(data.role);
3252
3485
  }
3253
3486
  /**
3254
3487
  * Fetches a Role from the API or resolves it from the local cache.
@@ -3313,7 +3546,10 @@ var RoleManager = class extends BaseManager {
3313
3546
  if (options.icon === null) {
3314
3547
  remove.push("Icon");
3315
3548
  } else {
3316
- payload.icon = await resolveAttachment(this.client.rest, options.icon, "icons");
3549
+ const resolvedIcon = await resolveAttachment(this.client.rest, options.icon, "icons");
3550
+ if (resolvedIcon !== void 0) {
3551
+ payload.icon = resolvedIcon;
3552
+ }
3317
3553
  }
3318
3554
  }
3319
3555
  if (remove.length > 0) {
@@ -3322,7 +3558,8 @@ var RoleManager = class extends BaseManager {
3322
3558
  if (Object.keys(payload).length === 0) {
3323
3559
  return this.fetch(id);
3324
3560
  }
3325
- const data = await this.client.rest.patch(`/servers/${this.server.id}/roles/${id}`, payload);
3561
+ const endpoint = `/servers/${this.server.id}/roles/${id}`;
3562
+ const data = await this.client.rest.patch(endpoint, payload);
3326
3563
  return this._add(data, id);
3327
3564
  }
3328
3565
  /**
@@ -3398,7 +3635,7 @@ var RoleManager = class extends BaseManager {
3398
3635
  const payload = {
3399
3636
  ranks: mappedIds
3400
3637
  };
3401
- const data = await this.client.rest.put(`/servers/${this.server.id}/roles`, payload);
3638
+ const data = await this.client.rest.patch(`/servers/${this.server.id}/roles/ranks`, payload);
3402
3639
  this.server._patch(data);
3403
3640
  return this.server;
3404
3641
  }
@@ -3410,7 +3647,7 @@ var ServerInvite = class {
3410
3647
  creatorId;
3411
3648
  channelId;
3412
3649
  constructor(data) {
3413
- this.code = data._id ?? data.code;
3650
+ this.code = data._id;
3414
3651
  this.creatorId = data.creator;
3415
3652
  this.channelId = data.channel;
3416
3653
  }
@@ -3427,7 +3664,7 @@ var ServerInviteManager = class extends BaseManager {
3427
3664
  this.server = server;
3428
3665
  }
3429
3666
  extractId(data) {
3430
- return data._id ?? data.code;
3667
+ return data._id;
3431
3668
  }
3432
3669
  construct(data) {
3433
3670
  return new ServerInvite(data);
@@ -3437,9 +3674,8 @@ var ServerInviteManager = class extends BaseManager {
3437
3674
  */
3438
3675
  async fetch() {
3439
3676
  const data = await this.client.rest.get(`/servers/${this.server.id}/invites`);
3440
- const rawInvites = Array.isArray(data) ? data : [];
3441
3677
  const fetched = new Collection();
3442
- for (const raw of rawInvites) {
3678
+ for (const raw of data) {
3443
3679
  const invite = this._add(raw);
3444
3680
  fetched.set(invite.code, invite);
3445
3681
  }
@@ -3452,7 +3688,7 @@ var ServerBan = class {
3452
3688
  userId;
3453
3689
  reason;
3454
3690
  constructor(data) {
3455
- this.userId = data._id?.user ?? data.id;
3691
+ this.userId = data._id?.user;
3456
3692
  this.reason = data.reason ?? null;
3457
3693
  }
3458
3694
  _patch(data) {
@@ -3524,7 +3760,7 @@ var Emoji = class extends Base {
3524
3760
  };
3525
3761
 
3526
3762
  // src/managers/EmojiManager.ts
3527
- import * as util10 from "util";
3763
+ import * as util11 from "util";
3528
3764
  var EmojiManager = class extends BaseManager {
3529
3765
  constructor(client, server, limit = Infinity) {
3530
3766
  super(client, limit);
@@ -3546,7 +3782,7 @@ var EmojiManager = class extends BaseManager {
3546
3782
  const data = await this.client.rest.get(`/custom/emoji/${id}`);
3547
3783
  return this._add(data);
3548
3784
  }
3549
- [util10.inspect.custom]() {
3785
+ [util11.inspect.custom]() {
3550
3786
  return this.cache;
3551
3787
  }
3552
3788
  };
@@ -3559,7 +3795,7 @@ var Server = class extends Base {
3559
3795
  ownerId;
3560
3796
  analytics = false;
3561
3797
  banner = null;
3562
- categories = [];
3798
+ categories = null;
3563
3799
  description = null;
3564
3800
  discoverable = false;
3565
3801
  flags = 0;
@@ -3612,13 +3848,6 @@ var Server = class extends Base {
3612
3848
  this.roles._add({ id, ...roleData });
3613
3849
  }
3614
3850
  }
3615
- if (data.emojis !== void 0) {
3616
- if (Array.isArray(data.emojis)) {
3617
- for (const emoji of data.emojis) {
3618
- this.emojis._add(emoji);
3619
- }
3620
- }
3621
- }
3622
3851
  if (clear && Array.isArray(clear)) {
3623
3852
  for (const field of clear) {
3624
3853
  switch (field) {
@@ -3657,7 +3886,7 @@ var Server = class extends Base {
3657
3886
  };
3658
3887
 
3659
3888
  // src/managers/ServerManager.ts
3660
- import * as util11 from "util";
3889
+ import * as util12 from "util";
3661
3890
  var ServerManager = class extends BaseManager {
3662
3891
  constructor(client, limit = Infinity) {
3663
3892
  super(client, limit);
@@ -3666,7 +3895,7 @@ var ServerManager = class extends BaseManager {
3666
3895
  * Tell BaseManager how to find the ID for Servers
3667
3896
  */
3668
3897
  extractId(data) {
3669
- return data._id ?? data.id;
3898
+ return data._id;
3670
3899
  }
3671
3900
  /**
3672
3901
  * Tell BaseManager how to build a Server
@@ -3707,21 +3936,19 @@ var ServerManager = class extends BaseManager {
3707
3936
  payload.system_messages = {};
3708
3937
  const sm = options.systemMessages;
3709
3938
  if (sm.userJoined !== void 0) {
3710
- if (sm.userJoined === null) remove.push("SystemMessageUserJoined");
3711
- else payload.system_messages.user_joined = sm.userJoined;
3939
+ payload.system_messages.user_joined = sm.userJoined;
3712
3940
  }
3713
3941
  if (sm.userLeft !== void 0) {
3714
- if (sm.userLeft === null) remove.push("SystemMessageUserLeft");
3715
- else payload.system_messages.user_left = sm.userLeft;
3942
+ payload.system_messages.user_left = sm.userLeft;
3716
3943
  }
3717
3944
  if (sm.userKicked !== void 0) {
3718
- if (sm.userKicked === null) remove.push("SystemMessageUserKicked");
3719
- else payload.system_messages.user_kicked = sm.userKicked;
3945
+ payload.system_messages.user_kicked = sm.userKicked;
3720
3946
  }
3721
3947
  if (sm.userBanned !== void 0) {
3722
- if (sm.userBanned === null) remove.push("SystemMessageUserBanned");
3723
- else payload.system_messages.user_banned = sm.userBanned;
3948
+ payload.system_messages.user_banned = sm.userBanned;
3724
3949
  }
3950
+ } else if (options.systemMessages === null) {
3951
+ remove.push("SystemMessages");
3725
3952
  }
3726
3953
  if (options.categories !== void 0) payload.categories = options.categories;
3727
3954
  if (options.analytics !== void 0) payload.analytics = options.analytics;
@@ -3730,7 +3957,7 @@ var ServerManager = class extends BaseManager {
3730
3957
  const data = await this.client.rest.patch(`/servers/${serverId}`, payload);
3731
3958
  return this._add(data);
3732
3959
  }
3733
- [util11.inspect.custom]() {
3960
+ [util12.inspect.custom]() {
3734
3961
  return this.cache;
3735
3962
  }
3736
3963
  };
@@ -3744,7 +3971,7 @@ var UserManager = class extends BaseManager {
3744
3971
  * Tell BaseManager how to find the ID for Users
3745
3972
  */
3746
3973
  extractId(data) {
3747
- return data._id ?? data.id;
3974
+ return data._id;
3748
3975
  }
3749
3976
  /**
3750
3977
  * Tell BaseManager how to build a User
@@ -3879,7 +4106,7 @@ var UserManager = class extends BaseManager {
3879
4106
  if (Object.keys(payload).length === 0) {
3880
4107
  return this.fetch("@me");
3881
4108
  }
3882
- const data = await this.client.rest.patch(`/users/@me`, payload);
4109
+ const data = await this.client.rest.patch(`/users/${this.client.user?.id}`, payload);
3883
4110
  return this._add(data);
3884
4111
  }
3885
4112
  /**
@@ -4039,14 +4266,17 @@ var EmbedBuilder = class {
4039
4266
  return { ...this.data };
4040
4267
  }
4041
4268
  };
4269
+
4270
+ // src/index.ts
4271
+ import * as API from "stoat-api";
4042
4272
  export {
4273
+ API,
4043
4274
  Attachment,
4044
4275
  AttachmentBuilder,
4045
4276
  Base,
4046
4277
  BaseChannel,
4047
4278
  BitField,
4048
4279
  ChannelManager,
4049
- ChannelType,
4050
4280
  Client,
4051
4281
  ClientUser,
4052
4282
  Collection,
@@ -4056,6 +4286,7 @@ export {
4056
4286
  Emoji,
4057
4287
  EmojiManager,
4058
4288
  GatewayManager,
4289
+ GroupChannel,
4059
4290
  Member,
4060
4291
  MemberManager,
4061
4292
  Message,
@@ -4076,8 +4307,6 @@ export {
4076
4307
  TextChannel,
4077
4308
  UnknownChannel,
4078
4309
  User,
4079
- UserManager,
4080
- UserPresence,
4081
- UserRelationship
4310
+ UserManager
4082
4311
  };
4083
4312
  //# sourceMappingURL=index.js.map