Skip to main content

djs_rest/endpoints/
channel.rs

1//! [Channel endpoints](https://docs.discord.com/developers/resources/channel): channels,
2//! permission overwrites, invites, group DMs and threads.
3//!
4//! Creating guild channels and listing a guild's channels or active threads are guild
5//! endpoints.
6
7use djs_model::{
8    channel::{Channel, FollowedChannel, ThreadMember},
9    id::{ChannelId, GenericId, MessageId, RoleId, UserId},
10    invite::InviteWithMetadata,
11    permissions::Permissions,
12    rest::{
13        ArchivedThreads, CreateChannelInvite, EditChannelPermissions, FollowAnnouncementChannel,
14        ForumThread, GetChannelPermissions, GetThreadMember, GroupDmAddRecipient,
15        ListArchivedThreads, ListJoinedPrivateArchivedThreads, ListThreadMembers, ModifyGroupDm,
16        ModifyGuildChannel, ModifyThread, SetVoiceChannelStatus, StartThreadFromMessage,
17        StartThreadInForumOrMediaChannel, StartThreadWithoutMessage,
18    },
19};
20
21use super::PermissionsResponse;
22use crate::client::boxed;
23use crate::{Error, Request, Rest, Route};
24
25impl Rest {
26    /// [Get Channel](https://docs.discord.com/developers/resources/channel#get-channel):
27    /// returns a channel; for a thread the current user joined, with their
28    /// [`ThreadMember`].
29    ///
30    /// discord.js counterpart: `ChannelManager#fetch`.
31    ///
32    /// # Errors
33    ///
34    /// See [`Rest::request`]; `10003` Unknown Channel, `50001` Missing Access.
35    pub fn get_channel(
36        &self,
37        channel_id: ChannelId,
38    ) -> impl Future<Output = Result<Channel, Error>> + Send + '_ {
39        boxed(async move {
40            self.call(Request::new(Route::GetChannel { channel_id }))
41                .await
42        })
43    }
44
45    /// [Modify Channel](https://docs.discord.com/developers/resources/channel#modify-channel)
46    /// of a guild channel (D-109): changes the fields set in `body`. Needs
47    /// `MANAGE_CHANNELS`, and `MANAGE_ROLES` to change permission overwrites.
48    ///
49    /// `reason` is shown in the audit log (D-086).
50    ///
51    /// discord.js counterpart: `GuildChannel#edit`.
52    ///
53    /// # Examples
54    ///
55    /// ```no_run
56    /// # async fn example(rest: djs_rest::Rest, channel_id: djs_model::id::ChannelId) -> Result<(), djs_rest::Error> {
57    /// use djs_model::{rest::ModifyGuildChannel, util::Patch};
58    ///
59    /// let mut body = ModifyGuildChannel::default();
60    /// body.topic = Patch::Set("Rust bots only".into());
61    /// body.rate_limit_per_user = Patch::Set(30);
62    /// rest.modify_channel(channel_id, &body, Some("Calming things down"))
63    ///     .await?;
64    /// # Ok(())
65    /// # }
66    /// ```
67    ///
68    /// # Errors
69    ///
70    /// See [`Rest::request`]; `50035` for an invalid field (see
71    /// [`ApiError::field_errors`](crate::ApiError::field_errors)), `50013` Missing
72    /// Permissions.
73    pub fn modify_channel<'a>(
74        &'a self,
75        channel_id: ChannelId,
76        body: &'a ModifyGuildChannel,
77        reason: Option<&'a str>,
78    ) -> impl Future<Output = Result<Channel, Error>> + Send + 'a {
79        boxed(async move {
80            self.call(
81                Request::new(Route::ModifyChannel { channel_id })
82                    .json(body)?
83                    .reason(reason),
84            )
85            .await
86        })
87    }
88
89    /// [Modify Channel](https://docs.discord.com/developers/resources/channel#modify-channel)
90    /// of a thread (D-109): changes the fields set in `body`. Needs `MANAGE_THREADS`, except
91    /// for unarchiving an unlocked thread; an archived thread must be unarchived by the same
92    /// request.
93    ///
94    /// `reason` is shown in the audit log (D-086).
95    ///
96    /// discord.js counterpart: `ThreadChannel#edit`.
97    ///
98    /// # Errors
99    ///
100    /// See [`Rest::request`]; `50083` when the thread is archived.
101    pub fn modify_thread<'a>(
102        &'a self,
103        channel_id: ChannelId,
104        body: &'a ModifyThread,
105        reason: Option<&'a str>,
106    ) -> impl Future<Output = Result<Channel, Error>> + Send + 'a {
107        boxed(async move {
108            self.call(
109                Request::new(Route::ModifyChannel { channel_id })
110                    .json(body)?
111                    .reason(reason),
112            )
113            .await
114        })
115    }
116
117    /// [Modify Channel](https://docs.discord.com/developers/resources/channel#modify-channel)
118    /// of a group DM (D-109): changes its name or icon.
119    ///
120    /// discord.js counterpart: `PartialGroupDMChannel#edit`.
121    ///
122    /// # Errors
123    ///
124    /// See [`Rest::request`].
125    pub fn modify_group_dm<'a>(
126        &'a self,
127        channel_id: ChannelId,
128        body: &'a ModifyGroupDm,
129    ) -> impl Future<Output = Result<Channel, Error>> + Send + 'a {
130        boxed(async move {
131            self.call(Request::new(Route::ModifyChannel { channel_id }).json(body)?)
132                .await
133        })
134    }
135
136    /// [Delete/Close Channel](https://docs.discord.com/developers/resources/channel#deleteclose-channel):
137    /// deletes a guild channel or thread (for good), or closes a DM; returns the channel.
138    /// Needs `MANAGE_CHANNELS`, or `MANAGE_THREADS` for a thread. The channels of a deleted
139    /// category are kept, without a parent.
140    ///
141    /// `reason` is shown in the audit log (D-086).
142    ///
143    /// discord.js counterpart: `GuildChannel#delete`, `DMChannel#delete`.
144    ///
145    /// # Errors
146    ///
147    /// See [`Rest::request`]; `50074` for the rules, guidelines or community updates
148    /// channel of a community guild.
149    pub fn delete_channel<'a>(
150        &'a self,
151        channel_id: ChannelId,
152        reason: Option<&'a str>,
153    ) -> impl Future<Output = Result<Channel, Error>> + Send + 'a {
154        boxed(async move {
155            self.call(Request::new(Route::DeleteChannel { channel_id }).reason(reason))
156                .await
157        })
158    }
159
160    /// [Get Channel Member Permissions](https://docs.discord.com/developers/resources/channel#get-channel-member-permissions):
161    /// returns a member's permissions in a channel, computed from their roles and the
162    /// channel's overwrites (a thread uses its parent's). Needs `VIEW_CHANNEL` (and `CONNECT`
163    /// in voice and stage channels).
164    ///
165    /// discord.js counterpart: `GuildChannel#permissionsFor(member)` (computed locally).
166    ///
167    /// # Errors
168    ///
169    /// See [`Rest::request`]; `10007` Unknown Member.
170    pub fn get_channel_member_permissions<'a>(
171        &'a self,
172        channel_id: ChannelId,
173        user_id: UserId,
174        query: &'a GetChannelPermissions,
175    ) -> impl Future<Output = Result<Permissions, Error>> + Send + 'a {
176        boxed(async move {
177            let response: PermissionsResponse = self
178                .request(
179                    Request::new(Route::GetChannelMemberPermissions {
180                        channel_id,
181                        user_id,
182                    })
183                    .query(query),
184                )
185                .await?;
186            Ok(response.permissions)
187        })
188    }
189
190    /// [Get Channel Role Permissions](https://docs.discord.com/developers/resources/channel#get-channel-role-permissions):
191    /// returns the permissions of a role together with `@everyone` in a channel, with their
192    /// overwrites applied (other roles and member overwrites are ignored). Needs
193    /// `VIEW_CHANNEL` (and `CONNECT` in voice and stage channels).
194    ///
195    /// discord.js counterpart: `GuildChannel#permissionsFor(role)` (computed locally).
196    ///
197    /// # Errors
198    ///
199    /// See [`Rest::request`]; `10011` Unknown Role.
200    pub fn get_channel_role_permissions<'a>(
201        &'a self,
202        channel_id: ChannelId,
203        role_id: RoleId,
204        query: &'a GetChannelPermissions,
205    ) -> impl Future<Output = Result<Permissions, Error>> + Send + 'a {
206        boxed(async move {
207            let response: PermissionsResponse = self
208                .request(
209                    Request::new(Route::GetChannelRolePermissions {
210                        channel_id,
211                        role_id,
212                    })
213                    .query(query),
214                )
215                .await?;
216            Ok(response.permissions)
217        })
218    }
219
220    /// [Set Voice Channel Status](https://docs.discord.com/developers/resources/channel#set-voice-channel-status):
221    /// sets or removes the status of a voice channel. Needs `SET_VOICE_CHANNEL_STATUS`, and
222    /// `MANAGE_CHANNELS` when the current user is not connected to the channel.
223    ///
224    /// `reason` is shown in the audit log (D-086).
225    ///
226    /// discord.js counterpart: `VoiceChannel#setStatus`.
227    ///
228    /// # Errors
229    ///
230    /// See [`Rest::request`].
231    pub fn set_voice_channel_status<'a>(
232        &'a self,
233        channel_id: ChannelId,
234        body: &'a SetVoiceChannelStatus,
235        reason: Option<&'a str>,
236    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
237        boxed(async move {
238            self.request_ignoring_body(
239                Request::new(Route::SetVoiceChannelStatus { channel_id })
240                    .json(body)?
241                    .reason(reason),
242            )
243            .await
244        })
245    }
246
247    /// [Edit Channel Permissions](https://docs.discord.com/developers/resources/channel#edit-channel-permissions):
248    /// creates or replaces the permission overwrite of a role or member (`overwrite_id`) in
249    /// a guild channel. Needs `MANAGE_ROLES`; only permissions the bot has can be allowed or
250    /// denied, unless it has a `MANAGE_ROLES` overwrite there.
251    ///
252    /// `reason` is shown in the audit log (D-086).
253    ///
254    /// discord.js counterpart: `PermissionOverwriteManager#edit` / `#create`.
255    ///
256    /// # Examples
257    ///
258    /// ```no_run
259    /// # async fn example(rest: djs_rest::Rest, channel_id: djs_model::id::ChannelId, role_id: djs_model::id::RoleId) -> Result<(), djs_rest::Error> {
260    /// use djs_model::{channel::OverwriteType, permissions::Permissions, rest::EditChannelPermissions};
261    ///
262    /// let mut muted = EditChannelPermissions::new(OverwriteType::Role);
263    /// muted.deny = Some(Permissions::SEND_MESSAGES | Permissions::ADD_REACTIONS);
264    /// rest.edit_channel_permissions(channel_id, role_id.cast(), &muted, None)
265    ///     .await?;
266    /// # Ok(())
267    /// # }
268    /// ```
269    ///
270    /// # Errors
271    ///
272    /// See [`Rest::request`]; `50013` Missing Permissions.
273    pub fn edit_channel_permissions<'a>(
274        &'a self,
275        channel_id: ChannelId,
276        overwrite_id: GenericId,
277        body: &'a EditChannelPermissions,
278        reason: Option<&'a str>,
279    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
280        boxed(async move {
281            self.call(
282                Request::new(Route::EditChannelPermissions {
283                    channel_id,
284                    overwrite_id,
285                })
286                .json(body)?
287                .reason(reason),
288            )
289            .await
290        })
291    }
292
293    /// [Delete Channel Permission](https://docs.discord.com/developers/resources/channel#delete-channel-permission):
294    /// removes the permission overwrite of a role or member (`overwrite_id`). Needs
295    /// `MANAGE_ROLES`.
296    ///
297    /// `reason` is shown in the audit log (D-086).
298    ///
299    /// discord.js counterpart: `PermissionOverwriteManager#delete`.
300    ///
301    /// # Errors
302    ///
303    /// See [`Rest::request`].
304    pub fn delete_channel_permission<'a>(
305        &'a self,
306        channel_id: ChannelId,
307        overwrite_id: GenericId,
308        reason: Option<&'a str>,
309    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
310        boxed(async move {
311            self.call(
312                Request::new(Route::DeleteChannelPermission {
313                    channel_id,
314                    overwrite_id,
315                })
316                .reason(reason),
317            )
318            .await
319        })
320    }
321
322    /// [Get Channel Invites](https://docs.discord.com/developers/resources/channel#get-channel-invites):
323    /// returns the invites of a guild channel. Needs `MANAGE_CHANNELS`.
324    ///
325    /// discord.js counterpart: `GuildChannel#fetchInvites`.
326    ///
327    /// # Errors
328    ///
329    /// See [`Rest::request`].
330    pub fn get_channel_invites(
331        &self,
332        channel_id: ChannelId,
333    ) -> impl Future<Output = Result<Vec<InviteWithMetadata>, Error>> + Send + '_ {
334        boxed(async move {
335            self.call(Request::new(Route::GetChannelInvites { channel_id }))
336                .await
337        })
338    }
339
340    /// [Create Channel Invite](https://docs.discord.com/developers/resources/channel#create-channel-invite):
341    /// creates an invite to a guild channel. Needs `CREATE_INSTANT_INVITE` (and
342    /// `MANAGE_ROLES` for [`role_ids`](CreateChannelInvite::role_ids)). With a
343    /// [`target_users_file`](CreateChannelInvite::target_users_file) the request is sent as
344    /// `multipart/form-data` (D-111).
345    ///
346    /// `reason` is shown in the audit log (D-086).
347    ///
348    /// discord.js counterpart: `GuildChannel#createInvite`.
349    ///
350    /// # Examples
351    ///
352    /// ```no_run
353    /// # async fn example(rest: djs_rest::Rest, channel_id: djs_model::id::ChannelId) -> Result<(), djs_rest::Error> {
354    /// use djs_model::rest::CreateChannelInvite;
355    ///
356    /// let mut body = CreateChannelInvite::default();
357    /// body.max_uses = Some(1);
358    /// body.unique = true;
359    /// let invite = rest.create_channel_invite(channel_id, &body, None).await?;
360    /// println!("https://discord.gg/{}", invite.code);
361    /// # Ok(())
362    /// # }
363    /// ```
364    ///
365    /// # Errors
366    ///
367    /// See [`Rest::request`]; `30016` Maximum number of invites reached.
368    pub fn create_channel_invite<'a>(
369        &'a self,
370        channel_id: ChannelId,
371        body: &'a CreateChannelInvite,
372        reason: Option<&'a str>,
373    ) -> impl Future<Output = Result<InviteWithMetadata, Error>> + Send + 'a {
374        boxed(async move {
375            let mut request = Request::new(Route::CreateChannelInvite { channel_id })
376                .json(body)?
377                .reason(reason);
378            if let Some(file) = &body.target_users_file {
379                request = request.form_file("target_users_file", file);
380            }
381            self.call(request).await
382        })
383    }
384
385    /// [Follow Announcement Channel](https://docs.discord.com/developers/resources/channel#follow-announcement-channel):
386    /// publishes the messages of an announcement channel into another channel, through a
387    /// webhook created there. Needs `MANAGE_WEBHOOKS` in the target channel.
388    ///
389    /// `reason` is shown in the audit log (D-086).
390    ///
391    /// discord.js counterpart: `NewsChannel#addFollower`.
392    ///
393    /// # Errors
394    ///
395    /// See [`Rest::request`]; `30007` Maximum number of webhooks reached.
396    pub fn follow_announcement_channel<'a>(
397        &'a self,
398        channel_id: ChannelId,
399        body: &'a FollowAnnouncementChannel,
400        reason: Option<&'a str>,
401    ) -> impl Future<Output = Result<FollowedChannel, Error>> + Send + 'a {
402        boxed(async move {
403            self.call(
404                Request::new(Route::FollowAnnouncementChannel { channel_id })
405                    .json(body)?
406                    .reason(reason),
407            )
408            .await
409        })
410    }
411
412    /// [Trigger Typing Indicator](https://docs.discord.com/developers/resources/channel#trigger-typing-indicator):
413    /// shows "… is typing" for 10 seconds (or until the bot sends a message). Meant for
414    /// commands that take a few seconds to answer.
415    ///
416    /// discord.js counterpart: `TextBasedChannel#sendTyping`.
417    ///
418    /// # Errors
419    ///
420    /// See [`Rest::request`].
421    pub fn trigger_typing_indicator(
422        &self,
423        channel_id: ChannelId,
424    ) -> impl Future<Output = Result<(), Error>> + Send + '_ {
425        boxed(async move {
426            self.request_ignoring_body(Request::new(Route::TriggerTypingIndicator { channel_id }))
427                .await
428        })
429    }
430
431    /// [Group DM Add Recipient](https://docs.discord.com/developers/resources/channel#group-dm-add-recipient):
432    /// adds a user to a group DM with the access token they gave the application
433    /// (`gdm.join` scope).
434    ///
435    /// discord.js counterpart: `PartialGroupDMChannel#addRecipient`.
436    ///
437    /// # Errors
438    ///
439    /// See [`Rest::request`].
440    pub fn group_dm_add_recipient<'a>(
441        &'a self,
442        channel_id: ChannelId,
443        user_id: UserId,
444        body: &'a GroupDmAddRecipient,
445    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
446        boxed(async move {
447            self.request_ignoring_body(
448                Request::new(Route::GroupDmAddRecipient {
449                    channel_id,
450                    user_id,
451                })
452                .json(body)?,
453            )
454            .await
455        })
456    }
457
458    /// [Group DM Remove Recipient](https://docs.discord.com/developers/resources/channel#group-dm-remove-recipient):
459    /// removes a user from a group DM.
460    ///
461    /// discord.js counterpart: `PartialGroupDMChannel#removeRecipient`.
462    ///
463    /// # Errors
464    ///
465    /// See [`Rest::request`].
466    pub fn group_dm_remove_recipient(
467        &self,
468        channel_id: ChannelId,
469        user_id: UserId,
470    ) -> impl Future<Output = Result<(), Error>> + Send + '_ {
471        boxed(async move {
472            self.request_ignoring_body(Request::new(Route::GroupDmRemoveRecipient {
473                channel_id,
474                user_id,
475            }))
476            .await
477        })
478    }
479
480    /// [Start Thread from Message](https://docs.discord.com/developers/resources/channel#start-thread-from-message):
481    /// creates a thread on an existing message (a public thread in a text channel, an
482    /// announcement thread in an announcement channel); the thread gets the message's ID.
483    /// Needs `CREATE_PUBLIC_THREADS`.
484    ///
485    /// `reason` is shown in the audit log (D-086).
486    ///
487    /// discord.js counterpart: `Message#startThread`.
488    ///
489    /// # Errors
490    ///
491    /// See [`Rest::request`]; `160004` when the message already has a thread.
492    pub fn start_thread_from_message<'a>(
493        &'a self,
494        channel_id: ChannelId,
495        message_id: MessageId,
496        body: &'a StartThreadFromMessage,
497        reason: Option<&'a str>,
498    ) -> impl Future<Output = Result<Channel, Error>> + Send + 'a {
499        boxed(async move {
500            self.call(
501                Request::new(Route::StartThreadFromMessage {
502                    channel_id,
503                    message_id,
504                })
505                .json(body)?
506                .reason(reason),
507            )
508            .await
509        })
510    }
511
512    /// [Start Thread without Message](https://docs.discord.com/developers/resources/channel#start-thread-without-message):
513    /// creates a thread that does not start from a message. Needs `CREATE_PUBLIC_THREADS` or
514    /// `CREATE_PRIVATE_THREADS`.
515    ///
516    /// `reason` is shown in the audit log (D-086).
517    ///
518    /// discord.js counterpart: `GuildTextThreadManager#create`.
519    ///
520    /// # Examples
521    ///
522    /// ```no_run
523    /// # async fn example(rest: djs_rest::Rest, channel_id: djs_model::id::ChannelId) -> Result<(), djs_rest::Error> {
524    /// use djs_model::{channel::ChannelType, rest::StartThreadWithoutMessage};
525    ///
526    /// let mut body = StartThreadWithoutMessage::new("Ticket #42", ChannelType::PrivateThread);
527    /// body.invitable = Some(false);
528    /// let thread = rest
529    ///     .start_thread_without_message(channel_id, &body, None)
530    ///     .await?;
531    /// # Ok(())
532    /// # }
533    /// ```
534    ///
535    /// # Errors
536    ///
537    /// See [`Rest::request`]; `160006` Maximum number of active threads reached.
538    pub fn start_thread_without_message<'a>(
539        &'a self,
540        channel_id: ChannelId,
541        body: &'a StartThreadWithoutMessage,
542        reason: Option<&'a str>,
543    ) -> impl Future<Output = Result<Channel, Error>> + Send + 'a {
544        boxed(async move {
545            self.call(
546                Request::new(Route::StartThreadWithoutMessage { channel_id })
547                    .json(body)?
548                    .reason(reason),
549            )
550            .await
551        })
552    }
553
554    /// [Start Thread in Forum or Media Channel](https://docs.discord.com/developers/resources/channel#start-thread-in-forum-or-media-channel):
555    /// creates a post with its first message, and returns both (D-115). The files of the
556    /// message are uploaded with it. Needs `SEND_MESSAGES`.
557    ///
558    /// `reason` is shown in the audit log (D-086).
559    ///
560    /// discord.js counterpart: `GuildForumThreadManager#create`.
561    ///
562    /// # Errors
563    ///
564    /// See [`Rest::request`]; `40067` when the channel requires a tag and none is applied.
565    pub fn start_thread_in_forum_or_media_channel<'a>(
566        &'a self,
567        channel_id: ChannelId,
568        body: &'a StartThreadInForumOrMediaChannel,
569        reason: Option<&'a str>,
570    ) -> impl Future<Output = Result<ForumThread, Error>> + Send + 'a {
571        boxed(async move {
572            self.call(
573                Request::new(Route::StartThreadInForumOrMediaChannel { channel_id })
574                    .json(body)?
575                    .files(&body.message.files)
576                    .reason(reason),
577            )
578            .await
579        })
580    }
581
582    /// [Join Thread](https://docs.discord.com/developers/resources/channel#join-thread):
583    /// adds the current user to a thread that is not archived.
584    ///
585    /// discord.js counterpart: `ThreadMemberManager#add('@me')` / `ThreadChannel#join`.
586    ///
587    /// # Errors
588    ///
589    /// See [`Rest::request`].
590    pub fn join_thread(
591        &self,
592        channel_id: ChannelId,
593    ) -> impl Future<Output = Result<(), Error>> + Send + '_ {
594        boxed(async move {
595            self.call(Request::new(Route::JoinThread { channel_id }))
596                .await
597        })
598    }
599
600    /// [Add Thread Member](https://docs.discord.com/developers/resources/channel#add-thread-member):
601    /// adds a member to a thread that is not archived (also succeeds if they already are
602    /// one). Needs permission to send messages in the thread.
603    ///
604    /// discord.js counterpart: `ThreadMemberManager#add`.
605    ///
606    /// # Errors
607    ///
608    /// See [`Rest::request`].
609    pub fn add_thread_member(
610        &self,
611        channel_id: ChannelId,
612        user_id: UserId,
613    ) -> impl Future<Output = Result<(), Error>> + Send + '_ {
614        boxed(async move {
615            self.call(Request::new(Route::AddThreadMember {
616                channel_id,
617                user_id,
618            }))
619            .await
620        })
621    }
622
623    /// [Leave Thread](https://docs.discord.com/developers/resources/channel#leave-thread):
624    /// removes the current user from a thread that is not archived.
625    ///
626    /// discord.js counterpart: `ThreadChannel#leave`.
627    ///
628    /// # Errors
629    ///
630    /// See [`Rest::request`].
631    pub fn leave_thread(
632        &self,
633        channel_id: ChannelId,
634    ) -> impl Future<Output = Result<(), Error>> + Send + '_ {
635        boxed(async move {
636            self.call(Request::new(Route::LeaveThread { channel_id }))
637                .await
638        })
639    }
640
641    /// [Remove Thread Member](https://docs.discord.com/developers/resources/channel#remove-thread-member):
642    /// removes a member from a thread that is not archived. Needs `MANAGE_THREADS` (or to
643    /// be the creator of a private thread).
644    ///
645    /// discord.js counterpart: `ThreadMemberManager#remove`.
646    ///
647    /// # Errors
648    ///
649    /// See [`Rest::request`].
650    pub fn remove_thread_member(
651        &self,
652        channel_id: ChannelId,
653        user_id: UserId,
654    ) -> impl Future<Output = Result<(), Error>> + Send + '_ {
655        boxed(async move {
656            self.call(Request::new(Route::RemoveThreadMember {
657                channel_id,
658                user_id,
659            }))
660            .await
661        })
662    }
663
664    /// [Get Thread Member](https://docs.discord.com/developers/resources/channel#get-thread-member):
665    /// returns a member of a thread.
666    ///
667    /// discord.js counterpart: `ThreadMemberManager#fetch`.
668    ///
669    /// # Errors
670    ///
671    /// See [`Rest::request`]; `10007` Unknown Member when the user is not in the thread.
672    pub fn get_thread_member<'a>(
673        &'a self,
674        channel_id: ChannelId,
675        user_id: UserId,
676        query: &'a GetThreadMember,
677    ) -> impl Future<Output = Result<ThreadMember, Error>> + Send + 'a {
678        boxed(async move {
679            self.call(
680                Request::new(Route::GetThreadMember {
681                    channel_id,
682                    user_id,
683                })
684                .query(query),
685            )
686            .await
687        })
688    }
689
690    /// [List Thread Members](https://docs.discord.com/developers/resources/channel#list-thread-members):
691    /// returns the members of a thread; with
692    /// [`with_member`](ListThreadMembers::with_member) one page of them, each with their
693    /// guild member. Needs the `GUILD_MEMBERS` privileged intent.
694    ///
695    /// discord.js counterpart: `ThreadMemberManager#fetch()`.
696    ///
697    /// # Errors
698    ///
699    /// See [`Rest::request`].
700    pub fn list_thread_members<'a>(
701        &'a self,
702        channel_id: ChannelId,
703        query: &'a ListThreadMembers,
704    ) -> impl Future<Output = Result<Vec<ThreadMember>, Error>> + Send + 'a {
705        boxed(async move {
706            self.call(Request::new(Route::ListThreadMembers { channel_id }).query(query))
707                .await
708        })
709    }
710
711    /// [List Public Archived Threads](https://docs.discord.com/developers/resources/channel#list-public-archived-threads):
712    /// returns archived public (or announcement) threads of a channel, most recently
713    /// archived first. Needs `READ_MESSAGE_HISTORY`.
714    ///
715    /// discord.js counterpart: `GuildTextThreadManager#fetchArchived({ type: 'public' })`.
716    ///
717    /// # Errors
718    ///
719    /// See [`Rest::request`].
720    pub fn list_public_archived_threads<'a>(
721        &'a self,
722        channel_id: ChannelId,
723        query: &'a ListArchivedThreads,
724    ) -> impl Future<Output = Result<ArchivedThreads, Error>> + Send + 'a {
725        boxed(async move {
726            self.call(Request::new(Route::ListPublicArchivedThreads { channel_id }).query(query))
727                .await
728        })
729    }
730
731    /// [List Private Archived Threads](https://docs.discord.com/developers/resources/channel#list-private-archived-threads):
732    /// returns archived private threads of a channel, most recently archived first. Needs
733    /// `READ_MESSAGE_HISTORY` and `MANAGE_THREADS`.
734    ///
735    /// discord.js counterpart: `GuildTextThreadManager#fetchArchived({ type: 'private' })`.
736    ///
737    /// # Errors
738    ///
739    /// See [`Rest::request`].
740    pub fn list_private_archived_threads<'a>(
741        &'a self,
742        channel_id: ChannelId,
743        query: &'a ListArchivedThreads,
744    ) -> impl Future<Output = Result<ArchivedThreads, Error>> + Send + 'a {
745        boxed(async move {
746            self.call(Request::new(Route::ListPrivateArchivedThreads { channel_id }).query(query))
747                .await
748        })
749    }
750
751    /// [List Joined Private Archived Threads](https://docs.discord.com/developers/resources/channel#list-joined-private-archived-threads):
752    /// returns the archived private threads of a channel that the current user joined,
753    /// highest ID first. Needs `READ_MESSAGE_HISTORY`.
754    ///
755    /// discord.js counterpart:
756    /// `GuildTextThreadManager#fetchArchived({ type: 'private', fetchAll: false })`.
757    ///
758    /// # Errors
759    ///
760    /// See [`Rest::request`].
761    pub fn list_joined_private_archived_threads<'a>(
762        &'a self,
763        channel_id: ChannelId,
764        query: &'a ListJoinedPrivateArchivedThreads,
765    ) -> impl Future<Output = Result<ArchivedThreads, Error>> + Send + 'a {
766        boxed(async move {
767            self.call(
768                Request::new(Route::ListJoinedPrivateArchivedThreads { channel_id }).query(query),
769            )
770            .await
771        })
772    }
773}