@discordeno/rest 19.0.0-next.bb85624 → 19.0.0-next.bcfeb5b
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.d.ts.map +1 -1
- package/dist/manager.js +411 -250
- package/dist/manager.js.map +1 -1
- package/dist/queue.js +10 -10
- package/dist/queue.js.map +1 -1
- package/dist/types.d.ts +204 -198
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +17 -16
package/dist/manager.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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,
|
|
2
|
+
import { calculateBits, camelize, camelToSnakeCase, delay, encode, getBotIdFromToken, isGetMessagesAfter, isGetMessagesAround, isGetMessagesBefore, isGetMessagesLimit, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
|
|
3
|
+
import fetch from 'node-fetch';
|
|
3
4
|
import { createInvalidRequestBucket } from './invalidBucket.js';
|
|
4
5
|
import { Queue } from './queue.js';
|
|
5
6
|
// TODO: make dynamic based on package.json file
|
|
@@ -11,7 +12,7 @@ export function createRestManager(options) {
|
|
|
11
12
|
token: options.token,
|
|
12
13
|
applicationId: options.applicationId ? BigInt(options.applicationId) : getBotIdFromToken(options.token),
|
|
13
14
|
version: options.version ?? 10,
|
|
14
|
-
baseUrl: options.baseUrl ?? 'https://discord.com/api',
|
|
15
|
+
baseUrl: options.proxy?.baseUrl ?? 'https://discord.com/api',
|
|
15
16
|
maxRetryCount: Infinity,
|
|
16
17
|
globallyRateLimited: false,
|
|
17
18
|
processingRateLimitedPaths: false,
|
|
@@ -19,6 +20,7 @@ export function createRestManager(options) {
|
|
|
19
20
|
queues: new Map(),
|
|
20
21
|
rateLimitedPaths: new Map(),
|
|
21
22
|
invalidBucket: createInvalidRequestBucket({}),
|
|
23
|
+
authorization: options.proxy?.authorization,
|
|
22
24
|
routes: {
|
|
23
25
|
webhooks: {
|
|
24
26
|
id: (webhookId)=>{
|
|
@@ -216,6 +218,8 @@ export function createRestManager(options) {
|
|
|
216
218
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
217
219
|
if (options.before) url += `&before=${options.before}`;
|
|
218
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
|
|
219
223
|
if (options.limit) url += `&limit=${options.limit}`;
|
|
220
224
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
221
225
|
if (options.userId) url += `&user_id=${options.userId}`;
|
|
@@ -541,56 +545,47 @@ export function createRestManager(options) {
|
|
|
541
545
|
if (typeof obj === 'bigint') return obj.toString();
|
|
542
546
|
return obj;
|
|
543
547
|
},
|
|
544
|
-
|
|
548
|
+
createRequestBody (method, options) {
|
|
545
549
|
const headers = {
|
|
546
550
|
'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`
|
|
547
551
|
};
|
|
548
|
-
if (!options
|
|
549
|
-
// SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
|
|
550
|
-
if (options.headers) {
|
|
551
|
-
for(const key in options.headers){
|
|
552
|
-
headers[key.toLowerCase()] = options.headers[key];
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
// GET METHODS SHOULD NOT HAVE A BODY
|
|
556
|
-
if (options.method === 'GET') {
|
|
557
|
-
options.body = undefined;
|
|
558
|
-
}
|
|
552
|
+
if (!options?.unauthorized) headers.authorization = `Bot ${rest.token}`;
|
|
559
553
|
// IF A REASON IS PROVIDED ENCODE IT IN HEADERS
|
|
560
|
-
if (options
|
|
561
|
-
headers['
|
|
562
|
-
options.body.reason = undefined;
|
|
554
|
+
if (options?.reason !== undefined) {
|
|
555
|
+
headers['x-audit-log-reason'] = encodeURIComponent(options?.reason);
|
|
563
556
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
} else
|
|
584
|
-
|
|
585
|
-
'
|
|
586
|
-
].includes(options.method)) {
|
|
587
|
-
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?.files !== undefined) {
|
|
562
|
+
const form = new FormData();
|
|
563
|
+
for(let i = 0; i < options.files.length; ++i){
|
|
564
|
+
form.append(`file${i}`, options.files[i].blob, options.files[i].name);
|
|
565
|
+
}
|
|
566
|
+
form.append('payload_json', JSON.stringify({
|
|
567
|
+
...options.body,
|
|
568
|
+
files: undefined
|
|
569
|
+
}));
|
|
570
|
+
body = form;
|
|
571
|
+
// No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
|
|
572
|
+
} else if (options?.body !== undefined) {
|
|
573
|
+
if (options.body instanceof FormData) {
|
|
574
|
+
body = options.body;
|
|
575
|
+
// No need to set the `content-type` header since `fetch` does that automatically for us when we use a `FormData` object.
|
|
576
|
+
} else {
|
|
577
|
+
body = JSON.stringify(rest.changeToDiscordFormat(options.body));
|
|
578
|
+
headers['content-type'] = `application/json`;
|
|
588
579
|
}
|
|
589
580
|
}
|
|
581
|
+
// SOMETIMES SPECIAL HEADERS (E.G. CUSTOM AUTHORIZATION) NEED TO BE USED
|
|
582
|
+
if (options?.headers) {
|
|
583
|
+
Object.assign(headers, options.headers);
|
|
584
|
+
}
|
|
590
585
|
return {
|
|
586
|
+
body,
|
|
591
587
|
headers,
|
|
592
|
-
|
|
593
|
-
method: options.method
|
|
588
|
+
method
|
|
594
589
|
};
|
|
595
590
|
},
|
|
596
591
|
processRateLimitedPaths () {
|
|
@@ -655,8 +650,8 @@ export function createRestManager(options) {
|
|
|
655
650
|
}
|
|
656
651
|
// IF THERE IS NO REMAINING GLOBAL LIMIT, MARK IT RATE LIMITED GLOBALLY
|
|
657
652
|
if (global) {
|
|
658
|
-
const
|
|
659
|
-
const globalReset = Date.now() + Number(
|
|
653
|
+
const retryAfter = headers.get('retry-after');
|
|
654
|
+
const globalReset = Date.now() + Number(retryAfter) * 1000;
|
|
660
655
|
// rest.debug(
|
|
661
656
|
// `[REST = Globally Rate Limited] URL: ${url} | Global Rest: ${globalReset}`
|
|
662
657
|
// )
|
|
@@ -685,12 +680,7 @@ export function createRestManager(options) {
|
|
|
685
680
|
},
|
|
686
681
|
async sendRequest (options) {
|
|
687
682
|
const url = options.url.startsWith('https://') ? options.url : `${rest.baseUrl}/v${rest.version}${options.url}`;
|
|
688
|
-
const payload = rest.
|
|
689
|
-
method: options.method,
|
|
690
|
-
url: options.url,
|
|
691
|
-
body: options.body,
|
|
692
|
-
...options.options
|
|
693
|
-
});
|
|
683
|
+
const payload = rest.createRequestBody(options.method, options.requestBodyOptions);
|
|
694
684
|
logger.debug(`sending request to ${url}`, 'with payload:', {
|
|
695
685
|
...payload,
|
|
696
686
|
headers: {
|
|
@@ -712,11 +702,12 @@ export function createRestManager(options) {
|
|
|
712
702
|
logger.debug(`Request to ${url} exceeded the maximum allowed retries.`, 'with payload:', payload);
|
|
713
703
|
// rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`)
|
|
714
704
|
// Remove item from queue to prevent retry
|
|
715
|
-
|
|
705
|
+
options.reject({
|
|
716
706
|
ok: false,
|
|
717
707
|
status: response.status,
|
|
718
708
|
error: 'The options was rate limited and it maxed out the retries limit.'
|
|
719
709
|
});
|
|
710
|
+
return;
|
|
720
711
|
}
|
|
721
712
|
// Rate limited, add back to queue
|
|
722
713
|
rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get('X-RateLimit-Scope') === 'shared');
|
|
@@ -726,39 +717,42 @@ export function createRestManager(options) {
|
|
|
726
717
|
await response.json();
|
|
727
718
|
return await options.retryRequest?.(options);
|
|
728
719
|
}
|
|
729
|
-
|
|
720
|
+
options.reject({
|
|
730
721
|
ok: false,
|
|
731
722
|
status: response.status,
|
|
732
723
|
body: JSON.stringify(await response.json())
|
|
733
724
|
});
|
|
725
|
+
return;
|
|
734
726
|
}
|
|
735
727
|
const is204 = response.status === 204;
|
|
736
728
|
const json = is204 ? undefined : await response.json();
|
|
737
729
|
// Discord sometimes sends no response with 204 code
|
|
738
|
-
|
|
730
|
+
options.resolve({
|
|
739
731
|
ok: true,
|
|
740
732
|
status: response.status,
|
|
741
733
|
body: JSON.stringify(json)
|
|
742
734
|
});
|
|
743
735
|
},
|
|
744
|
-
// Credits: github.com/abalabahaha/eris lib/rest/RequestHandler.js#L397
|
|
745
|
-
// Modified for our use-case
|
|
746
736
|
simplifyUrl (url, method) {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
737
|
+
const parts = url.split('/');
|
|
738
|
+
const secondLastPart = parts[parts.length - 2];
|
|
739
|
+
if (secondLastPart === 'channels' || secondLastPart === 'guilds') {
|
|
740
|
+
return url;
|
|
741
|
+
}
|
|
742
|
+
if (secondLastPart === 'reactions' || parts[parts.length - 1] === '@me') {
|
|
743
|
+
parts.splice(-2);
|
|
744
|
+
parts.push('reactions');
|
|
745
|
+
} else {
|
|
746
|
+
parts.splice(-1);
|
|
747
|
+
parts.push('x');
|
|
756
748
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
route = method + route;
|
|
749
|
+
if (parts[parts.length - 3] === 'reactions') {
|
|
750
|
+
parts.splice(-2);
|
|
760
751
|
}
|
|
761
|
-
|
|
752
|
+
if (method === 'DELETE' && secondLastPart === 'messages') {
|
|
753
|
+
return `D${parts.join('/')}`;
|
|
754
|
+
}
|
|
755
|
+
return parts.join('/');
|
|
762
756
|
},
|
|
763
757
|
processRequest (request) {
|
|
764
758
|
const route = request.url.substring(request.url.indexOf('api/'));
|
|
@@ -785,45 +779,85 @@ export function createRestManager(options) {
|
|
|
785
779
|
rest.queues.set(url, bucketQueue);
|
|
786
780
|
}
|
|
787
781
|
},
|
|
788
|
-
async makeRequest (method, url,
|
|
782
|
+
async makeRequest (method, url, options) {
|
|
783
|
+
if (!rest.baseUrl.startsWith('https://discord.com') && url[0] === '/') {
|
|
784
|
+
// Special handling for sending blobs across http to proxy
|
|
785
|
+
// TODO: fix this hacky handling
|
|
786
|
+
if (!(options?.body instanceof FormData) && !Array.isArray(options?.body) && options?.body?.file) {
|
|
787
|
+
if (!Array.isArray(options.body.file)) {
|
|
788
|
+
options.body.file = [
|
|
789
|
+
options.body.file
|
|
790
|
+
];
|
|
791
|
+
}
|
|
792
|
+
// convert blobs to string before sending to proxy
|
|
793
|
+
options.body.file = await Promise.all(options.body.file.map(async (f)=>{
|
|
794
|
+
const url = encode(await f.blob.arrayBuffer());
|
|
795
|
+
return {
|
|
796
|
+
name: f.name,
|
|
797
|
+
blob: `data:${f.blob.type};base64,${url}`
|
|
798
|
+
};
|
|
799
|
+
}));
|
|
800
|
+
}
|
|
801
|
+
const headers = {
|
|
802
|
+
Authorization: rest.authorization ?? ''
|
|
803
|
+
};
|
|
804
|
+
if (options?.body) {
|
|
805
|
+
headers['Content-Type'] = 'application/json';
|
|
806
|
+
}
|
|
807
|
+
const result = await fetch(`${rest.baseUrl}${url}`, {
|
|
808
|
+
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
809
|
+
headers,
|
|
810
|
+
method
|
|
811
|
+
});
|
|
812
|
+
if (!result.ok) {
|
|
813
|
+
const err = await result.json().catch(()=>{});
|
|
814
|
+
// Legacy Handling to not break old code or when body is missing
|
|
815
|
+
if (!err?.body) throw new Error(`Error: ${err.message ?? result.statusText}`);
|
|
816
|
+
throw new Error(JSON.stringify(err));
|
|
817
|
+
}
|
|
818
|
+
return result.status !== 204 ? await result.json() : undefined;
|
|
819
|
+
}
|
|
789
820
|
return await new Promise((resolve, reject)=>{
|
|
790
821
|
const payload = {
|
|
791
822
|
url,
|
|
792
823
|
method,
|
|
793
|
-
|
|
824
|
+
requestBodyOptions: options,
|
|
794
825
|
retryCount: 0,
|
|
795
|
-
retryRequest: async function(
|
|
826
|
+
retryRequest: async function(payload) {
|
|
796
827
|
rest.processRequest(payload);
|
|
797
828
|
},
|
|
798
|
-
resolve: (data)=>
|
|
799
|
-
|
|
800
|
-
|
|
829
|
+
resolve: (data)=>{
|
|
830
|
+
resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
|
|
831
|
+
},
|
|
832
|
+
reject
|
|
801
833
|
};
|
|
802
834
|
rest.processRequest(payload);
|
|
803
835
|
});
|
|
804
836
|
},
|
|
805
|
-
async get (url) {
|
|
806
|
-
return camelize(await rest.makeRequest('GET', url));
|
|
837
|
+
async get (url, options) {
|
|
838
|
+
return camelize(await rest.makeRequest('GET', url, options));
|
|
807
839
|
},
|
|
808
|
-
async post (url,
|
|
809
|
-
return camelize(await rest.makeRequest('POST', url,
|
|
840
|
+
async post (url, options) {
|
|
841
|
+
return camelize(await rest.makeRequest('POST', url, options));
|
|
810
842
|
},
|
|
811
|
-
async delete (url,
|
|
812
|
-
|
|
843
|
+
async delete (url, options) {
|
|
844
|
+
camelize(await rest.makeRequest('DELETE', url, options));
|
|
813
845
|
},
|
|
814
|
-
async patch (url,
|
|
815
|
-
return camelize(await rest.makeRequest('PATCH', url,
|
|
846
|
+
async patch (url, options) {
|
|
847
|
+
return camelize(await rest.makeRequest('PATCH', url, options));
|
|
816
848
|
},
|
|
817
|
-
async put (url,
|
|
818
|
-
return camelize(await rest.makeRequest('PUT', url,
|
|
849
|
+
async put (url, options) {
|
|
850
|
+
return camelize(await rest.makeRequest('PUT', url, options));
|
|
819
851
|
},
|
|
820
852
|
async addReaction (channelId, messageId, reaction) {
|
|
821
853
|
reaction = processReactionString(reaction);
|
|
822
|
-
|
|
854
|
+
await rest.put(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
|
|
823
855
|
},
|
|
824
856
|
async addReactions (channelId, messageId, reactions, ordered = false) {
|
|
825
857
|
if (!ordered) {
|
|
826
|
-
await Promise.all(reactions.map(async (reaction)=>
|
|
858
|
+
await Promise.all(reactions.map(async (reaction)=>{
|
|
859
|
+
await rest.addReaction(channelId, messageId, reaction);
|
|
860
|
+
}));
|
|
827
861
|
return;
|
|
828
862
|
}
|
|
829
863
|
for (const reaction of reactions){
|
|
@@ -831,283 +865,378 @@ export function createRestManager(options) {
|
|
|
831
865
|
}
|
|
832
866
|
},
|
|
833
867
|
async addRole (guildId, userId, roleId, reason) {
|
|
834
|
-
|
|
868
|
+
await rest.put(rest.routes.guilds.roles.member(guildId, userId, roleId), {
|
|
835
869
|
reason
|
|
836
870
|
});
|
|
837
871
|
},
|
|
838
872
|
async addThreadMember (channelId, userId) {
|
|
839
|
-
|
|
873
|
+
await rest.put(rest.routes.channels.threads.user(channelId, userId));
|
|
840
874
|
},
|
|
841
|
-
async createAutomodRule (guildId,
|
|
842
|
-
return await rest.post(rest.routes.guilds.automod.rules(guildId),
|
|
875
|
+
async createAutomodRule (guildId, body) {
|
|
876
|
+
return await rest.post(rest.routes.guilds.automod.rules(guildId), {
|
|
877
|
+
body
|
|
878
|
+
});
|
|
843
879
|
},
|
|
844
|
-
async createChannel (guildId,
|
|
845
|
-
return await rest.post(rest.routes.guilds.channels(guildId),
|
|
880
|
+
async createChannel (guildId, body) {
|
|
881
|
+
return await rest.post(rest.routes.guilds.channels(guildId), {
|
|
882
|
+
body
|
|
883
|
+
});
|
|
846
884
|
},
|
|
847
|
-
async createEmoji (guildId,
|
|
848
|
-
return await rest.post(rest.routes.guilds.emojis(guildId),
|
|
885
|
+
async createEmoji (guildId, body) {
|
|
886
|
+
return await rest.post(rest.routes.guilds.emojis(guildId), {
|
|
887
|
+
body
|
|
888
|
+
});
|
|
849
889
|
},
|
|
850
|
-
async createGlobalApplicationCommand (
|
|
851
|
-
return await rest.post(rest.routes.interactions.commands.commands(rest.applicationId),
|
|
890
|
+
async createGlobalApplicationCommand (body) {
|
|
891
|
+
return await rest.post(rest.routes.interactions.commands.commands(rest.applicationId), {
|
|
892
|
+
body
|
|
893
|
+
});
|
|
852
894
|
},
|
|
853
|
-
async createGuild (
|
|
854
|
-
return await rest.post(rest.routes.guilds.all(),
|
|
895
|
+
async createGuild (body) {
|
|
896
|
+
return await rest.post(rest.routes.guilds.all(), {
|
|
897
|
+
body
|
|
898
|
+
});
|
|
855
899
|
},
|
|
856
|
-
async createGuildApplicationCommand (
|
|
857
|
-
return await rest.post(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId),
|
|
900
|
+
async createGuildApplicationCommand (body, guildId) {
|
|
901
|
+
return await rest.post(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
|
|
902
|
+
body
|
|
903
|
+
});
|
|
858
904
|
},
|
|
859
|
-
async createGuildFromTemplate (templateCode,
|
|
860
|
-
if (
|
|
861
|
-
|
|
905
|
+
async createGuildFromTemplate (templateCode, body) {
|
|
906
|
+
if (body.icon) {
|
|
907
|
+
body.icon = await urlToBase64(body.icon);
|
|
862
908
|
}
|
|
863
|
-
return await rest.post(rest.routes.guilds.templates.code(templateCode),
|
|
909
|
+
return await rest.post(rest.routes.guilds.templates.code(templateCode), {
|
|
910
|
+
body
|
|
911
|
+
});
|
|
864
912
|
},
|
|
865
913
|
async createGuildSticker (guildId, options) {
|
|
866
|
-
|
|
914
|
+
const form = new FormData();
|
|
915
|
+
form.append('file', options.file.blob, options.file.name);
|
|
916
|
+
form.append('name', options.name);
|
|
917
|
+
form.append('description', options.description);
|
|
918
|
+
form.append('tags', options.tags);
|
|
919
|
+
return await rest.post(rest.routes.guilds.stickers(guildId), {
|
|
920
|
+
body: form
|
|
921
|
+
});
|
|
867
922
|
},
|
|
868
|
-
async createGuildTemplate (guildId,
|
|
869
|
-
return await rest.post(rest.routes.guilds.templates.all(guildId),
|
|
923
|
+
async createGuildTemplate (guildId, body) {
|
|
924
|
+
return await rest.post(rest.routes.guilds.templates.all(guildId), {
|
|
925
|
+
body
|
|
926
|
+
});
|
|
870
927
|
},
|
|
871
|
-
async createForumThread (channelId,
|
|
872
|
-
return await rest.post(rest.routes.channels.forum(channelId),
|
|
928
|
+
async createForumThread (channelId, body) {
|
|
929
|
+
return await rest.post(rest.routes.channels.forum(channelId), {
|
|
930
|
+
body,
|
|
931
|
+
files: body.files
|
|
932
|
+
});
|
|
873
933
|
},
|
|
874
|
-
async createInvite (channelId,
|
|
875
|
-
return await rest.post(rest.routes.channels.invites(channelId),
|
|
934
|
+
async createInvite (channelId, body = {}) {
|
|
935
|
+
return await rest.post(rest.routes.channels.invites(channelId), {
|
|
936
|
+
body
|
|
937
|
+
});
|
|
876
938
|
},
|
|
877
|
-
async createRole (guildId,
|
|
939
|
+
async createRole (guildId, body, reason) {
|
|
878
940
|
return await rest.post(rest.routes.guilds.roles.all(guildId), {
|
|
879
|
-
|
|
941
|
+
body,
|
|
880
942
|
reason
|
|
881
943
|
});
|
|
882
944
|
},
|
|
883
|
-
async createScheduledEvent (guildId,
|
|
884
|
-
return await rest.post(rest.routes.guilds.events.events(guildId),
|
|
945
|
+
async createScheduledEvent (guildId, body) {
|
|
946
|
+
return await rest.post(rest.routes.guilds.events.events(guildId), {
|
|
947
|
+
body
|
|
948
|
+
});
|
|
885
949
|
},
|
|
886
|
-
async createStageInstance (
|
|
887
|
-
return await rest.post(rest.routes.channels.stages(),
|
|
950
|
+
async createStageInstance (body) {
|
|
951
|
+
return await rest.post(rest.routes.channels.stages(), {
|
|
952
|
+
body
|
|
953
|
+
});
|
|
888
954
|
},
|
|
889
|
-
async createWebhook (channelId, options) {
|
|
955
|
+
async createWebhook (channelId, options, reason) {
|
|
890
956
|
return await rest.post(rest.routes.channels.webhooks(channelId), {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
957
|
+
body: {
|
|
958
|
+
name: options.name,
|
|
959
|
+
avatar: options.avatar ? await urlToBase64(options.avatar) : undefined
|
|
960
|
+
},
|
|
961
|
+
reason
|
|
894
962
|
});
|
|
895
963
|
},
|
|
896
964
|
async deleteAutomodRule (guildId, ruleId, reason) {
|
|
897
|
-
|
|
965
|
+
await rest.delete(rest.routes.guilds.automod.rule(guildId, ruleId), {
|
|
898
966
|
reason
|
|
899
967
|
});
|
|
900
968
|
},
|
|
901
969
|
async deleteChannel (channelId, reason) {
|
|
902
|
-
|
|
970
|
+
await rest.delete(rest.routes.channels.channel(channelId), {
|
|
903
971
|
reason
|
|
904
972
|
});
|
|
905
973
|
},
|
|
906
974
|
async deleteChannelPermissionOverride (channelId, overwriteId, reason) {
|
|
907
|
-
|
|
975
|
+
await rest.delete(rest.routes.channels.overwrite(channelId, overwriteId), {
|
|
908
976
|
reason
|
|
909
|
-
}
|
|
977
|
+
});
|
|
910
978
|
},
|
|
911
979
|
async deleteEmoji (guildId, id, reason) {
|
|
912
|
-
|
|
980
|
+
await rest.delete(rest.routes.guilds.emoji(guildId, id), {
|
|
913
981
|
reason
|
|
914
982
|
});
|
|
915
983
|
},
|
|
916
984
|
async deleteFollowupMessage (token, messageId) {
|
|
917
|
-
|
|
985
|
+
await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId));
|
|
918
986
|
},
|
|
919
987
|
async deleteGlobalApplicationCommand (commandId) {
|
|
920
|
-
|
|
988
|
+
await rest.delete(rest.routes.interactions.commands.command(rest.applicationId, commandId));
|
|
921
989
|
},
|
|
922
990
|
async deleteGuild (guildId) {
|
|
923
|
-
|
|
991
|
+
await rest.delete(rest.routes.guilds.guild(guildId));
|
|
924
992
|
},
|
|
925
993
|
async deleteGuildApplicationCommand (commandId, guildId) {
|
|
926
|
-
|
|
994
|
+
await rest.delete(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId));
|
|
927
995
|
},
|
|
928
996
|
async deleteGuildSticker (guildId, stickerId, reason) {
|
|
929
|
-
|
|
997
|
+
await rest.delete(rest.routes.guilds.sticker(guildId, stickerId), {
|
|
930
998
|
reason
|
|
931
|
-
}
|
|
999
|
+
});
|
|
932
1000
|
},
|
|
933
1001
|
async deleteGuildTemplate (guildId, templateCode) {
|
|
934
|
-
|
|
1002
|
+
await rest.delete(rest.routes.guilds.templates.guild(guildId, templateCode));
|
|
935
1003
|
},
|
|
936
1004
|
async deleteIntegration (guildId, integrationId) {
|
|
937
|
-
|
|
1005
|
+
await rest.delete(rest.routes.guilds.integration(guildId, integrationId));
|
|
938
1006
|
},
|
|
939
1007
|
async deleteInvite (inviteCode, reason) {
|
|
940
|
-
|
|
1008
|
+
await rest.delete(rest.routes.guilds.invite(inviteCode), {
|
|
941
1009
|
reason
|
|
942
|
-
}
|
|
1010
|
+
});
|
|
943
1011
|
},
|
|
944
1012
|
async deleteMessage (channelId, messageId, reason) {
|
|
945
|
-
|
|
1013
|
+
await rest.delete(rest.routes.channels.message(channelId, messageId), {
|
|
946
1014
|
reason
|
|
947
1015
|
});
|
|
948
1016
|
},
|
|
949
1017
|
async deleteMessages (channelId, messageIds, reason) {
|
|
950
|
-
|
|
951
|
-
|
|
1018
|
+
await rest.post(rest.routes.channels.bulk(channelId), {
|
|
1019
|
+
body: {
|
|
1020
|
+
messages: messageIds.slice(0, 100).map((id)=>id.toString())
|
|
1021
|
+
},
|
|
952
1022
|
reason
|
|
953
1023
|
});
|
|
954
1024
|
},
|
|
955
1025
|
async deleteOriginalInteractionResponse (token) {
|
|
956
|
-
|
|
1026
|
+
await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token));
|
|
957
1027
|
},
|
|
958
1028
|
async deleteOwnReaction (channelId, messageId, reaction) {
|
|
959
1029
|
reaction = processReactionString(reaction);
|
|
960
|
-
|
|
1030
|
+
await rest.delete(rest.routes.channels.reactions.bot(channelId, messageId, reaction));
|
|
961
1031
|
},
|
|
962
1032
|
async deleteReactionsAll (channelId, messageId) {
|
|
963
|
-
|
|
1033
|
+
await rest.delete(rest.routes.channels.reactions.all(channelId, messageId));
|
|
964
1034
|
},
|
|
965
1035
|
async deleteReactionsEmoji (channelId, messageId, reaction) {
|
|
966
1036
|
reaction = processReactionString(reaction);
|
|
967
|
-
|
|
1037
|
+
await rest.delete(rest.routes.channels.reactions.emoji(channelId, messageId, reaction));
|
|
968
1038
|
},
|
|
969
1039
|
async deleteRole (guildId, roleId) {
|
|
970
|
-
|
|
1040
|
+
await rest.delete(rest.routes.guilds.roles.one(guildId, roleId));
|
|
971
1041
|
},
|
|
972
1042
|
async deleteScheduledEvent (guildId, eventId) {
|
|
973
|
-
|
|
1043
|
+
await rest.delete(rest.routes.guilds.events.event(guildId, eventId));
|
|
974
1044
|
},
|
|
975
1045
|
async deleteStageInstance (channelId, reason) {
|
|
976
|
-
|
|
1046
|
+
await rest.delete(rest.routes.channels.stage(channelId), {
|
|
977
1047
|
reason
|
|
978
|
-
}
|
|
1048
|
+
});
|
|
979
1049
|
},
|
|
980
1050
|
async deleteUserReaction (channelId, messageId, userId, reaction) {
|
|
981
1051
|
reaction = processReactionString(reaction);
|
|
982
|
-
|
|
1052
|
+
await rest.delete(rest.routes.channels.reactions.user(channelId, messageId, reaction, userId));
|
|
983
1053
|
},
|
|
984
1054
|
async deleteWebhook (webhookId, reason) {
|
|
985
|
-
|
|
1055
|
+
await rest.delete(rest.routes.webhooks.id(webhookId), {
|
|
986
1056
|
reason
|
|
987
1057
|
});
|
|
988
1058
|
},
|
|
989
1059
|
async deleteWebhookMessage (webhookId, token, messageId, options) {
|
|
990
|
-
|
|
1060
|
+
await rest.delete(rest.routes.webhooks.message(webhookId, token, messageId, options));
|
|
991
1061
|
},
|
|
992
1062
|
async deleteWebhookWithToken (webhookId, token) {
|
|
993
|
-
|
|
1063
|
+
await rest.delete(rest.routes.webhooks.webhook(webhookId, token));
|
|
994
1064
|
},
|
|
995
|
-
async editApplicationCommandPermissions (guildId, commandId, bearerToken,
|
|
1065
|
+
async editApplicationCommandPermissions (guildId, commandId, bearerToken, permissions) {
|
|
996
1066
|
return await rest.put(rest.routes.interactions.commands.permission(rest.applicationId, guildId, commandId), {
|
|
997
|
-
|
|
998
|
-
|
|
1067
|
+
body: {
|
|
1068
|
+
permissions
|
|
1069
|
+
},
|
|
999
1070
|
headers: {
|
|
1000
1071
|
authorization: `Bearer ${bearerToken}`
|
|
1001
1072
|
}
|
|
1002
1073
|
});
|
|
1003
1074
|
},
|
|
1004
|
-
async editAutomodRule (guildId, ruleId,
|
|
1005
|
-
return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId),
|
|
1075
|
+
async editAutomodRule (guildId, ruleId, body) {
|
|
1076
|
+
return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), {
|
|
1077
|
+
body
|
|
1078
|
+
});
|
|
1006
1079
|
},
|
|
1007
1080
|
async editBotProfile (options) {
|
|
1008
1081
|
const avatar = options?.botAvatarURL ? await urlToBase64(options?.botAvatarURL) : options?.botAvatarURL;
|
|
1009
1082
|
return await rest.patch(rest.routes.userBot(), {
|
|
1010
|
-
|
|
1011
|
-
|
|
1083
|
+
body: {
|
|
1084
|
+
username: options.username?.trim(),
|
|
1085
|
+
avatar
|
|
1086
|
+
}
|
|
1012
1087
|
});
|
|
1013
1088
|
},
|
|
1014
|
-
async editChannel (channelId,
|
|
1015
|
-
return await rest.patch(rest.routes.channels.channel(channelId),
|
|
1089
|
+
async editChannel (channelId, body) {
|
|
1090
|
+
return await rest.patch(rest.routes.channels.channel(channelId), {
|
|
1091
|
+
body
|
|
1092
|
+
});
|
|
1016
1093
|
},
|
|
1017
|
-
async editChannelPermissionOverrides (channelId,
|
|
1018
|
-
|
|
1094
|
+
async editChannelPermissionOverrides (channelId, body) {
|
|
1095
|
+
await rest.put(rest.routes.channels.overwrite(channelId, body.id), {
|
|
1096
|
+
body
|
|
1097
|
+
});
|
|
1019
1098
|
},
|
|
1020
|
-
async editChannelPositions (guildId,
|
|
1021
|
-
|
|
1099
|
+
async editChannelPositions (guildId, body) {
|
|
1100
|
+
await rest.patch(rest.routes.guilds.channels(guildId), {
|
|
1101
|
+
body
|
|
1102
|
+
});
|
|
1022
1103
|
},
|
|
1023
|
-
async editEmoji (guildId, id,
|
|
1024
|
-
return await rest.patch(rest.routes.guilds.emoji(guildId, id),
|
|
1104
|
+
async editEmoji (guildId, id, body) {
|
|
1105
|
+
return await rest.patch(rest.routes.guilds.emoji(guildId, id), {
|
|
1106
|
+
body
|
|
1107
|
+
});
|
|
1025
1108
|
},
|
|
1026
|
-
async editFollowupMessage (token, messageId,
|
|
1027
|
-
return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId),
|
|
1109
|
+
async editFollowupMessage (token, messageId, body) {
|
|
1110
|
+
return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
|
|
1111
|
+
body,
|
|
1112
|
+
files: body.files
|
|
1113
|
+
});
|
|
1028
1114
|
},
|
|
1029
|
-
async editGlobalApplicationCommand (commandId,
|
|
1030
|
-
return await rest.patch(rest.routes.interactions.commands.command(rest.applicationId, commandId),
|
|
1115
|
+
async editGlobalApplicationCommand (commandId, body) {
|
|
1116
|
+
return await rest.patch(rest.routes.interactions.commands.command(rest.applicationId, commandId), {
|
|
1117
|
+
body
|
|
1118
|
+
});
|
|
1031
1119
|
},
|
|
1032
|
-
async editGuild (guildId,
|
|
1033
|
-
return await rest.patch(rest.routes.guilds.guild(guildId),
|
|
1120
|
+
async editGuild (guildId, body) {
|
|
1121
|
+
return await rest.patch(rest.routes.guilds.guild(guildId), {
|
|
1122
|
+
body
|
|
1123
|
+
});
|
|
1034
1124
|
},
|
|
1035
|
-
async editGuildApplicationCommand (commandId, guildId,
|
|
1036
|
-
return await rest.patch(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId),
|
|
1125
|
+
async editGuildApplicationCommand (commandId, guildId, body) {
|
|
1126
|
+
return await rest.patch(rest.routes.interactions.commands.guilds.one(rest.applicationId, guildId, commandId), {
|
|
1127
|
+
body
|
|
1128
|
+
});
|
|
1037
1129
|
},
|
|
1038
1130
|
async editGuildMfaLevel (guildId, mfaLevel, reason) {
|
|
1039
|
-
|
|
1040
|
-
|
|
1131
|
+
await rest.post(rest.routes.guilds.mfa(guildId), {
|
|
1132
|
+
body: {
|
|
1133
|
+
level: mfaLevel
|
|
1134
|
+
},
|
|
1041
1135
|
reason
|
|
1042
1136
|
});
|
|
1043
1137
|
},
|
|
1044
|
-
async editGuildSticker (guildId, stickerId,
|
|
1045
|
-
return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId),
|
|
1138
|
+
async editGuildSticker (guildId, stickerId, body) {
|
|
1139
|
+
return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), {
|
|
1140
|
+
body
|
|
1141
|
+
});
|
|
1046
1142
|
},
|
|
1047
|
-
async editGuildTemplate (guildId, templateCode,
|
|
1048
|
-
return await rest.patch(rest.routes.guilds.templates.guild(guildId, templateCode),
|
|
1143
|
+
async editGuildTemplate (guildId, templateCode, body) {
|
|
1144
|
+
return await rest.patch(rest.routes.guilds.templates.guild(guildId, templateCode), {
|
|
1145
|
+
body
|
|
1146
|
+
});
|
|
1049
1147
|
},
|
|
1050
|
-
async editMessage (channelId, messageId,
|
|
1051
|
-
return await rest.patch(rest.routes.channels.message(channelId, messageId),
|
|
1148
|
+
async editMessage (channelId, messageId, body) {
|
|
1149
|
+
return await rest.patch(rest.routes.channels.message(channelId, messageId), {
|
|
1150
|
+
body
|
|
1151
|
+
});
|
|
1052
1152
|
},
|
|
1053
|
-
async editOriginalInteractionResponse (token,
|
|
1054
|
-
return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token),
|
|
1153
|
+
async editOriginalInteractionResponse (token, body) {
|
|
1154
|
+
return await rest.patch(rest.routes.interactions.responses.original(rest.applicationId, token), {
|
|
1155
|
+
body,
|
|
1156
|
+
files: body.files
|
|
1157
|
+
});
|
|
1055
1158
|
},
|
|
1056
1159
|
async editOriginalWebhookMessage (webhookId, token, options) {
|
|
1057
1160
|
return await rest.patch(rest.routes.webhooks.original(webhookId, token, options), {
|
|
1058
|
-
|
|
1059
|
-
|
|
1161
|
+
body: {
|
|
1162
|
+
type: InteractionResponseTypes.UpdateMessage,
|
|
1163
|
+
data: options
|
|
1164
|
+
},
|
|
1165
|
+
files: options.files
|
|
1060
1166
|
});
|
|
1061
1167
|
},
|
|
1062
1168
|
async editOwnVoiceState (guildId, options) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1169
|
+
await rest.patch(rest.routes.guilds.voice(guildId), {
|
|
1170
|
+
body: {
|
|
1171
|
+
...options,
|
|
1172
|
+
request_to_speak_timestamp: options.requestToSpeakTimestamp ? new Date(options.requestToSpeakTimestamp).toISOString() : options.requestToSpeakTimestamp
|
|
1173
|
+
}
|
|
1067
1174
|
});
|
|
1068
1175
|
},
|
|
1069
|
-
async editScheduledEvent (guildId, eventId,
|
|
1070
|
-
return await rest.patch(rest.routes.guilds.events.event(guildId, eventId),
|
|
1176
|
+
async editScheduledEvent (guildId, eventId, body) {
|
|
1177
|
+
return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), {
|
|
1178
|
+
body
|
|
1179
|
+
});
|
|
1071
1180
|
},
|
|
1072
|
-
async editRole (guildId, roleId,
|
|
1073
|
-
return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId),
|
|
1181
|
+
async editRole (guildId, roleId, body) {
|
|
1182
|
+
return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), {
|
|
1183
|
+
body
|
|
1184
|
+
});
|
|
1074
1185
|
},
|
|
1075
|
-
async editRolePositions (guildId,
|
|
1076
|
-
return await rest.patch(rest.routes.guilds.roles.all(guildId),
|
|
1186
|
+
async editRolePositions (guildId, body) {
|
|
1187
|
+
return await rest.patch(rest.routes.guilds.roles.all(guildId), {
|
|
1188
|
+
body
|
|
1189
|
+
});
|
|
1077
1190
|
},
|
|
1078
|
-
async editStageInstance (channelId,
|
|
1191
|
+
async editStageInstance (channelId, topic, reason) {
|
|
1079
1192
|
return await rest.patch(rest.routes.channels.stage(channelId), {
|
|
1080
|
-
|
|
1193
|
+
body: {
|
|
1194
|
+
topic
|
|
1195
|
+
},
|
|
1196
|
+
reason
|
|
1081
1197
|
});
|
|
1082
1198
|
},
|
|
1083
1199
|
async editUserVoiceState (guildId, options) {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
suppress: options.suppress,
|
|
1087
|
-
user_id: options.userId
|
|
1200
|
+
await rest.patch(rest.routes.guilds.voice(guildId, options.userId), {
|
|
1201
|
+
body: options
|
|
1088
1202
|
});
|
|
1089
1203
|
},
|
|
1090
|
-
async editWebhook (webhookId,
|
|
1091
|
-
return await rest.patch(rest.routes.webhooks.id(webhookId),
|
|
1204
|
+
async editWebhook (webhookId, body) {
|
|
1205
|
+
return await rest.patch(rest.routes.webhooks.id(webhookId), {
|
|
1206
|
+
body
|
|
1207
|
+
});
|
|
1092
1208
|
},
|
|
1093
1209
|
async editWebhookMessage (webhookId, token, messageId, options) {
|
|
1094
|
-
return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options),
|
|
1210
|
+
return await rest.patch(rest.routes.webhooks.message(webhookId, token, messageId, options), {
|
|
1211
|
+
body: options,
|
|
1212
|
+
files: options.files
|
|
1213
|
+
});
|
|
1095
1214
|
},
|
|
1096
|
-
async editWebhookWithToken (webhookId, token,
|
|
1097
|
-
return await rest.patch(rest.routes.webhooks.webhook(webhookId, token),
|
|
1215
|
+
async editWebhookWithToken (webhookId, token, body) {
|
|
1216
|
+
return await rest.patch(rest.routes.webhooks.webhook(webhookId, token), {
|
|
1217
|
+
body
|
|
1218
|
+
});
|
|
1098
1219
|
},
|
|
1099
|
-
async editWelcomeScreen (guildId,
|
|
1100
|
-
return await rest.patch(rest.routes.guilds.welcome(guildId),
|
|
1220
|
+
async editWelcomeScreen (guildId, body) {
|
|
1221
|
+
return await rest.patch(rest.routes.guilds.welcome(guildId), {
|
|
1222
|
+
body
|
|
1223
|
+
});
|
|
1101
1224
|
},
|
|
1102
|
-
async editWidgetSettings (guildId,
|
|
1103
|
-
return await rest.patch(rest.routes.guilds.widget(guildId),
|
|
1225
|
+
async editWidgetSettings (guildId, body) {
|
|
1226
|
+
return await rest.patch(rest.routes.guilds.widget(guildId), {
|
|
1227
|
+
body
|
|
1228
|
+
});
|
|
1104
1229
|
},
|
|
1105
1230
|
async executeWebhook (webhookId, token, options) {
|
|
1106
|
-
return await rest.post(rest.routes.webhooks.webhook(webhookId, token, options),
|
|
1231
|
+
return await rest.post(rest.routes.webhooks.webhook(webhookId, token, options), {
|
|
1232
|
+
body: options
|
|
1233
|
+
});
|
|
1107
1234
|
},
|
|
1108
1235
|
async followAnnouncement (sourceChannelId, targetChannelId) {
|
|
1109
1236
|
return await rest.post(rest.routes.channels.follow(sourceChannelId), {
|
|
1110
|
-
|
|
1237
|
+
body: {
|
|
1238
|
+
webhook_channel_id: targetChannelId
|
|
1239
|
+
}
|
|
1111
1240
|
});
|
|
1112
1241
|
},
|
|
1113
1242
|
async getActiveThreads (guildId) {
|
|
@@ -1154,7 +1283,9 @@ export function createRestManager(options) {
|
|
|
1154
1283
|
},
|
|
1155
1284
|
async getDmChannel (userId) {
|
|
1156
1285
|
return await rest.post(rest.routes.channels.dm(), {
|
|
1157
|
-
|
|
1286
|
+
body: {
|
|
1287
|
+
recipient_id: userId
|
|
1288
|
+
}
|
|
1158
1289
|
});
|
|
1159
1290
|
},
|
|
1160
1291
|
async getEmoji (guildId, emojiId) {
|
|
@@ -1298,77 +1429,101 @@ export function createRestManager(options) {
|
|
|
1298
1429
|
return await rest.get(rest.routes.guilds.widget(guildId));
|
|
1299
1430
|
},
|
|
1300
1431
|
async joinThread (channelId) {
|
|
1301
|
-
|
|
1432
|
+
await rest.put(rest.routes.channels.threads.me(channelId));
|
|
1302
1433
|
},
|
|
1303
1434
|
async leaveGuild (guildId) {
|
|
1304
|
-
|
|
1435
|
+
await rest.delete(rest.routes.guilds.leave(guildId));
|
|
1305
1436
|
},
|
|
1306
1437
|
async leaveThread (channelId) {
|
|
1307
|
-
|
|
1438
|
+
await rest.delete(rest.routes.channels.threads.me(channelId));
|
|
1308
1439
|
},
|
|
1309
1440
|
async publishMessage (channelId, messageId) {
|
|
1310
1441
|
return await rest.post(rest.routes.channels.crosspost(channelId, messageId));
|
|
1311
1442
|
},
|
|
1312
1443
|
async removeRole (guildId, userId, roleId, reason) {
|
|
1313
|
-
|
|
1444
|
+
await rest.delete(rest.routes.guilds.roles.member(guildId, userId, roleId), {
|
|
1314
1445
|
reason
|
|
1315
1446
|
});
|
|
1316
1447
|
},
|
|
1317
1448
|
async removeThreadMember (channelId, userId) {
|
|
1318
|
-
|
|
1449
|
+
await rest.delete(rest.routes.channels.threads.user(channelId, userId));
|
|
1319
1450
|
},
|
|
1451
|
+
// TODO: why that
|
|
1320
1452
|
async sendFollowupMessage (token, options) {
|
|
1321
1453
|
return await new Promise((resolve, reject)=>{
|
|
1322
1454
|
rest.sendRequest({
|
|
1323
1455
|
url: rest.routes.webhooks.webhook(rest.applicationId, token),
|
|
1324
1456
|
method: 'POST',
|
|
1325
|
-
|
|
1457
|
+
requestBodyOptions: {
|
|
1458
|
+
body: options,
|
|
1459
|
+
files: options.files
|
|
1460
|
+
},
|
|
1326
1461
|
retryCount: 0,
|
|
1327
1462
|
retryRequest: async function(options) {
|
|
1328
1463
|
// TODO: should change to reprocess queue item
|
|
1329
1464
|
await rest.sendRequest(options);
|
|
1330
1465
|
},
|
|
1331
|
-
resolve: (data)=>
|
|
1466
|
+
resolve: (data)=>{
|
|
1467
|
+
resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
|
|
1468
|
+
},
|
|
1332
1469
|
reject
|
|
1333
1470
|
});
|
|
1334
1471
|
});
|
|
1335
1472
|
},
|
|
1473
|
+
// TODO: why that
|
|
1336
1474
|
async sendInteractionResponse (interactionId, token, options) {
|
|
1337
|
-
|
|
1475
|
+
await new Promise((resolve, reject)=>{
|
|
1338
1476
|
rest.sendRequest({
|
|
1339
1477
|
url: rest.routes.interactions.responses.callback(interactionId, token),
|
|
1340
1478
|
method: 'POST',
|
|
1341
|
-
|
|
1479
|
+
requestBodyOptions: {
|
|
1480
|
+
body: options
|
|
1481
|
+
},
|
|
1342
1482
|
retryCount: 0,
|
|
1343
1483
|
retryRequest: async function(options) {
|
|
1344
1484
|
// TODO: should change to reprocess queue item
|
|
1345
1485
|
await rest.sendRequest(options);
|
|
1346
1486
|
},
|
|
1347
|
-
resolve: (data)=>
|
|
1487
|
+
resolve: (data)=>{
|
|
1488
|
+
resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
|
|
1489
|
+
},
|
|
1348
1490
|
reject
|
|
1349
1491
|
});
|
|
1350
1492
|
});
|
|
1351
1493
|
},
|
|
1352
|
-
async sendMessage (channelId,
|
|
1353
|
-
return await rest.post(rest.routes.channels.messages(channelId),
|
|
1494
|
+
async sendMessage (channelId, body) {
|
|
1495
|
+
return await rest.post(rest.routes.channels.messages(channelId), {
|
|
1496
|
+
body,
|
|
1497
|
+
files: body.files
|
|
1498
|
+
});
|
|
1354
1499
|
},
|
|
1355
|
-
async startThreadWithMessage (channelId, messageId,
|
|
1356
|
-
return await rest.post(rest.routes.channels.threads.message(channelId, messageId),
|
|
1500
|
+
async startThreadWithMessage (channelId, messageId, body) {
|
|
1501
|
+
return await rest.post(rest.routes.channels.threads.message(channelId, messageId), {
|
|
1502
|
+
body
|
|
1503
|
+
});
|
|
1357
1504
|
},
|
|
1358
|
-
async startThreadWithoutMessage (channelId,
|
|
1359
|
-
return await rest.post(rest.routes.channels.threads.all(channelId),
|
|
1505
|
+
async startThreadWithoutMessage (channelId, body) {
|
|
1506
|
+
return await rest.post(rest.routes.channels.threads.all(channelId), {
|
|
1507
|
+
body
|
|
1508
|
+
});
|
|
1360
1509
|
},
|
|
1361
1510
|
async syncGuildTemplate (guildId) {
|
|
1362
1511
|
return await rest.put(rest.routes.guilds.templates.all(guildId));
|
|
1363
1512
|
},
|
|
1364
|
-
async banMember (guildId, userId,
|
|
1365
|
-
|
|
1513
|
+
async banMember (guildId, userId, body) {
|
|
1514
|
+
await rest.put(rest.routes.guilds.members.ban(guildId, userId), {
|
|
1515
|
+
body
|
|
1516
|
+
});
|
|
1366
1517
|
},
|
|
1367
|
-
async editBotMember (guildId,
|
|
1368
|
-
return await rest.patch(rest.routes.guilds.members.bot(guildId),
|
|
1518
|
+
async editBotMember (guildId, body) {
|
|
1519
|
+
return await rest.patch(rest.routes.guilds.members.bot(guildId), {
|
|
1520
|
+
body
|
|
1521
|
+
});
|
|
1369
1522
|
},
|
|
1370
|
-
async editMember (guildId, userId,
|
|
1371
|
-
return await rest.patch(rest.routes.guilds.members.member(guildId, userId),
|
|
1523
|
+
async editMember (guildId, userId, body) {
|
|
1524
|
+
return await rest.patch(rest.routes.guilds.members.member(guildId, userId), {
|
|
1525
|
+
body
|
|
1526
|
+
});
|
|
1372
1527
|
},
|
|
1373
1528
|
async getMember (guildId, userId) {
|
|
1374
1529
|
return await rest.get(rest.routes.guilds.members.member(guildId, userId));
|
|
@@ -1377,37 +1532,43 @@ export function createRestManager(options) {
|
|
|
1377
1532
|
return await rest.get(rest.routes.guilds.members.members(guildId, options));
|
|
1378
1533
|
},
|
|
1379
1534
|
async kickMember (guildId, userId, reason) {
|
|
1380
|
-
|
|
1535
|
+
await rest.delete(rest.routes.guilds.members.member(guildId, userId), {
|
|
1381
1536
|
reason
|
|
1382
1537
|
});
|
|
1383
1538
|
},
|
|
1384
1539
|
async pinMessage (channelId, messageId, reason) {
|
|
1385
|
-
|
|
1540
|
+
await rest.put(rest.routes.channels.pin(channelId, messageId), {
|
|
1386
1541
|
reason
|
|
1387
|
-
}
|
|
1542
|
+
});
|
|
1388
1543
|
},
|
|
1389
|
-
async pruneMembers (guildId,
|
|
1390
|
-
return await rest.post(rest.routes.guilds.members.prune(guildId),
|
|
1544
|
+
async pruneMembers (guildId, body) {
|
|
1545
|
+
return await rest.post(rest.routes.guilds.members.prune(guildId), {
|
|
1546
|
+
body
|
|
1547
|
+
});
|
|
1391
1548
|
},
|
|
1392
1549
|
async searchMembers (guildId, query, options) {
|
|
1393
1550
|
return await rest.get(rest.routes.guilds.members.search(guildId, query, options));
|
|
1394
1551
|
},
|
|
1395
1552
|
async unbanMember (guildId, userId) {
|
|
1396
|
-
|
|
1553
|
+
await rest.delete(rest.routes.guilds.members.ban(guildId, userId));
|
|
1397
1554
|
},
|
|
1398
1555
|
async unpinMessage (channelId, messageId, reason) {
|
|
1399
|
-
|
|
1556
|
+
await rest.delete(rest.routes.channels.pin(channelId, messageId), {
|
|
1400
1557
|
reason
|
|
1401
|
-
}
|
|
1558
|
+
});
|
|
1402
1559
|
},
|
|
1403
1560
|
async triggerTypingIndicator (channelId) {
|
|
1404
|
-
|
|
1561
|
+
await rest.post(rest.routes.channels.typing(channelId));
|
|
1405
1562
|
},
|
|
1406
|
-
async upsertGlobalApplicationCommands (
|
|
1407
|
-
return await rest.put(rest.routes.interactions.commands.commands(rest.applicationId),
|
|
1563
|
+
async upsertGlobalApplicationCommands (body) {
|
|
1564
|
+
return await rest.put(rest.routes.interactions.commands.commands(rest.applicationId), {
|
|
1565
|
+
body
|
|
1566
|
+
});
|
|
1408
1567
|
},
|
|
1409
|
-
async upsertGuildApplicationCommands (guildId,
|
|
1410
|
-
return await rest.put(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId),
|
|
1568
|
+
async upsertGuildApplicationCommands (guildId, body) {
|
|
1569
|
+
return await rest.put(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), {
|
|
1570
|
+
body
|
|
1571
|
+
});
|
|
1411
1572
|
}
|
|
1412
1573
|
};
|
|
1413
1574
|
return rest;
|