@discordeno/rest 19.0.0-next.f2b6590 → 19.0.0-next.f41fe4d

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/manager.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable no-const-assign */ import { InteractionResponseTypes } from '@discordeno/types';
2
- import { calculateBits, camelize, camelToSnakeCase, delay, encode, findFiles, getBotIdFromToken, isGetMessagesAfter, isGetMessagesAround, isGetMessagesBefore, isGetMessagesLimit, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
2
+ import { calculateBits, camelize, camelToSnakeCase, delay, encode, getBotIdFromToken, isGetMessagesAfter, isGetMessagesAround, isGetMessagesBefore, isGetMessagesLimit, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
3
3
  import fetch from 'node-fetch';
4
4
  import { createInvalidRequestBucket } from './invalidBucket.js';
5
5
  import { Queue } from './queue.js';
@@ -218,6 +218,8 @@ export function createRestManager(options) {
218
218
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
219
219
  if (options.before) url += `&before=${options.before}`;
220
220
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
221
+ if (options.after) url += `&after=${options.after}`;
222
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
221
223
  if (options.limit) url += `&limit=${options.limit}`;
222
224
  // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
223
225
  if (options.userId) url += `&user_id=${options.userId}`;
@@ -548,50 +550,40 @@ export function createRestManager(options) {
548
550
  'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`
549
551
  };
550
552
  if (!options.unauthorized) headers.authorization = `Bot ${rest.token}`;
551
- // SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
552
- if (options.headers) {
553
- for(const key in options.headers){
554
- headers[key.toLowerCase()] = options.headers[key];
555
- }
556
- }
557
- // GET METHODS SHOULD NOT HAVE A BODY
558
- if (options.method === 'GET') {
559
- options.body = undefined;
560
- }
561
553
  // IF A REASON IS PROVIDED ENCODE IT IN HEADERS
562
- if (options.body?.reason) {
563
- headers['X-Audit-Log-Reason'] = encodeURIComponent(options.body.reason);
564
- options.body.reason = undefined;
554
+ if (options.reason !== undefined) {
555
+ headers['x-audit-log-reason'] = encodeURIComponent(options.reason);
565
556
  }
566
- if (options.body) {
567
- const { file } = options.body;
568
- if (file) {
569
- const files = findFiles(file);
570
- const form = new FormData();
571
- // WHEN CREATING A STICKER, DISCORD WANTS FORM DATA ONLY
572
- if (options.url?.endsWith('/stickers') && options.method === 'POST') {
573
- form.append('file', files[0].blob, files[0].name);
574
- form.append('name', options.body.name);
575
- form.append('description', options.body.description);
576
- form.append('tags', options.body.tags);
577
- } else {
578
- for(let i = 0; i < files.length; i++){
579
- form.append(`file${i}`, files[i].blob, files[i].name);
580
- }
581
- if (file) options.body.file = undefined;
582
- form.append('payload_json', JSON.stringify(rest.changeToDiscordFormat(options.body)));
583
- }
584
- options.body.file = form;
585
- } else if (options.body && ![
586
- 'GET',
587
- 'DELETE'
588
- ].includes(options.method)) {
589
- headers['Content-Type'] = 'application/json';
557
+ let body;
558
+ // TODO: check if we need to add specific check for GET method
559
+ // Since GET does not allow bodies
560
+ // Have to check for attachments first, since body then has to be send in a different way.
561
+ if (options.attachments !== undefined) {
562
+ const form = new FormData();
563
+ for(let i = 0; i < options.attachments.length; ++i){
564
+ form.append(`file${i}`, options.attachments[i].blob, options.attachments[i].name);
565
+ }
566
+ form.append('payload_json', JSON.stringify(options.body));
567
+ body = form;
568
+ // TODO: boundary?
569
+ // `multipart/form-data; boundary=${form.getBoundary()}`
570
+ headers['content-type'] = `multipart/form-data`;
571
+ } else if (options.body !== undefined) {
572
+ if (options.body instanceof FormData) {
573
+ body = options.body;
574
+ headers['content-type'] = `multipart/form-data`;
575
+ } else {
576
+ body = JSON.stringify(options.body);
577
+ headers['content-type'] = `application/json`;
590
578
  }
591
579
  }
580
+ // SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
581
+ if (options.headers) {
582
+ Object.assign(headers, options.headers);
583
+ }
592
584
  return {
585
+ body,
593
586
  headers,
594
- body: options.body?.file ?? JSON.stringify(rest.changeToDiscordFormat(options.body)),
595
587
  method: options.method
596
588
  };
597
589
  },
@@ -690,7 +682,7 @@ export function createRestManager(options) {
690
682
  const payload = rest.createRequest({
691
683
  method: options.method,
692
684
  url: options.url,
693
- body: options.body,
685
+ body: options.options?.body,
694
686
  ...options.options
695
687
  });
696
688
  logger.debug(`sending request to ${url}`, 'with payload:', {
@@ -745,24 +737,26 @@ export function createRestManager(options) {
745
737
  body: JSON.stringify(json)
746
738
  });
747
739
  },
748
- // Credits: github.com/abalabahaha/eris lib/rest/RequestHandler.js#L397
749
- // Modified for our use-case
750
740
  simplifyUrl (url, method) {
751
- let route = url.replace(/\/([a-z-]+)\/(?:[0-9]{17,19})/g, function(match, p) {
752
- return [
753
- 'channels',
754
- 'guilds'
755
- ].includes(p) ? match : `/${p}/x`;
756
- }).replace(/\/reactions\/[^/]+/g, '/reactions/x');
757
- // GENERAL /reactions and /reactions/emoji/@me share the buckets
758
- if (route.includes('/reactions')) {
759
- route = route.substring(0, route.indexOf('/reactions') + '/reactions'.length);
741
+ const parts = url.split('/');
742
+ const secondLastPart = parts[parts.length - 2];
743
+ if (secondLastPart === 'channels' || secondLastPart === 'guilds') {
744
+ return url;
745
+ }
746
+ if (secondLastPart === 'reactions' || parts[parts.length - 1] === '@me') {
747
+ parts.splice(-2);
748
+ parts.push('reactions');
749
+ } else {
750
+ parts.splice(-1);
751
+ parts.push('x');
752
+ }
753
+ if (parts[parts.length - 3] === 'reactions') {
754
+ parts.splice(-2);
760
755
  }
761
- // Delete Message endpoint has its own rate limit
762
- if (method === 'DELETE' && route.endsWith('/messages/x')) {
763
- route = method + route;
756
+ if (method === 'DELETE' && secondLastPart === 'messages') {
757
+ return `D${parts.join('/')}`;
764
758
  }
765
- return route;
759
+ return parts.join('/');
766
760
  },
767
761
  processRequest (request) {
768
762
  const route = request.url.substring(request.url.indexOf('api/'));
@@ -789,17 +783,18 @@ export function createRestManager(options) {
789
783
  rest.queues.set(url, bucketQueue);
790
784
  }
791
785
  },
792
- async makeRequest (method, url, body, options) {
786
+ async makeRequest (method, url, options) {
793
787
  if (!rest.baseUrl.startsWith('https://discord.com') && url[0] === '/') {
794
788
  // Special handling for sending blobs across http to proxy
795
- if (body?.file) {
796
- if (!Array.isArray(body.file)) {
797
- body.file = [
798
- body.file
789
+ // TODO: fix this hacky handling
790
+ if (!(options?.body instanceof FormData) && !Array.isArray(options?.body) && options?.body?.file) {
791
+ if (!Array.isArray(options.body.file)) {
792
+ options.body.file = [
793
+ options.body.file
799
794
  ];
800
795
  }
801
796
  // convert blobs to string before sending to proxy
802
- body.file = await Promise.all(body.file.map(async (f)=>{
797
+ options.body.file = await Promise.all(options.body.file.map(async (f)=>{
803
798
  const url = encode(await f.blob.arrayBuffer());
804
799
  return {
805
800
  name: f.name,
@@ -808,13 +803,13 @@ export function createRestManager(options) {
808
803
  }));
809
804
  }
810
805
  const headers = {
811
- Authorization: rest.authorization ?? ""
806
+ Authorization: rest.authorization ?? ''
812
807
  };
813
- if (body) {
808
+ if (options?.body) {
814
809
  headers['Content-Type'] = 'application/json';
815
810
  }
816
811
  const result = await fetch(`${rest.baseUrl}${url}`, {
817
- body: body ? JSON.stringify(body) : undefined,
812
+ body: options?.body ? JSON.stringify(options.body) : undefined,
818
813
  headers,
819
814
  method
820
815
  });
@@ -830,34 +825,43 @@ export function createRestManager(options) {
830
825
  const payload = {
831
826
  url,
832
827
  method,
833
- body,
828
+ options,
834
829
  retryCount: 0,
835
- retryRequest: async function(options) {
830
+ retryRequest: async function(payload) {
836
831
  rest.processRequest(payload);
837
832
  },
838
833
  resolve: (data)=>{
839
834
  resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
840
835
  },
841
- reject,
842
- options
836
+ reject
843
837
  };
844
838
  rest.processRequest(payload);
845
839
  });
846
840
  },
847
- async get (url) {
848
- return camelize(await rest.makeRequest('GET', url));
841
+ async get (url, body) {
842
+ return camelize(await rest.makeRequest('GET', url, {
843
+ body
844
+ }));
849
845
  },
850
846
  async post (url, body) {
851
- return camelize(await rest.makeRequest('POST', url, body));
847
+ return camelize(await rest.makeRequest('POST', url, {
848
+ body
849
+ }));
852
850
  },
853
851
  async delete (url, body) {
854
- camelize(await rest.makeRequest('DELETE', url, body));
852
+ camelize(await rest.makeRequest('DELETE', url, {
853
+ body
854
+ }));
855
855
  },
856
856
  async patch (url, body) {
857
- return camelize(await rest.makeRequest('PATCH', url, body));
857
+ return camelize(await rest.makeRequest('PATCH', url, {
858
+ body
859
+ }));
858
860
  },
859
- async put (url, body, options) {
860
- return camelize(await rest.makeRequest('PUT', url, body, options));
861
+ async put (url, body) {
862
+ return camelize(await rest.makeRequest('PUT', url, {
863
+ body
864
+ }));
861
865
  },
862
866
  async addReaction (channelId, messageId, reaction) {
863
867
  reaction = processReactionString(reaction);
@@ -882,59 +886,92 @@ export function createRestManager(options) {
882
886
  async addThreadMember (channelId, userId) {
883
887
  await rest.put(rest.routes.channels.threads.user(channelId, userId));
884
888
  },
885
- async createAutomodRule (guildId, options) {
886
- return await rest.post(rest.routes.guilds.automod.rules(guildId), options);
889
+ async createAutomodRule (guildId, body) {
890
+ return await rest.post(rest.routes.guilds.automod.rules(guildId), {
891
+ body
892
+ });
887
893
  },
888
- async createChannel (guildId, options) {
889
- return await rest.post(rest.routes.guilds.channels(guildId), options);
894
+ async createChannel (guildId, body) {
895
+ return await rest.post(rest.routes.guilds.channels(guildId), {
896
+ body
897
+ });
890
898
  },
891
- async createEmoji (guildId, options) {
892
- return await rest.post(rest.routes.guilds.emojis(guildId), options);
899
+ async createEmoji (guildId, body) {
900
+ return await rest.post(rest.routes.guilds.emojis(guildId), {
901
+ body
902
+ });
893
903
  },
894
- async createGlobalApplicationCommand (command) {
895
- return await rest.post(rest.routes.interactions.commands.commands(rest.applicationId), command);
904
+ async createGlobalApplicationCommand (body) {
905
+ return await rest.post(rest.routes.interactions.commands.commands(rest.applicationId), {
906
+ body
907
+ });
896
908
  },
897
- async createGuild (options) {
898
- return await rest.post(rest.routes.guilds.all(), options);
909
+ async createGuild (body) {
910
+ return await rest.post(rest.routes.guilds.all(), {
911
+ body
912
+ });
899
913
  },
900
- async createGuildApplicationCommand (command, guildId) {
901
- return await rest.post(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), command);
914
+ async createGuildApplicationCommand (body, guildId) {
915
+ return await rest.post(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
916
+ body
917
+ });
902
918
  },
903
- async createGuildFromTemplate (templateCode, options) {
904
- if (options.icon) {
905
- options.icon = await urlToBase64(options.icon);
919
+ async createGuildFromTemplate (templateCode, body) {
920
+ if (body.icon) {
921
+ body.icon = await urlToBase64(body.icon);
906
922
  }
907
- return await rest.post(rest.routes.guilds.templates.code(templateCode), options);
923
+ return await rest.post(rest.routes.guilds.templates.code(templateCode), {
924
+ body
925
+ });
908
926
  },
909
927
  async createGuildSticker (guildId, options) {
910
- return await rest.post(rest.routes.guilds.stickers(guildId), options);
928
+ const form = new FormData();
929
+ form.append('file', options.file.blob, options.file.name);
930
+ form.append('name', options.name);
931
+ form.append('description', options.description);
932
+ form.append('tags', options.tags);
933
+ return await rest.post(rest.routes.guilds.stickers(guildId), {
934
+ body: form
935
+ });
911
936
  },
912
- async createGuildTemplate (guildId, options) {
913
- return await rest.post(rest.routes.guilds.templates.all(guildId), options);
937
+ async createGuildTemplate (guildId, body) {
938
+ return await rest.post(rest.routes.guilds.templates.all(guildId), {
939
+ body
940
+ });
914
941
  },
915
- async createForumThread (channelId, options) {
916
- return await rest.post(rest.routes.channels.forum(channelId), options);
942
+ async createForumThread (channelId, body) {
943
+ return await rest.post(rest.routes.channels.forum(channelId), {
944
+ body
945
+ });
917
946
  },
918
- async createInvite (channelId, options = {}) {
919
- return await rest.post(rest.routes.channels.invites(channelId), options);
947
+ async createInvite (channelId, body = {}) {
948
+ return await rest.post(rest.routes.channels.invites(channelId), {
949
+ body
950
+ });
920
951
  },
921
- async createRole (guildId, options, reason) {
952
+ async createRole (guildId, body, reason) {
922
953
  return await rest.post(rest.routes.guilds.roles.all(guildId), {
923
- ...options,
954
+ body,
924
955
  reason
925
956
  });
926
957
  },
927
- async createScheduledEvent (guildId, options) {
928
- return await rest.post(rest.routes.guilds.events.events(guildId), options);
958
+ async createScheduledEvent (guildId, body) {
959
+ return await rest.post(rest.routes.guilds.events.events(guildId), {
960
+ body
961
+ });
929
962
  },
930
- async createStageInstance (options) {
931
- return await rest.post(rest.routes.channels.stages(), options);
963
+ async createStageInstance (body) {
964
+ return await rest.post(rest.routes.channels.stages(), {
965
+ body
966
+ });
932
967
  },
933
- async createWebhook (channelId, options) {
968
+ async createWebhook (channelId, options, reason) {
934
969
  return await rest.post(rest.routes.channels.webhooks(channelId), {
935
- name: options.name,
936
- avatar: options.avatar ? await urlToBase64(options.avatar) : undefined,
937
- reason: options.reason
970
+ body: {
971
+ name: options.name,
972
+ avatar: options.avatar ? await urlToBase64(options.avatar) : undefined
973
+ },
974
+ reason
938
975
  });
939
976
  },
940
977
  async deleteAutomodRule (guildId, ruleId, reason) {
@@ -948,9 +985,9 @@ export function createRestManager(options) {
948
985
  });
949
986
  },
950
987
  async deleteChannelPermissionOverride (channelId, overwriteId, reason) {
951
- await rest.delete(rest.routes.channels.overwrite(channelId, overwriteId), reason ? {
988
+ await rest.delete(rest.routes.channels.overwrite(channelId, overwriteId), {
952
989
  reason
953
- } : undefined);
990
+ });
954
991
  },
955
992
  async deleteEmoji (guildId, id, reason) {
956
993
  await rest.delete(rest.routes.guilds.emoji(guildId, id), {
@@ -970,9 +1007,9 @@ export function createRestManager(options) {
970
1007
  await rest.delete(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId));
971
1008
  },
972
1009
  async deleteGuildSticker (guildId, stickerId, reason) {
973
- await rest.delete(rest.routes.guilds.sticker(guildId, stickerId), reason ? {
1010
+ await rest.delete(rest.routes.guilds.sticker(guildId, stickerId), {
974
1011
  reason
975
- } : undefined);
1012
+ });
976
1013
  },
977
1014
  async deleteGuildTemplate (guildId, templateCode) {
978
1015
  await rest.delete(rest.routes.guilds.templates.guild(guildId, templateCode));
@@ -981,9 +1018,9 @@ export function createRestManager(options) {
981
1018
  await rest.delete(rest.routes.guilds.integration(guildId, integrationId));
982
1019
  },
983
1020
  async deleteInvite (inviteCode, reason) {
984
- await rest.delete(rest.routes.guilds.invite(inviteCode), reason ? {
1021
+ await rest.delete(rest.routes.guilds.invite(inviteCode), {
985
1022
  reason
986
- } : undefined);
1023
+ });
987
1024
  },
988
1025
  async deleteMessage (channelId, messageId, reason) {
989
1026
  await rest.delete(rest.routes.channels.message(channelId, messageId), {
@@ -992,7 +1029,9 @@ export function createRestManager(options) {
992
1029
  },
993
1030
  async deleteMessages (channelId, messageIds, reason) {
994
1031
  await rest.post(rest.routes.channels.bulk(channelId), {
995
- messages: messageIds.slice(0, 100).map((id)=>id.toString()),
1032
+ body: {
1033
+ messages: messageIds.slice(0, 100).map((id)=>id.toString())
1034
+ },
996
1035
  reason
997
1036
  });
998
1037
  },
@@ -1017,9 +1056,9 @@ export function createRestManager(options) {
1017
1056
  await rest.delete(rest.routes.guilds.events.event(guildId, eventId));
1018
1057
  },
1019
1058
  async deleteStageInstance (channelId, reason) {
1020
- await rest.delete(rest.routes.channels.stage(channelId), reason ? {
1059
+ await rest.delete(rest.routes.channels.stage(channelId), {
1021
1060
  reason
1022
- } : undefined);
1061
+ });
1023
1062
  },
1024
1063
  async deleteUserReaction (channelId, messageId, userId, reaction) {
1025
1064
  reaction = processReactionString(reaction);
@@ -1036,122 +1075,177 @@ export function createRestManager(options) {
1036
1075
  async deleteWebhookWithToken (webhookId, token) {
1037
1076
  await rest.delete(rest.routes.webhooks.webhook(webhookId, token));
1038
1077
  },
1039
- async editApplicationCommandPermissions (guildId, commandId, bearerToken, options) {
1078
+ async editApplicationCommandPermissions (guildId, commandId, bearerToken, permissions) {
1040
1079
  return await rest.put(rest.routes.interactions.commands.permission(rest.applicationId, guildId, commandId), {
1041
- permissions: options
1042
- }, {
1080
+ body: {
1081
+ permissions
1082
+ },
1043
1083
  headers: {
1044
1084
  authorization: `Bearer ${bearerToken}`
1045
1085
  }
1046
1086
  });
1047
1087
  },
1048
- async editAutomodRule (guildId, ruleId, options) {
1049
- return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), options);
1088
+ async editAutomodRule (guildId, ruleId, body) {
1089
+ return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), {
1090
+ body
1091
+ });
1050
1092
  },
1051
1093
  async editBotProfile (options) {
1052
1094
  const avatar = options?.botAvatarURL ? await urlToBase64(options?.botAvatarURL) : options?.botAvatarURL;
1053
1095
  return await rest.patch(rest.routes.userBot(), {
1054
- username: options.username?.trim(),
1055
- avatar
1096
+ body: {
1097
+ username: options.username?.trim(),
1098
+ avatar
1099
+ }
1056
1100
  });
1057
1101
  },
1058
- async editChannel (channelId, options) {
1059
- return await rest.patch(rest.routes.channels.channel(channelId), options);
1102
+ async editChannel (channelId, body) {
1103
+ return await rest.patch(rest.routes.channels.channel(channelId), {
1104
+ body
1105
+ });
1060
1106
  },
1061
- async editChannelPermissionOverrides (channelId, options) {
1062
- await rest.put(rest.routes.channels.overwrite(channelId, options.id), options);
1107
+ async editChannelPermissionOverrides (channelId, body) {
1108
+ await rest.put(rest.routes.channels.overwrite(channelId, body.id), {
1109
+ body
1110
+ });
1063
1111
  },
1064
- async editChannelPositions (guildId, channelPositions) {
1065
- await rest.patch(rest.routes.guilds.channels(guildId), channelPositions);
1112
+ async editChannelPositions (guildId, body) {
1113
+ await rest.patch(rest.routes.guilds.channels(guildId), {
1114
+ body
1115
+ });
1066
1116
  },
1067
- async editEmoji (guildId, id, options) {
1068
- return await rest.patch(rest.routes.guilds.emoji(guildId, id), options);
1117
+ async editEmoji (guildId, id, body) {
1118
+ return await rest.patch(rest.routes.guilds.emoji(guildId, id), {
1119
+ body
1120
+ });
1069
1121
  },
1070
- async editFollowupMessage (token, messageId, options) {
1071
- return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), options);
1122
+ async editFollowupMessage (token, messageId, body) {
1123
+ return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
1124
+ body
1125
+ });
1072
1126
  },
1073
- async editGlobalApplicationCommand (commandId, options) {
1074
- return await rest.patch(rest.routes.interactions.commands.command(rest.applicationId, commandId), options);
1127
+ async editGlobalApplicationCommand (commandId, body) {
1128
+ return await rest.patch(rest.routes.interactions.commands.command(rest.applicationId, commandId), {
1129
+ body
1130
+ });
1075
1131
  },
1076
- async editGuild (guildId, options) {
1077
- return await rest.patch(rest.routes.guilds.guild(guildId), options);
1132
+ async editGuild (guildId, body) {
1133
+ return await rest.patch(rest.routes.guilds.guild(guildId), {
1134
+ body
1135
+ });
1078
1136
  },
1079
- async editGuildApplicationCommand (commandId, guildId, options) {
1080
- return await rest.patch(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId), options);
1137
+ async editGuildApplicationCommand (commandId, guildId, body) {
1138
+ return await rest.patch(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId), {
1139
+ body
1140
+ });
1081
1141
  },
1082
1142
  async editGuildMfaLevel (guildId, mfaLevel, reason) {
1083
1143
  await rest.post(rest.routes.guilds.mfa(guildId), {
1084
- level: mfaLevel,
1144
+ body: {
1145
+ level: mfaLevel
1146
+ },
1085
1147
  reason
1086
1148
  });
1087
1149
  },
1088
- async editGuildSticker (guildId, stickerId, options) {
1089
- return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), options);
1150
+ async editGuildSticker (guildId, stickerId, body) {
1151
+ return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), {
1152
+ body
1153
+ });
1090
1154
  },
1091
- async editGuildTemplate (guildId, templateCode, options) {
1092
- return await rest.patch(rest.routes.guilds.templates.guild(guildId, templateCode), options);
1155
+ async editGuildTemplate (guildId, templateCode, body) {
1156
+ return await rest.patch(rest.routes.guilds.templates.guild(guildId, templateCode), {
1157
+ body
1158
+ });
1093
1159
  },
1094
- async editMessage (channelId, messageId, options) {
1095
- return await rest.patch(rest.routes.channels.message(channelId, messageId), options);
1160
+ async editMessage (channelId, messageId, body) {
1161
+ return await rest.patch(rest.routes.channels.message(channelId, messageId), {
1162
+ body
1163
+ });
1096
1164
  },
1097
- async editOriginalInteractionResponse (token, options) {
1098
- return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token), options);
1165
+ async editOriginalInteractionResponse (token, body) {
1166
+ return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token), {
1167
+ body
1168
+ });
1099
1169
  },
1100
1170
  async editOriginalWebhookMessage (webhookId, token, options) {
1101
1171
  return await rest.patch(rest.routes.webhooks.original(webhookId, token, options), {
1102
- type: InteractionResponseTypes.UpdateMessage,
1103
- data: options
1172
+ body: {
1173
+ type: InteractionResponseTypes.UpdateMessage,
1174
+ data: options
1175
+ }
1104
1176
  });
1105
1177
  },
1106
1178
  async editOwnVoiceState (guildId, options) {
1107
1179
  await rest.patch(rest.routes.guilds.voice(guildId), {
1108
- channel_id: options.channelId,
1109
- suppress: options.suppress,
1110
- request_to_speak_timestamp: options.requestToSpeakTimestamp ? new Date(options.requestToSpeakTimestamp).toISOString() : options.requestToSpeakTimestamp
1180
+ body: {
1181
+ ...options,
1182
+ request_to_speak_timestamp: options.requestToSpeakTimestamp ? new Date(options.requestToSpeakTimestamp).toISOString() : options.requestToSpeakTimestamp
1183
+ }
1111
1184
  });
1112
1185
  },
1113
- async editScheduledEvent (guildId, eventId, options) {
1114
- return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), options);
1186
+ async editScheduledEvent (guildId, eventId, body) {
1187
+ return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), {
1188
+ body
1189
+ });
1115
1190
  },
1116
- async editRole (guildId, roleId, options) {
1117
- return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), options);
1191
+ async editRole (guildId, roleId, body) {
1192
+ return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), {
1193
+ body
1194
+ });
1118
1195
  },
1119
- async editRolePositions (guildId, options) {
1120
- return await rest.patch(rest.routes.guilds.roles.all(guildId), options);
1196
+ async editRolePositions (guildId, body) {
1197
+ return await rest.patch(rest.routes.guilds.roles.all(guildId), {
1198
+ body
1199
+ });
1121
1200
  },
1122
- async editStageInstance (channelId, data) {
1201
+ async editStageInstance (channelId, topic, reason) {
1123
1202
  return await rest.patch(rest.routes.channels.stage(channelId), {
1124
- topic: data.topic
1203
+ body: {
1204
+ topic
1205
+ },
1206
+ reason
1125
1207
  });
1126
1208
  },
1127
1209
  async editUserVoiceState (guildId, options) {
1128
1210
  await rest.patch(rest.routes.guilds.voice(guildId, options.userId), {
1129
- channel_id: options.channelId,
1130
- suppress: options.suppress,
1131
- user_id: options.userId
1211
+ body: options
1132
1212
  });
1133
1213
  },
1134
- async editWebhook (webhookId, options) {
1135
- return await rest.patch(rest.routes.webhooks.id(webhookId), options);
1214
+ async editWebhook (webhookId, body) {
1215
+ return await rest.patch(rest.routes.webhooks.id(webhookId), {
1216
+ body
1217
+ });
1136
1218
  },
1137
1219
  async editWebhookMessage (webhookId, token, messageId, options) {
1138
- return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options), options);
1220
+ return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options), {
1221
+ body: options
1222
+ });
1139
1223
  },
1140
- async editWebhookWithToken (webhookId, token, options) {
1141
- return await rest.patch(rest.routes.webhooks.webhook(webhookId, token), options);
1224
+ async editWebhookWithToken (webhookId, token, body) {
1225
+ return await rest.patch(rest.routes.webhooks.webhook(webhookId, token), {
1226
+ body
1227
+ });
1142
1228
  },
1143
- async editWelcomeScreen (guildId, options) {
1144
- return await rest.patch(rest.routes.guilds.welcome(guildId), options);
1229
+ async editWelcomeScreen (guildId, body) {
1230
+ return await rest.patch(rest.routes.guilds.welcome(guildId), {
1231
+ body
1232
+ });
1145
1233
  },
1146
- async editWidgetSettings (guildId, options) {
1147
- return await rest.patch(rest.routes.guilds.widget(guildId), options);
1234
+ async editWidgetSettings (guildId, body) {
1235
+ return await rest.patch(rest.routes.guilds.widget(guildId), {
1236
+ body
1237
+ });
1148
1238
  },
1149
1239
  async executeWebhook (webhookId, token, options) {
1150
- return await rest.post(rest.routes.webhooks.webhook(webhookId, token, options), options);
1240
+ return await rest.post(rest.routes.webhooks.webhook(webhookId, token, options), {
1241
+ body: options
1242
+ });
1151
1243
  },
1152
1244
  async followAnnouncement (sourceChannelId, targetChannelId) {
1153
1245
  return await rest.post(rest.routes.channels.follow(sourceChannelId), {
1154
- webhook_channel_id: targetChannelId
1246
+ body: {
1247
+ webhook_channel_id: targetChannelId
1248
+ }
1155
1249
  });
1156
1250
  },
1157
1251
  async getActiveThreads (guildId) {
@@ -1198,7 +1292,9 @@ export function createRestManager(options) {
1198
1292
  },
1199
1293
  async getDmChannel (userId) {
1200
1294
  return await rest.post(rest.routes.channels.dm(), {
1201
- recipient_id: userId.toString()
1295
+ body: {
1296
+ recipient_id: userId
1297
+ }
1202
1298
  });
1203
1299
  },
1204
1300
  async getEmoji (guildId, emojiId) {
@@ -1361,12 +1457,15 @@ export function createRestManager(options) {
1361
1457
  async removeThreadMember (channelId, userId) {
1362
1458
  await rest.delete(rest.routes.channels.threads.user(channelId, userId));
1363
1459
  },
1460
+ // TODO: why that
1364
1461
  async sendFollowupMessage (token, options) {
1365
1462
  return await new Promise((resolve, reject)=>{
1366
1463
  rest.sendRequest({
1367
1464
  url: rest.routes.webhooks.webhook(rest.applicationId, token),
1368
1465
  method: 'POST',
1369
- body: options,
1466
+ options: {
1467
+ body: options
1468
+ },
1370
1469
  retryCount: 0,
1371
1470
  retryRequest: async function(options) {
1372
1471
  // TODO: should change to reprocess queue item
@@ -1379,12 +1478,15 @@ export function createRestManager(options) {
1379
1478
  });
1380
1479
  });
1381
1480
  },
1481
+ // TODO: why that
1382
1482
  async sendInteractionResponse (interactionId, token, options) {
1383
1483
  await new Promise((resolve, reject)=>{
1384
1484
  rest.sendRequest({
1385
1485
  url: rest.routes.interactions.responses.callback(interactionId, token),
1386
1486
  method: 'POST',
1387
- body: options,
1487
+ options: {
1488
+ body: options
1489
+ },
1388
1490
  retryCount: 0,
1389
1491
  retryRequest: async function(options) {
1390
1492
  // TODO: should change to reprocess queue item
@@ -1397,26 +1499,38 @@ export function createRestManager(options) {
1397
1499
  });
1398
1500
  });
1399
1501
  },
1400
- async sendMessage (channelId, options) {
1401
- return await rest.post(rest.routes.channels.messages(channelId), options);
1502
+ async sendMessage (channelId, body) {
1503
+ return await rest.post(rest.routes.channels.messages(channelId), {
1504
+ body
1505
+ });
1402
1506
  },
1403
- async startThreadWithMessage (channelId, messageId, options) {
1404
- return await rest.post(rest.routes.channels.threads.message(channelId, messageId), options);
1507
+ async startThreadWithMessage (channelId, messageId, body) {
1508
+ return await rest.post(rest.routes.channels.threads.message(channelId, messageId), {
1509
+ body
1510
+ });
1405
1511
  },
1406
- async startThreadWithoutMessage (channelId, options) {
1407
- return await rest.post(rest.routes.channels.threads.all(channelId), options);
1512
+ async startThreadWithoutMessage (channelId, body) {
1513
+ return await rest.post(rest.routes.channels.threads.all(channelId), {
1514
+ body
1515
+ });
1408
1516
  },
1409
1517
  async syncGuildTemplate (guildId) {
1410
1518
  return await rest.put(rest.routes.guilds.templates.all(guildId));
1411
1519
  },
1412
- async banMember (guildId, userId, options) {
1413
- await rest.put(rest.routes.guilds.members.ban(guildId, userId), options);
1520
+ async banMember (guildId, userId, body) {
1521
+ await rest.put(rest.routes.guilds.members.ban(guildId, userId), {
1522
+ body
1523
+ });
1414
1524
  },
1415
- async editBotMember (guildId, options) {
1416
- return await rest.patch(rest.routes.guilds.members.bot(guildId), options);
1525
+ async editBotMember (guildId, body) {
1526
+ return await rest.patch(rest.routes.guilds.members.bot(guildId), {
1527
+ body
1528
+ });
1417
1529
  },
1418
- async editMember (guildId, userId, options) {
1419
- return await rest.patch(rest.routes.guilds.members.member(guildId, userId), options);
1530
+ async editMember (guildId, userId, body) {
1531
+ return await rest.patch(rest.routes.guilds.members.member(guildId, userId), {
1532
+ body
1533
+ });
1420
1534
  },
1421
1535
  async getMember (guildId, userId) {
1422
1536
  return await rest.get(rest.routes.guilds.members.member(guildId, userId));
@@ -1430,12 +1544,14 @@ export function createRestManager(options) {
1430
1544
  });
1431
1545
  },
1432
1546
  async pinMessage (channelId, messageId, reason) {
1433
- await rest.put(rest.routes.channels.pin(channelId, messageId), reason ? {
1547
+ await rest.put(rest.routes.channels.pin(channelId, messageId), {
1434
1548
  reason
1435
- } : undefined);
1549
+ });
1436
1550
  },
1437
- async pruneMembers (guildId, options) {
1438
- return await rest.post(rest.routes.guilds.members.prune(guildId), options);
1551
+ async pruneMembers (guildId, body) {
1552
+ return await rest.post(rest.routes.guilds.members.prune(guildId), {
1553
+ body
1554
+ });
1439
1555
  },
1440
1556
  async searchMembers (guildId, query, options) {
1441
1557
  return await rest.get(rest.routes.guilds.members.search(guildId, query, options));
@@ -1444,18 +1560,22 @@ export function createRestManager(options) {
1444
1560
  await rest.delete(rest.routes.guilds.members.ban(guildId, userId));
1445
1561
  },
1446
1562
  async unpinMessage (channelId, messageId, reason) {
1447
- await rest.delete(rest.routes.channels.pin(channelId, messageId), reason ? {
1563
+ await rest.delete(rest.routes.channels.pin(channelId, messageId), {
1448
1564
  reason
1449
- } : undefined);
1565
+ });
1450
1566
  },
1451
1567
  async triggerTypingIndicator (channelId) {
1452
1568
  await rest.post(rest.routes.channels.typing(channelId));
1453
1569
  },
1454
- async upsertGlobalApplicationCommands (commands) {
1455
- return await rest.put(rest.routes.interactions.commands.commands(rest.applicationId), commands);
1570
+ async upsertGlobalApplicationCommands (body) {
1571
+ return await rest.put(rest.routes.interactions.commands.commands(rest.applicationId), {
1572
+ body
1573
+ });
1456
1574
  },
1457
- async upsertGuildApplicationCommands (guildId, commands) {
1458
- return await rest.put(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), commands);
1575
+ async upsertGuildApplicationCommands (guildId, body) {
1576
+ return await rest.put(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
1577
+ body
1578
+ });
1459
1579
  }
1460
1580
  };
1461
1581
  return rest;