-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathchannel.ts
More file actions
751 lines (710 loc) · 25.4 KB
/
channel.ts
File metadata and controls
751 lines (710 loc) · 25.4 KB
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
/* eslint-disable jsdoc/check-param-names */
import { makeURLSearchParams, type RawFile, type RequestData, type REST } from '@discordjs/rest';
import {
Routes,
type RESTDeleteAPIChannelResult,
type RESTGetAPIChannelInvitesResult,
type RESTGetAPIChannelMessageReactionUsersQuery,
type RESTGetAPIChannelMessageReactionUsersResult,
type RESTGetAPIChannelMessageResult,
type RESTGetAPIChannelMessagesPinsQuery,
type RESTGetAPIChannelMessagesPinsResult,
type RESTGetAPIChannelMessagesQuery,
type RESTGetAPIChannelMessagesResult,
type RESTGetAPIChannelResult,
type RESTGetAPIChannelThreadsArchivedQuery,
type RESTGetAPIChannelUsersThreadsArchivedResult,
type RESTGetAPIChannelWebhooksResult,
type RESTPatchAPIChannelJSONBody,
type RESTPatchAPIChannelMessageJSONBody,
type RESTPatchAPIChannelMessageResult,
type RESTPatchAPIChannelResult,
type RESTPostAPIChannelFollowersResult,
type RESTPostAPIChannelInviteJSONBody,
type RESTPostAPIChannelInviteResult,
type RESTPostAPIChannelMessageCrosspostResult,
type RESTPostAPIChannelMessageJSONBody,
type RESTPostAPIChannelMessageResult,
type RESTPostAPIChannelThreadsJSONBody,
type RESTPostAPIChannelThreadsResult,
type RESTPostAPIChannelWebhookJSONBody,
type RESTPostAPIChannelWebhookResult,
type RESTPostAPIGuildForumThreadsJSONBody,
type RESTPostAPISoundboardSendSoundJSONBody,
type RESTPutAPIChannelPermissionJSONBody,
type RESTPutAPIChannelRecipientJSONBody,
type Snowflake,
} from 'discord-api-types/v10';
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
}
export interface CreateMessageOptions extends RESTPostAPIChannelMessageJSONBody {
files?: RawFile[];
}
export interface EditMessageOptions extends RESTPatchAPIChannelMessageJSONBody {
files?: RawFile[];
}
export class ChannelsAPI {
public constructor(private readonly rest: REST) {}
/**
* Sends a message in a channel
*
* @see {@link https://discord.com/developers/docs/resources/message#create-message}
* @param channelId - The id of the channel to send the message in
* @param body - The data for sending the message
* @param options - The options for sending the message
*/
public async createMessage(
channelId: Snowflake,
{ files, ...body }: CreateMessageOptions,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.post(Routes.channelMessages(channelId), {
auth,
files,
body,
signal,
}) as Promise<RESTPostAPIChannelMessageResult>;
}
/**
* Edits a message
*
* @see {@link https://discord.com/developers/docs/resources/message#edit-message}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to edit
* @param body - The data for editing the message
* @param options - The options for editing the message
*/
public async editMessage(
channelId: Snowflake,
messageId: Snowflake,
{ files, ...body }: EditMessageOptions,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.patch(Routes.channelMessage(channelId, messageId), {
auth,
files,
body,
signal,
}) as Promise<RESTPatchAPIChannelMessageResult>;
}
/**
* Fetches the reactions for a message
*
* @see {@link https://discord.com/developers/docs/resources/message#get-reactions}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to get the reactions for
* @param emoji - The emoji to get the reactions for. URL encoding happens internally
* @param query - The query options for fetching the reactions
* @param options - The options for fetching the message reactions
* @example
* ```ts
* // Unicode.
* await api.channels.getMessageReactions('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.getMessageReactions('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async getMessageReactions(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
query: RESTGetAPIChannelMessageReactionUsersQuery = {},
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.get(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), {
auth,
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelMessageReactionUsersResult>;
}
/**
* Deletes a reaction for the current user
*
* @see {@link https://discord.com/developers/docs/resources/message#delete-own-reaction}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reaction for
* @param emoji - The emoji to delete the reaction for. URL encoding happens internally
* @param options - The options for deleting the reaction
* @example
* ```ts
* // Unicode.
* await api.channels.deleteOwnMessageReaction('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.deleteOwnMessageReaction('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async deleteOwnMessageReaction(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), {
auth,
signal,
});
}
/**
* Deletes a reaction for a user
*
* @see {@link https://discord.com/developers/docs/resources/message#delete-user-reaction}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reaction for
* @param emoji - The emoji to delete the reaction for. URL encoding happens internally
* @param userId - The id of the user to delete the reaction for
* @param options - The options for deleting the reaction
* @example
* ```ts
* // Unicode.
* await api.channels.deleteUserMessageReaction('1234567890', '1234567890', '👍', '1234567890');
*
* // Custom emoji.
* await api.channels.deleteUserMessageReaction('1234567890', '1234567890', 'emoji_name:1234567890', '1234567890');
* ```
*/
public async deleteUserMessageReaction(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
userId: Snowflake,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageUserReaction(channelId, messageId, encodeURIComponent(emoji), userId), {
auth,
signal,
});
}
/**
* Deletes all reactions for a message
*
* @see {@link https://discord.com/developers/docs/resources/message#delete-all-reactions}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reactions for
* @param options - The options for deleting the reactions
*/
public async deleteAllMessageReactions(
channelId: Snowflake,
messageId: Snowflake,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId), { auth, signal });
}
/**
* Deletes all reactions of an emoji for a message
*
* @see {@link https://discord.com/developers/docs/resources/message#delete-all-reactions-for-emoji}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reactions for
* @param emoji - The emoji to delete the reactions for. URL encoding happens internally
* @param options - The options for deleting the reactions
* @example
* ```ts
* // Unicode.
* await api.channels.deleteAllMessageReactionsForEmoji('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.deleteAllMessageReactionsForEmoji('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async deleteAllMessageReactionsForEmoji(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), {
auth,
signal,
});
}
/**
* Adds a reaction to a message
*
* @see {@link https://discord.com/developers/docs/resources/message#create-reaction}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to add the reaction to
* @param emoji - The emoji to add the reaction with. URL encoding happens internally
* @param options - The options for adding the reaction
* @example
* ```ts
* // Unicode.
* await api.channels.addMessageReaction('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.addMessageReaction('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async addMessageReaction(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.put(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), {
auth,
signal,
});
}
/**
* Fetches a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel}
* @param channelId - The id of the channel
* @param options - The options for fetching the channel
*/
public async get(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
return this.rest.get(Routes.channel(channelId), { auth, signal }) as Promise<RESTGetAPIChannelResult>;
}
/**
* Edits a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#modify-channel}
* @param channelId - The id of the channel to edit
* @param body - The new channel data
* @param options - The options for editing the channel
*/
public async edit(
channelId: Snowflake,
body: RESTPatchAPIChannelJSONBody,
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
return this.rest.patch(Routes.channel(channelId), {
auth,
reason,
body,
signal,
}) as Promise<RESTPatchAPIChannelResult>;
}
/**
* Deletes a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#deleteclose-channel}
* @param channelId - The id of the channel to delete
* @param options - The options for deleting the channel
*/
public async delete(
channelId: Snowflake,
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
return this.rest.delete(Routes.channel(channelId), { auth, signal, reason }) as Promise<RESTDeleteAPIChannelResult>;
}
/**
* Fetches the messages of a channel
*
* @see {@link https://discord.com/developers/docs/resources/message#get-channel-messages}
* @param channelId - The id of the channel to fetch messages from
* @param query - The query options for fetching messages
* @param options - The options for fetching the messages
*/
public async getMessages(
channelId: Snowflake,
query: RESTGetAPIChannelMessagesQuery = {},
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.get(Routes.channelMessages(channelId), {
auth,
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelMessagesResult>;
}
/**
* Shows a typing indicator in a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#trigger-typing-indicator}
* @param channelId - The id of the channel to show the typing indicator in
* @param options - The options for showing the typing indicator
*/
public async showTyping(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
await this.rest.post(Routes.channelTyping(channelId), { auth, signal });
}
/**
* Fetches pinned messages of a channel
*
* @see {@link https://discord.com/developers/docs/resources/message#get-channel-pins}
* @param channelId - The id of the channel to fetch pinned messages from
* @param query - The query options for fetching pinned messages
* @param options - The options for fetching pinned messages
*/
public async getPins(
channelId: Snowflake,
query: RESTGetAPIChannelMessagesPinsQuery = {},
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.get(Routes.channelMessagesPins(channelId), {
auth,
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelMessagesPinsResult>;
}
/**
* Pins a message in a channel
*
* @see {@link https://discord.com/developers/docs/resources/message#pin-message}
* @param channelId - The id of the channel to pin the message in
* @param messageId - The id of the message to pin
* @param options - The options for pinning the message
*/
public async pinMessage(
channelId: Snowflake,
messageId: Snowflake,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
await this.rest.put(Routes.channelMessagesPin(channelId, messageId), { auth, reason, signal });
}
/**
* Deletes a message
*
* @see {@link https://discord.com/developers/docs/resources/message#delete-message}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete
* @param options - The options for deleting the message
*/
public async deleteMessage(
channelId: Snowflake,
messageId: Snowflake,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessage(channelId, messageId), { auth, reason, signal });
}
/**
* Bulk deletes messages
*
* @see {@link https://discord.com/developers/docs/resources/message#bulk-delete-messages}
* @param channelId - The id of the channel the messages are in
* @param messageIds - The ids of the messages to delete
* @param options - The options for deleting the messages
*/
public async bulkDeleteMessages(
channelId: Snowflake,
messageIds: Snowflake[],
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
): Promise<void> {
await this.rest.post(Routes.channelBulkDelete(channelId), { auth, reason, body: { messages: messageIds }, signal });
}
/**
* Fetches a message
*
* @see {@link https://discord.com/developers/docs/resources/message#get-channel-message}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to fetch
* @param options - The options for fetching the message
*/
public async getMessage(
channelId: Snowflake,
messageId: Snowflake,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.get(Routes.channelMessage(channelId, messageId), {
auth,
signal,
}) as Promise<RESTGetAPIChannelMessageResult>;
}
/**
* Crossposts a message
*
* @see {@link https://discord.com/developers/docs/resources/message#crosspost-message}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to crosspost
* @param options - The options for crossposting the message
*/
public async crosspostMessage(
channelId: Snowflake,
messageId: Snowflake,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.post(Routes.channelMessageCrosspost(channelId, messageId), {
auth,
signal,
}) as Promise<RESTPostAPIChannelMessageCrosspostResult>;
}
/**
* Unpins a message in a channel
*
* @see {@link https://discord.com/developers/docs/resources/message#unpin-message}
* @param channelId - The id of the channel to unpin the message in
* @param messageId - The id of the message to unpin
* @param options - The options for unpinning the message
*/
public async unpinMessage(
channelId: Snowflake,
messageId: Snowflake,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessagesPin(channelId, messageId), { auth, reason, signal });
}
/**
* Follows an announcement channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#follow-announcement-channel}
* @param channelId - The id of the announcement channel to follow
* @param webhookChannelId - The id of the webhook channel to follow the announcements in
* @param options - The options for following the announcement channel
*/
public async followAnnouncements(
channelId: Snowflake,
webhookChannelId: Snowflake,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.channelFollowers(channelId), {
auth,
body: { webhook_channel_id: webhookChannelId },
reason,
signal,
}) as Promise<RESTPostAPIChannelFollowersResult>;
}
/**
* Creates a new invite for a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#create-channel-invite}
* @param channelId - The id of the channel to create an invite for
* @param body - The data for creating the invite
* @param options - The options for creating the invite
*/
public async createInvite(
channelId: Snowflake,
body: RESTPostAPIChannelInviteJSONBody,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.channelInvites(channelId), {
auth,
reason,
body,
signal,
}) as Promise<RESTPostAPIChannelInviteResult>;
}
/**
* Fetches the invites of a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel-invites}
* @param channelId - The id of the channel to fetch invites from
* @param options - The options for fetching the invites
*/
public async getInvites(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
return this.rest.get(Routes.channelInvites(channelId), { auth, signal }) as Promise<RESTGetAPIChannelInvitesResult>;
}
/**
* Creates a new thread
*
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-from-message}
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-without-message}
* @param channelId - The id of the channel to start the thread in
* @param body - The data for starting the thread
* @param messageId - The id of the message to start the thread from
* @param options - The options for starting the thread
*/
public async createThread(
channelId: Snowflake,
body: RESTPostAPIChannelThreadsJSONBody,
messageId?: Snowflake,
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.threads(channelId, messageId), {
auth,
body,
signal,
reason,
}) as Promise<RESTPostAPIChannelThreadsResult>;
}
/**
* Creates a new forum post
*
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel}
* @param channelId - The id of the forum channel to start the thread in
* @param body - The data for starting the thread
* @param options - The options for starting the thread
*/
public async createForumThread(
channelId: Snowflake,
{ message, ...optionsBody }: StartForumThreadOptions,
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
const { files, ...messageBody } = message;
const body = {
...optionsBody,
message: messageBody,
};
return this.rest.post(Routes.threads(channelId), {
auth,
files,
body,
reason,
signal,
}) as Promise<RESTPostAPIChannelThreadsResult>;
}
/**
* Fetches the archived threads of a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#list-public-archived-threads}
* @see {@link https://discord.com/developers/docs/resources/channel#list-private-archived-threads}
* @param channelId - The id of the channel to fetch archived threads from
* @param archivedStatus - The archived status of the threads to fetch
* @param query - The options for fetching archived threads
* @param options - The options for fetching archived threads
*/
public async getArchivedThreads(
channelId: Snowflake,
archivedStatus: 'private' | 'public',
query: RESTGetAPIChannelThreadsArchivedQuery = {},
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.get(Routes.channelThreads(channelId, archivedStatus), {
auth,
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
}
/**
* Fetches the private joined archived threads of a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads}
* @param channelId - The id of the channel to fetch joined archived threads from
* @param query - The options for fetching joined archived threads
* @param options - The options for fetching joined archived threads
*/
public async getJoinedPrivateArchivedThreads(
channelId: Snowflake,
query: RESTGetAPIChannelThreadsArchivedQuery = {},
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
return this.rest.get(Routes.channelJoinedArchivedThreads(channelId), {
auth,
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
}
/**
* Creates a new webhook
*
* @see {@link https://discord.com/developers/docs/resources/webhook#create-webhook}
* @param channelId - The id of the channel to create the webhook in
* @param body - The data for creating the webhook
* @param options - The options for creating the webhook
*/
public async createWebhook(
channelId: Snowflake,
body: RESTPostAPIChannelWebhookJSONBody,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.channelWebhooks(channelId), {
auth,
reason,
body,
signal,
}) as Promise<RESTPostAPIChannelWebhookResult>;
}
/**
* Fetches the webhooks of a channel
*
* @see {@link https://discord.com/developers/docs/resources/webhook#get-channel-webhooks}
* @param channelId - The id of the channel
* @param options - The options for fetching the webhooks
*/
public async getWebhooks(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
return this.rest.get(Routes.channelWebhooks(channelId), {
auth,
signal,
}) as Promise<RESTGetAPIChannelWebhooksResult>;
}
/**
* Edits the permission overwrite for a user or role in a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#edit-channel-permissions}
* @param channelId - The id of the channel to edit the permission overwrite in
* @param overwriteId - The id of the user or role to edit the permission overwrite for
* @param body - The data for editing the permission overwrite
* @param options - The options for editing the permission overwrite
*/
public async editPermissionOverwrite(
channelId: Snowflake,
overwriteId: Snowflake,
body: RESTPutAPIChannelPermissionJSONBody,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
await this.rest.put(Routes.channelPermission(channelId, overwriteId), {
auth,
reason,
body,
signal,
});
}
/**
* Deletes the permission overwrite for a user or role in a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-permission}
* @param channelId - The id of the channel to delete the permission overwrite in
* @param overwriteId - The id of the user or role to delete the permission overwrite for
* @param options - The options for deleting the permission overwrite
*/
public async deletePermissionOverwrite(
channelId: Snowflake,
overwriteId: Snowflake,
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelPermission(channelId, overwriteId), {
auth,
reason,
signal,
});
}
/**
* Sends a soundboard sound in a channel
*
* @see {@link https://discord.com/developers/docs/resources/soundboard#send-soundboard-sound}
* @param channelId - The id of the channel to send the soundboard sound in
* @param body - The data for sending the soundboard sound
* @param options - The options for sending the soundboard sound
*/
public async sendSoundboardSound(
channelId: Snowflake,
body: RESTPostAPISoundboardSendSoundJSONBody,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.post(Routes.sendSoundboardSound(channelId), {
auth,
body,
signal,
});
}
/**
* Adds a recipient to a group DM channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#group-dm-add-recipient}
* @param channelId - The id of the channel to add the recipient to
* @param userId - The id of the user to add as a recipient
* @param body - The data for adding the recipient
* @param options - The options for adding the recipient
*/
public async addGroupDMRecipient(
channelId: Snowflake,
userId: Snowflake,
body: RESTPutAPIChannelRecipientJSONBody,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.put(Routes.channelRecipient(channelId, userId), {
auth,
body,
signal,
});
}
/**
* Removes a recipient from a group DM channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient}
* @param channelId - The id of the channel to remove the recipient from
* @param userId - The id of the user to remove as a recipient
* @param options - The options for removing the recipient
*/
public async removeGroupDMRecipient(
channelId: Snowflake,
userId: Snowflake,
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelRecipient(channelId, userId), {
auth,
signal,
});
}
}