forked from discordjs/discord.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guild.ts
901 lines (833 loc) · 29.1 KB
/
guild.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
import type { RawFile } from '@discordjs/rest';
import { makeURLSearchParams, type REST } from '@discordjs/rest';
import {
Routes,
type GuildMFALevel,
type GuildWidgetStyle,
type RESTGetAPIAuditLogQuery,
type RESTGetAPIAuditLogResult,
type RESTGetAPIAutoModerationRuleResult,
type RESTGetAPIAutoModerationRulesResult,
type RESTGetAPIGuildBansResult,
type RESTGetAPIGuildChannelsResult,
type RESTGetAPIGuildEmojiResult,
type RESTGetAPIGuildEmojisResult,
type RESTGetAPIGuildIntegrationsResult,
type RESTGetAPIGuildInvitesResult,
type RESTGetAPIGuildMemberResult,
type RESTGetAPIGuildMembersQuery,
type RESTGetAPIGuildMembersSearchResult,
type RESTGetAPIGuildPreviewResult,
type RESTGetAPIGuildPruneCountResult,
type RESTGetAPIGuildResult,
type RESTGetAPIGuildRolesResult,
type RESTGetAPIGuildScheduledEventQuery,
type RESTGetAPIGuildScheduledEventResult,
type RESTGetAPIGuildScheduledEventsQuery,
type RESTGetAPIGuildScheduledEventsResult,
type RESTGetAPIGuildScheduledEventUsersQuery,
type RESTGetAPIGuildScheduledEventUsersResult,
type RESTGetAPIGuildStickerResult,
type RESTGetAPIGuildStickersResult,
type RESTGetAPIGuildTemplatesResult,
type RESTGetAPIGuildThreadsResult,
type RESTGetAPIGuildVanityUrlResult,
type RESTGetAPIGuildVoiceRegionsResult,
type RESTGetAPIGuildPruneCountQuery,
type RESTPostAPIGuildStickerFormDataBody,
type RESTPostAPIGuildStickerResult,
type RESTGetAPIGuildMembersSearchQuery,
type RESTGetAPIGuildWelcomeScreenResult,
type RESTGetAPIGuildWidgetImageResult,
type RESTGetAPIGuildWidgetJSONResult,
type RESTGetAPITemplateResult,
type RESTPatchAPIAutoModerationRuleJSONBody,
type RESTPatchAPIGuildChannelPositionsJSONBody,
type RESTPatchAPIGuildEmojiJSONBody,
type RESTPatchAPIGuildEmojiResult,
type RESTPatchAPIGuildJSONBody,
type RESTPatchAPIGuildMemberJSONBody,
type RESTPatchAPIGuildMemberResult,
type RESTPatchAPIGuildResult,
type RESTPatchAPIGuildRoleJSONBody,
type RESTPatchAPIGuildRolePositionsJSONBody,
type RESTPatchAPIGuildRolePositionsResult,
type RESTPatchAPIGuildRoleResult,
type RESTPatchAPIGuildScheduledEventJSONBody,
type RESTPatchAPIGuildScheduledEventResult,
type RESTPatchAPIGuildStickerJSONBody,
type RESTPatchAPIGuildStickerResult,
type RESTPatchAPIGuildTemplateJSONBody,
type RESTPatchAPIGuildTemplateResult,
type RESTPatchAPIGuildVoiceStateUserJSONBody,
type RESTPatchAPIGuildWelcomeScreenJSONBody,
type RESTPatchAPIGuildWelcomeScreenResult,
type RESTPatchAPIGuildWidgetSettingsJSONBody,
type RESTPatchAPIGuildWidgetSettingsResult,
type RESTPostAPIAutoModerationRuleJSONBody,
type RESTPostAPIAutoModerationRuleResult,
type RESTPostAPIGuildChannelJSONBody,
type RESTPostAPIGuildChannelResult,
type RESTPostAPIGuildEmojiJSONBody,
type RESTPostAPIGuildEmojiResult,
type RESTPostAPIGuildPruneJSONBody,
type RESTPostAPIGuildRoleJSONBody,
type RESTPostAPIGuildRoleResult,
type RESTPostAPIGuildScheduledEventJSONBody,
type RESTPostAPIGuildScheduledEventResult,
type RESTPostAPIGuildsJSONBody,
type RESTPostAPIGuildsMFAResult,
type RESTPostAPIGuildsResult,
type RESTPostAPIGuildTemplatesResult,
type RESTPostAPITemplateCreateGuildJSONBody,
type RESTPutAPIGuildBanJSONBody,
type RESTPutAPIGuildTemplateSyncResult,
type Snowflake,
} from 'discord-api-types/v10';
export class GuildsAPI {
public constructor(private readonly rest: REST) {}
/**
* Fetches a guild
*
* @param guildId - The id of the guild
*/
public async get(guildId: string) {
return this.rest.get(Routes.guild(guildId)) as Promise<RESTGetAPIGuildResult>;
}
/**
* Fetches a guild preview
*
* @param guildId - The id of the guild to fetch the preview from
*/
public async getPreview(guildId: Snowflake) {
return this.rest.get(Routes.guildPreview(guildId)) as Promise<RESTGetAPIGuildPreviewResult>;
}
/**
* Creates a guild
*
* @param data - The guild to create
*/
public async create(data: RESTPostAPIGuildsJSONBody) {
return this.rest.post(Routes.guilds(), { body: data }) as Promise<RESTPostAPIGuildsResult>;
}
/**
* Edits a guild
*
* @param guildId - The id of the guild to edit
* @param data - The new guild data
* @param reason - The reason for editing this guild
*/
public async edit(guildId: Snowflake, data: RESTPatchAPIGuildJSONBody, reason?: string) {
return this.rest.patch(Routes.guild(guildId), { reason, body: data }) as Promise<RESTPatchAPIGuildResult>;
}
/**
* Deletes a guild
*
* @param guildId - The id of the guild to delete
* @param reason - The reason for deleting this guild
*/
public async delete(guildId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guild(guildId), { reason });
}
/**
* Fetches all the members of a guild
*
* @param guildId - The id of the guild
* @param options - The options to use when fetching the guild members
*/
public async getMembers(guildId: Snowflake, options: RESTGetAPIGuildMembersQuery = {}) {
return this.rest.get(Routes.guildMembers(guildId), {
query: makeURLSearchParams(options),
}) as Promise<RESTGetAPIGuildMemberResult>;
}
/**
* Fetches a guild's channels
*
* @param guildId - The id of the guild to fetch the channels from
*/
public async getChannels(guildId: Snowflake) {
return this.rest.get(Routes.guildChannels(guildId)) as Promise<RESTGetAPIGuildChannelsResult>;
}
/**
* Creates a guild channel
*
* @param guildId - The id of the guild to create the channel in
* @param data - The data to create the new channel
* @param reason - The reason for creating this channel
*/
public async createChannel(guildId: Snowflake, data: RESTPostAPIGuildChannelJSONBody, reason?: string) {
return this.rest.post(Routes.guildChannels(guildId), {
reason,
body: data,
}) as Promise<RESTPostAPIGuildChannelResult>;
}
/**
* Edits a guild channel's positions
*
* @param guildId - The id of the guild to edit the channel positions from
* @param data - The data to edit the channel positions with
* @param reason - The reason for editing the channel positions
*/
public async setChannelPositions(
guildId: Snowflake,
data: RESTPatchAPIGuildChannelPositionsJSONBody,
reason?: string,
) {
await this.rest.patch(Routes.guildChannels(guildId), { reason, body: data });
}
/**
* Fetches the active threads in a guild
*
* @param guildId - The id of the guild to fetch the active threads from
*/
public async getActiveThreads(guildId: Snowflake) {
return this.rest.get(Routes.guildActiveThreads(guildId)) as Promise<RESTGetAPIGuildThreadsResult>;
}
/**
* Fetches a guild member ban
*
* @param guildId - The id of the guild to fetch the ban from
*/
public async getMemberBans(guildId: Snowflake) {
return this.rest.get(Routes.guildBans(guildId)) as Promise<RESTGetAPIGuildBansResult>;
}
/**
* Bans a user from a guild
*
* @param guildId - The id of the guild to ban the member in
* @param userId - The id of the user to ban
* @param options - Options for banning the user
* @param reason - The reason for banning the user
*/
public async banUser(
guildId: Snowflake,
userId: Snowflake,
options: RESTPutAPIGuildBanJSONBody = {},
reason?: string,
) {
await this.rest.put(Routes.guildBan(guildId, userId), { reason, body: options });
}
/**
* Unbans a user from a guild
*
* @param guildId - The id of the guild to unban the member in
* @param userId - The id of the user to unban
* @param reason - The reason for unbanning the user
*/
public async unbanUser(guildId: Snowflake, userId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildBan(guildId, userId), { reason });
}
/**
* Gets all the roles in a guild
*
* @param guildId - The id of the guild to fetch the roles from
*/
public async getRoles(guildId: Snowflake) {
return this.rest.get(Routes.guildRoles(guildId)) as Promise<RESTGetAPIGuildRolesResult>;
}
/**
* Creates a guild role
*
* @param guildId - The id of the guild to create the role in
* @param data - The data to create the role with
* @param reason - The reason for creating the role
*/
public async createRole(guildId: Snowflake, data: RESTPostAPIGuildRoleJSONBody, reason?: string) {
return this.rest.post(Routes.guildRoles(guildId), { reason, body: data }) as Promise<RESTPostAPIGuildRoleResult>;
}
/**
* Sets role positions in a guild
*
* @param guildId - The id of the guild to set role positions for
* @param data - The data for setting a role position
* @param reason - The reason for setting the role position
*/
public async setRolePositions(guildId: Snowflake, data: RESTPatchAPIGuildRolePositionsJSONBody, reason?: string) {
return this.rest.patch(Routes.guildRoles(guildId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildRolePositionsResult>;
}
/**
* Edits a guild role
*
* @param guildId - The id of the guild to edit the role in
* @param roleId - The id of the role to edit
* @param data - data for editing the role
* @param reason - The reason for editing the role
*/
public async editRole(guildId: Snowflake, roleId: Snowflake, data: RESTPatchAPIGuildRoleJSONBody, reason?: string) {
return this.rest.patch(Routes.guildRole(guildId, roleId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildRoleResult>;
}
/**
* Deletes a guild role
*
* @param guildId - The id of the guild to delete the role in
* @param roleId - The id of the role to delete
* @param reason - The reason for deleting the role
*/
public async deleteRole(guildId: Snowflake, roleId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildRole(guildId, roleId), { reason });
}
/**
* Edits the multi-factor-authentication (MFA) level of a guild
*
* @param guildId - The id of the guild to edit the MFA level for
* @param level - The new MFA level
* @param reason - The reason for editing the MFA level
*/
public async editMFALevel(guildId: Snowflake, level: GuildMFALevel, reason?: string) {
return this.rest.post(Routes.guildMFA(guildId), {
reason,
body: { mfa_level: level },
}) as Promise<RESTPostAPIGuildsMFAResult>;
}
/**
* Fetch the number of members that can be pruned from a guild
*
* @param guildId - The id of the guild to fetch the number of pruned members from
* @param options - The options for fetching the number of pruned members
*/
public async getPruneCount(guildId: Snowflake, options: RESTGetAPIGuildPruneCountQuery = {}) {
return this.rest.get(Routes.guildPrune(guildId), {
query: makeURLSearchParams(options),
}) as Promise<RESTGetAPIGuildPruneCountResult>;
}
/**
* Prunes members in a guild
*
* @param guildId - The id of the guild to prune members in
* @param options - The options for pruning members
* @param reason - The reason for pruning members
*/
public async beginPrune(guildId: Snowflake, options: RESTPostAPIGuildPruneJSONBody = {}, reason?: string) {
return this.rest.post(Routes.guildPrune(guildId), {
body: options,
reason,
}) as Promise<RESTGetAPIGuildPruneCountResult>;
}
/**
* Fetches voice regions for a guild
*
* @param guildId - The id of the guild to fetch the voice regions from
*/
public async getVoiceRegions(guildId: Snowflake) {
return this.rest.get(Routes.guildVoiceRegions(guildId)) as Promise<RESTGetAPIGuildVoiceRegionsResult>;
}
/**
* Fetches the invites for a guild
*
* @param guildId - The id of the guild to fetch the invites from
*/
public async getInvites(guildId: Snowflake) {
return this.rest.get(Routes.guildInvites(guildId)) as Promise<RESTGetAPIGuildInvitesResult>;
}
/**
* Fetches the integrations for a guild
*
* @param guildId - The id of the guild to fetch the integrations from
*/
public async getIntegrations(guildId: Snowflake) {
return this.rest.get(Routes.guildIntegrations(guildId)) as Promise<RESTGetAPIGuildIntegrationsResult>;
}
/**
* Deletes an integration from a guild
*
* @param guildId - The id of the guild to delete the integration from
* @param integrationId - The id of the integration to delete
* @param reason - The reason for deleting the integration
*/
public async deleteIntegration(guildId: Snowflake, integrationId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildIntegration(guildId, integrationId), { reason });
}
/**
* Fetches the widget settings for a guild
*
* @param guildId - The id of the guild to fetch the widget settings from
*/
public async getWidgetSettings(guildId: Snowflake) {
return this.rest.get(Routes.guildWidgetSettings(guildId)) as Promise<RESTGetAPIGuildWidgetImageResult>;
}
/**
* Edits the widget settings for a guild
*
* @param guildId - The id of the guild to edit the widget settings from
* @param data - The new widget settings data
* @param reason - The reason for editing the widget settings
*/
public async editWidgetSettings(guildId: Snowflake, data: RESTPatchAPIGuildWidgetSettingsJSONBody, reason?: string) {
return this.rest.patch(Routes.guildWidgetSettings(guildId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildWidgetSettingsResult>;
}
/**
* Fetches the widget for a guild
*
* @param guildId - The id of the guild to fetch the widget from
*/
public async getWidget(guildId: Snowflake) {
return this.rest.get(Routes.guildWidgetJSON(guildId)) as Promise<RESTGetAPIGuildWidgetJSONResult>;
}
/**
* Fetches the vanity url for a guild
*
* @param guildId - The id of the guild to fetch the vanity url from
*/
public async getVanityURL(guildId: Snowflake) {
return this.rest.get(Routes.guildVanityUrl(guildId)) as Promise<RESTGetAPIGuildVanityUrlResult>;
}
/**
* Fetches the widget image for a guild
*
* @param guildId - The id of the guild to fetch the widget image from
* @param style - The style of the widget image
*/
public async getWidgetImage(guildId: Snowflake, style?: GuildWidgetStyle) {
return this.rest.get(Routes.guildWidgetImage(guildId), {
query: makeURLSearchParams({ style }),
}) as Promise<RESTGetAPIGuildWidgetImageResult>;
}
/**
* Fetches the welcome screen for a guild
*
* @param guildId - The id of the guild to fetch the welcome screen from
*/
public async getWelcomeScreen(guildId: Snowflake) {
return this.rest.get(Routes.guildWelcomeScreen(guildId)) as Promise<RESTGetAPIGuildWelcomeScreenResult>;
}
/**
* Edits the welcome screen for a guild
*
* @param guildId - The id of the guild to edit the welcome screen for
* @param data - The new welcome screen data
* @param reason - The reason for editing the welcome screen
*/
public async editWelcomeScreen(guildId: Snowflake, data?: RESTPatchAPIGuildWelcomeScreenJSONBody, reason?: string) {
return this.rest.patch(Routes.guildWelcomeScreen(guildId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildWelcomeScreenResult>;
}
/**
* Edits a user's voice state in a guild
*
* @param guildId - The id of the guild to edit the current user's voice state in
* @param userId - The id of the user to edit the voice state for
* @param data - The data for editing the voice state
* @param reason - The reason for editing the voice state
*/
public async editUserVoiceState(
guildId: Snowflake,
userId: Snowflake,
data: RESTPatchAPIGuildVoiceStateUserJSONBody,
reason?: string,
) {
await this.rest.patch(Routes.guildVoiceState(guildId, userId), { reason, body: data });
}
/**
* Fetches all emojis for a guild
*
* @param guildId - The id of the guild to fetch the emojis from
*/
public async getEmojis(guildId: Snowflake) {
return this.rest.get(Routes.guildEmojis(guildId)) as Promise<RESTGetAPIGuildEmojisResult>;
}
/**
* Fetches an emoji for a guild
*
* @param guildId - The id of the guild to fetch the emoji from
* @param emojiId - The id of the emoji to fetch
*/
public async getEmoji(guildId: Snowflake, emojiId: Snowflake) {
return this.rest.get(Routes.guildEmoji(guildId, emojiId)) as Promise<RESTGetAPIGuildEmojiResult>;
}
/**
* Creates a new emoji for a guild
*
* @param guildId - The id of the guild to create the emoji from
* @param data - The data for creating the emoji
* @param reason - The reason for creating the emoji
*/
public async createEmoji(guildId: Snowflake, data: RESTPostAPIGuildEmojiJSONBody, reason?: string) {
return this.rest.post(Routes.guildEmojis(guildId), {
reason,
body: data,
}) as Promise<RESTPostAPIGuildEmojiResult>;
}
/**
* Edits an emoji for a guild
*
* @param guildId - The id of the guild to edit the emoji from
* @param emojiId - The id of the emoji to edit
* @param data - The data for editing the emoji
* @param reason - The reason for editing the emoji
*/
public async editEmoji(
guildId: Snowflake,
emojiId: Snowflake,
data: RESTPatchAPIGuildEmojiJSONBody,
reason?: string,
) {
return this.rest.patch(Routes.guildEmoji(guildId, emojiId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildEmojiResult>;
}
/**
* Deletes an emoji for a guild
*
* @param guildId - The id of the guild to delete the emoji from
* @param emojiId - The id of the emoji to delete
* @param reason - The reason for deleting the emoji
*/
public async deleteEmoji(guildId: Snowflake, emojiId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildEmoji(guildId, emojiId), { reason });
}
/**
* Fetches all scheduled events for a guild
*
* @param guildId - The id of the guild to fetch the scheduled events from
* @param options - The options for fetching the scheduled events
*/
public async getScheduledEvents(guildId: Snowflake, options: RESTGetAPIGuildScheduledEventsQuery = {}) {
return this.rest.get(Routes.guildScheduledEvents(guildId), {
query: makeURLSearchParams(options),
}) as Promise<RESTGetAPIGuildScheduledEventsResult>;
}
/**
* Creates a new scheduled event for a guild
*
* @param guildId - The id of the guild to create the scheduled event from
* @param data - The data to create the event with
* @param reason - The reason for creating the scheduled event
*/
public async createScheduledEvent(guildId: Snowflake, data: RESTPostAPIGuildScheduledEventJSONBody, reason?: string) {
return this.rest.post(Routes.guildScheduledEvents(guildId), {
reason,
body: data,
}) as Promise<RESTPostAPIGuildScheduledEventResult>;
}
/**
* Fetches a scheduled event for a guild
*
* @param guildId - The id of the guild to fetch the scheduled event from
* @param eventId - The id of the scheduled event to fetch
* @param options - The options for fetching the scheduled event
*/
public async getScheduledEvent(
guildId: Snowflake,
eventId: Snowflake,
options: RESTGetAPIGuildScheduledEventQuery = {},
) {
return this.rest.get(Routes.guildScheduledEvent(guildId, eventId), {
query: makeURLSearchParams(options),
}) as Promise<RESTGetAPIGuildScheduledEventResult>;
}
/**
* Edits a scheduled event for a guild
*
* @param guildId - The id of the guild to edit the scheduled event from
* @param eventId - The id of the scheduled event to edit
* @param data - The new event data
* @param reason - The reason for editing the scheduled event
*/
public async editScheduledEvent(
guildId: Snowflake,
eventId: Snowflake,
data: RESTPatchAPIGuildScheduledEventJSONBody,
reason?: string,
) {
return this.rest.patch(Routes.guildScheduledEvent(guildId, eventId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildScheduledEventResult>;
}
/**
* Deletes a scheduled event for a guild
*
* @param guildId - The id of the guild to delete the scheduled event from
* @param eventId - The id of the scheduled event to delete
* @param reason - The reason for deleting the scheduled event
*/
public async deleteScheduledEvent(guildId: Snowflake, eventId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildScheduledEvent(guildId, eventId), { reason });
}
/**
* Gets all users that are interested in a scheduled event
*
* @param guildId - The id of the guild to fetch the scheduled event users from
* @param eventId - The id of the scheduled event to fetch the users for
* @param options - The options for fetching the scheduled event users
*/
public async getScheduledEventUsers(
guildId: Snowflake,
eventId: Snowflake,
options: RESTGetAPIGuildScheduledEventUsersQuery = {},
) {
return this.rest.get(Routes.guildScheduledEventUsers(guildId, eventId), {
query: makeURLSearchParams(options),
}) as Promise<RESTGetAPIGuildScheduledEventUsersResult>;
}
/**
* Fetches all the templates for a guild
*
* @param guildId - The id of the guild to fetch the templates from
*/
public async getTemplates(guildId: Snowflake) {
return this.rest.get(Routes.guildTemplates(guildId)) as Promise<RESTGetAPIGuildTemplatesResult>;
}
/**
* Syncs a template for a guild
*
* @param guildId - The id of the guild to sync the template from
* @param templateCode - The code of the template to sync
*/
public async syncTemplate(guildId: Snowflake, templateCode: string) {
return this.rest.put(Routes.guildTemplate(guildId, templateCode)) as Promise<RESTPutAPIGuildTemplateSyncResult>;
}
/**
* Edits a template for a guild
*
* @param guildId - The id of the guild to edit the template from
* @param templateCode - The code of the template to edit
* @param data - The data for editing the template
*/
public async editTemplate(guildId: Snowflake, templateCode: string, data: RESTPatchAPIGuildTemplateJSONBody) {
return this.rest.patch(Routes.guildTemplate(guildId, templateCode), {
body: data,
}) as Promise<RESTPatchAPIGuildTemplateResult>;
}
/**
* Deletes a template for a guild
*
* @param guildId - The id of the guild to delete the template from
* @param templateCode - The code of the template to delete
*/
public async deleteTemplate(guildId: Snowflake, templateCode: string) {
await this.rest.delete(Routes.guildTemplate(guildId, templateCode));
}
/**
* Fetches all the stickers for a guild
*
* @param guildId - The id of the guild to fetch the stickers from
*/
public async getStickers(guildId: Snowflake) {
return this.rest.get(Routes.guildStickers(guildId)) as Promise<RESTGetAPIGuildStickersResult>;
}
/**
* Fetches a sticker for a guild
*
* @param guildId - The id of the guild to fetch the sticker from
* @param stickerId - The id of the sticker to fetch
*/
public async getSticker(guildId: Snowflake, stickerId: Snowflake) {
return this.rest.get(Routes.guildSticker(guildId, stickerId)) as Promise<RESTGetAPIGuildStickerResult>;
}
/**
* Creates a sticker for a guild
*
* @param guildId - The id of the guild to create the sticker for
* @param data - The data for creating the sticker
* @param reason - The reason for creating the sticker
*/
public async createSticker(
guildId: Snowflake,
{ file, ...body }: Omit<RESTPostAPIGuildStickerFormDataBody, 'file'> & { file: RawFile },
reason?: string,
) {
const fileData = { ...file, key: 'file' };
return this.rest.post(Routes.guildStickers(guildId), {
appendToFormData: true,
body,
files: [fileData],
reason,
}) as Promise<RESTPostAPIGuildStickerResult>;
}
/**
* Edits a sticker for a guild
*
* @param guildId - The id of the guild to edit the sticker from
* @param stickerId - The id of the sticker to edit
* @param data - The data for editing the sticker
* @param reason - The reason for editing the sticker
*/
public async editSticker(
guildId: Snowflake,
stickerId: Snowflake,
data: RESTPatchAPIGuildStickerJSONBody,
reason?: string,
) {
return this.rest.patch(Routes.guildSticker(guildId, stickerId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildStickerResult>;
}
/**
* Deletes a sticker for a guild
*
* @param guildId - The id of the guild to delete the sticker from
* @param stickerId - The id of the sticker to delete
* @param reason - The reason for deleting the sticker
*/
public async deleteSticker(guildId: Snowflake, stickerId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildSticker(guildId, stickerId), { reason });
}
/**
* Fetches the audit logs for a guild
*
* @param guildId - The id of the guild to fetch the audit logs from
* @param options - The options for fetching the audit logs
*/
public async getAuditLogs(guildId: Snowflake, options: RESTGetAPIAuditLogQuery = {}) {
return this.rest.get(Routes.guildAuditLog(guildId), {
query: makeURLSearchParams(options),
}) as Promise<RESTGetAPIAuditLogResult>;
}
/**
* Fetches all auto moderation rules for a guild
*
* @param guildId - The id of the guild to fetch the auto moderation rules from
*/
public async getAutoModerationRules(guildId: Snowflake) {
return this.rest.get(Routes.guildAutoModerationRules(guildId)) as Promise<RESTGetAPIAutoModerationRulesResult>;
}
/**
* Fetches an auto moderation rule for a guild
*
* @param guildId - The id of the guild to fetch the auto moderation rule from
* @param ruleId - The id of the auto moderation rule to fetch
*/
public async getAutoModerationRule(guildId: Snowflake, ruleId: Snowflake) {
return this.rest.get(
Routes.guildAutoModerationRule(guildId, ruleId),
) as Promise<RESTGetAPIAutoModerationRuleResult>;
}
/**
* Creates a new auto moderation rule for a guild
*
* @param guildId - The id of the guild to create the auto moderation rule from
* @param data - The data for creating the auto moderation rule
*/
public async createAutoModerationRule(
guildId: Snowflake,
data: RESTPostAPIAutoModerationRuleJSONBody,
reason?: string,
) {
return this.rest.post(Routes.guildAutoModerationRules(guildId), {
reason,
body: data,
}) as Promise<RESTPostAPIAutoModerationRuleResult>;
}
/**
* Edits an auto moderation rule for a guild
*
* @param guildId - The id of the guild to edit the auto moderation rule from
* @param ruleId - The id of the auto moderation rule to edit
* @param data - The data for editing the auto moderation rule
* @param reason - The reason for editing the auto moderation rule
*/
public async editAutoModerationRule(
guildId: Snowflake,
ruleId: Snowflake,
data: RESTPatchAPIAutoModerationRuleJSONBody,
reason?: string,
) {
return this.rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), {
reason,
body: data,
}) as Promise<RESTPatchAPIAutoModerationRuleJSONBody>;
}
/**
* Deletes an auto moderation rule for a guild
*
* @param guildId - The id of the guild to delete the auto moderation rule from
* @param ruleId - The id of the auto moderation rule to delete
* @param reason - The reason for deleting the auto moderation rule
*/
public async deleteAutoModerationRule(guildId: Snowflake, ruleId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildAutoModerationRule(guildId, ruleId), { reason });
}
/**
* Fetches a guild member
*
* @param guildId - The id of the guild
* @param userId - The id of the user
*/
public async getMember(guildId: Snowflake, userId: Snowflake) {
return this.rest.get(Routes.guildMember(guildId, userId)) as Promise<RESTGetAPIGuildMemberResult>;
}
/**
* Searches for guild members
*
* @param guildId - The id of the guild to search in
* @param query - The query to search for
* @param limit - The maximum number of members to return
*/
public async searchForMembers(guildId: Snowflake, options: RESTGetAPIGuildMembersSearchQuery) {
return this.rest.get(Routes.guildMembersSearch(guildId), {
query: makeURLSearchParams(options),
}) as Promise<RESTGetAPIGuildMembersSearchResult>;
}
/**
* Edits a guild member
*
* @param guildId - The id of the guild
* @param userId - The id of the user
* @param data - The data to use when editing the guild member
* @param reason - The reason for editing this guild member
*/
public async editMember(
guildId: Snowflake,
userId: Snowflake,
data: RESTPatchAPIGuildMemberJSONBody = {},
reason?: string,
) {
return this.rest.patch(Routes.guildMember(guildId, userId), {
reason,
body: data,
}) as Promise<RESTPatchAPIGuildMemberResult>;
}
/**
* Adds a role to a guild member
*
* @param guildId - The id of the guild
* @param userId - The id of the user
* @param roleId - The id of the role
* @param reason - The reason for adding this role to the guild member
*/
public async addRoleToMember(guildId: Snowflake, userId: Snowflake, roleId: Snowflake, reason?: string) {
await this.rest.put(Routes.guildMemberRole(guildId, userId, roleId), { reason });
}
/**
* Removes a role from a guild member
*
* @param guildId - The id of the guild
* @param userId - The id of the user
* @param roleId - The id of the role
* @param reason - The reason for removing this role from the guild member
*/
public async removeRoleFromMember(guildId: Snowflake, userId: Snowflake, roleId: Snowflake, reason?: string) {
await this.rest.delete(Routes.guildMemberRole(guildId, userId, roleId), { reason });
}
/**
* Fetches a guild template
*
* @param templateCode - The code of the template
*/
public async getTemplate(templateCode: string) {
return this.rest.get(Routes.template(templateCode)) as Promise<RESTGetAPITemplateResult>;
}
/**
* Creates a new template
*
* @param templateCode - The code of the template
* @param data - The data to use when creating the template
*/
public async createTemplate(templateCode: string, data: RESTPostAPITemplateCreateGuildJSONBody) {
return this.rest.post(Routes.template(templateCode), { body: data }) as Promise<RESTPostAPIGuildTemplatesResult>;
}
}