Rust_Discord_API/utils/channel.rs
1use reqwest::Client;
2use serde_json::Value;
3use std::error::Error;
4
5/// Fetches information about a Discord channel.
6///
7/// # Arguments
8///
9/// * `client` - The HTTP client used to send the request.
10/// * `token` - The bot token for authentication.
11/// * `channel_id` - The ID of the channel to fetch information for.
12///
13/// # Returns
14///
15/// A result containing the channel information as a JSON value.
16#[allow(dead_code)]
17pub async fn fetch_channel_info(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
18 let url = format!("https://discord.com/api/v9/channels/{}", channel_id);
19 let response: Value = client.get(&url)
20 .bearer_auth(token)
21 .send()
22 .await?
23 .json()
24 .await?;
25
26 Ok(response)
27}
28
29/// Modifies a Discord channel.
30///
31/// # Arguments
32///
33/// * `client` - The HTTP client used to send the request.
34/// * `token` - The bot token for authentication.
35/// * `channel_id` - The ID of the channel to modify.
36/// * `settings` - The JSON value of the settings to update.
37///
38/// # Returns
39///
40/// A result indicating success or failure.
41#[allow(dead_code)]
42pub async fn modify_channel(client: &Client, token: &str, channel_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
43 let url = format!("https://discord.com/api/v9/channels/{}", channel_id);
44
45 client.patch(&url)
46 .bearer_auth(token)
47 .json(&settings)
48 .send()
49 .await?
50 .error_for_status()?;
51
52 Ok(())
53}
54
55/// Deletes a Discord channel.
56///
57/// # Arguments
58///
59/// * `client` - The HTTP client used to send the request.
60/// * `token` - The bot token for authentication.
61/// * `channel_id` - The ID of the channel to delete.
62///
63/// # Returns
64///
65/// A result indicating success or failure.
66#[allow(dead_code)]
67pub async fn delete_channel(client: &Client, token: &str, channel_id: &str) -> Result<(), Box<dyn Error>> {
68 let url = format!("https://discord.com/api/v9/channels/{}", channel_id);
69
70 client.delete(&url)
71 .bearer_auth(token)
72 .send()
73 .await?
74 .error_for_status()?;
75
76 Ok(())
77}
78
79/// Fetches messages from a Discord channel.
80///
81/// # Arguments
82///
83/// * `client` - The HTTP client used to send the request.
84/// * `token` - The bot token for authentication.
85/// * `channel_id` - The ID of the channel to fetch messages from.
86///
87/// # Returns
88///
89/// A result containing the channel messages as a JSON value.
90#[allow(dead_code)]
91pub async fn get_channel_messages(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
92 let url = format!("https://discord.com/api/v9/channels/{}/messages", channel_id);
93 let response: Value = client.get(&url)
94 .bearer_auth(token)
95 .send()
96 .await?
97 .json()
98 .await?;
99
100 Ok(response)
101}
102
103/// Fetches a single message from a Discord channel.
104///
105/// # Arguments
106///
107/// * `client` - The HTTP client used to send the request.
108/// * `token` - The bot token for authentication.
109/// * `channel_id` - The ID of the channel where the message is located.
110/// * `message_id` - The ID of the message to fetch.
111///
112/// # Returns
113///
114/// A result containing the message information as a JSON value.
115#[allow(dead_code)]
116pub async fn get_channel_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<Value, Box<dyn Error>> {
117 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}", channel_id, message_id);
118 let response: Value = client.get(&url)
119 .bearer_auth(token)
120 .send()
121 .await?
122 .json()
123 .await?;
124
125 Ok(response)
126}
127
128/// Crossposts a message in an Announcement Channel.
129///
130/// # Arguments
131///
132/// * `client` - The HTTP client used to send the request.
133/// * `token` - The bot token for authentication.
134/// * `channel_id` - The ID of the announcement channel.
135/// * `message_id` - The ID of the message to crosspost.
136///
137/// # Returns
138///
139/// A result indicating success or failure.
140#[allow(dead_code)]
141pub async fn crosspost_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
142 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/crosspost", channel_id, message_id);
143
144 client.post(&url)
145 .bearer_auth(token)
146 .send()
147 .await?
148 .error_for_status()?;
149
150 Ok(())
151}
152
153/// Creates a reaction for a message.
154///
155/// # Arguments
156///
157/// * `client` - The HTTP client used to send the request.
158/// * `token` - The bot token for authentication.
159/// * `channel_id` - The ID of the channel where the message is located.
160/// * `message_id` - The ID of the message to react to.
161/// * `emoji` - The emoji to react with.
162///
163/// # Returns
164///
165/// A result indicating success or failure.
166#[allow(dead_code)]
167pub async fn create_reaction(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str) -> Result<(), Box<dyn Error>> {
168 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}/@me", channel_id, message_id, emoji);
169
170 client.put(&url)
171 .bearer_auth(token)
172 .send()
173 .await?
174 .error_for_status()?;
175
176 Ok(())
177}
178
179/// Deletes the bot's reaction to a message.
180///
181/// # Arguments
182///
183/// * `client` - The HTTP client used to send the request.
184/// * `token` - The bot token for authentication.
185/// * `channel_id` - The ID of the channel where the message is located.
186/// * `message_id` - The ID of the message to remove the reaction from.
187/// * `emoji` - The emoji to remove.
188///
189/// # Returns
190///
191/// A result indicating success or failure.
192#[allow(dead_code)]
193pub async fn delete_own_reaction(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str) -> Result<(), Box<dyn Error>> {
194 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}/@me", channel_id, message_id, emoji);
195
196 client.delete(&url)
197 .bearer_auth(token)
198 .send()
199 .await?
200 .error_for_status()?;
201
202 Ok(())
203}
204
205/// Deletes a user's reaction to a message.
206///
207/// # Arguments
208///
209/// * `client` - The HTTP client used to send the request.
210/// * `token` - The bot token for authentication.
211/// * `channel_id` - The ID of the channel where the message is located.
212/// * `message_id` - The ID of the message to remove the reaction from.
213/// * `emoji` - The emoji to remove.
214/// * `user_id` - The ID of the user whose reaction to remove.
215///
216/// # Returns
217///
218/// A result indicating success or failure.
219#[allow(dead_code)]
220pub async fn delete_user_reaction(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
221 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}/{}", channel_id, message_id, emoji, user_id);
222
223 client.delete(&url)
224 .bearer_auth(token)
225 .send()
226 .await?
227 .error_for_status()?;
228
229 Ok(())
230}
231
232/// Gets all reactions for a message.
233///
234/// # Arguments
235///
236/// * `client` - The HTTP client used to send the request.
237/// * `token` - The bot token for authentication.
238/// * `channel_id` - The ID of the channel where the message is located.
239/// * `message_id` - The ID of the message to get reactions for.
240///
241/// # Returns
242///
243/// A result containing the reactions as a JSON value.
244#[allow(dead_code)]
245pub async fn get_reactions(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<Value, Box<dyn Error>> {
246 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions", channel_id, message_id);
247 let response: Value = client.get(&url)
248 .bearer_auth(token)
249 .send()
250 .await?
251 .json()
252 .await?;
253
254 Ok(response)
255}
256
257/// Deletes all reactions for a message.
258///
259/// # Arguments
260///
261/// * `client` - The HTTP client used to send the request.
262/// * `token` - The bot token for authentication.
263/// * `channel_id` - The ID of the channel where the message is located.
264/// * `message_id` - The ID of the message to delete reactions from.
265///
266/// # Returns
267///
268/// A result indicating success or failure.
269#[allow(dead_code)]
270pub async fn delete_all_reactions(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
271 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions", channel_id, message_id);
272
273 client.delete(&url)
274 .bearer_auth(token)
275 .send()
276 .await?
277 .error_for_status()?;
278
279 Ok(())
280}
281
282/// Deletes all reactions for a message with a specific emoji.
283///
284/// # Arguments
285///
286/// * `client` - The HTTP client used to send the request.
287/// * `token` - The bot token for authentication.
288/// * `channel_id` - The ID of the channel where the message is located.
289/// * `message_id` - The ID of the message to delete reactions from.
290/// * `emoji` - The emoji to remove reactions for.
291///
292/// # Returns
293///
294/// A result indicating success or failure.
295#[allow(dead_code)]
296pub async fn delete_all_reactions_for_emoji(client: &Client, token: &str, channel_id: &str, message_id: &str, emoji: &str) -> Result<(), Box<dyn Error>> {
297 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/reactions/{}", channel_id, message_id, emoji);
298
299 client.delete(&url)
300 .bearer_auth(token)
301 .send()
302 .await?
303 .error_for_status()?;
304
305 Ok(())
306}
307
308/// Edits a message in a specified Discord channel.
309///
310/// # Arguments
311///
312/// * `client` - The HTTP client used to send the request.
313/// * `token` - The bot token for authentication.
314/// * `channel_id` - The ID of the channel where the message is located.
315/// * `message_id` - The ID of the message to edit.
316/// * `new_content` - The new content of the message.
317///
318/// # Returns
319///
320/// A result indicating success or failure.
321#[allow(dead_code)]
322pub async fn edit_message(client: &Client, token: &str, channel_id: &str, message_id: &str, new_content: &str) -> Result<(), Box<dyn Error>> {
323 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}", channel_id, message_id);
324 let body = serde_json::json!({ "content": new_content });
325
326 client.patch(&url)
327 .bearer_auth(token)
328 .json(&body)
329 .send()
330 .await?
331 .error_for_status()?;
332
333 Ok(())
334}
335
336/// Deletes a message in a specified Discord channel.
337///
338/// # Arguments
339///
340/// * `client` - The HTTP client used to send the request.
341/// * `token` - The bot token for authentication.
342/// * `channel_id` - The ID of the channel where the message is located.
343/// * `message_id` - The ID of the message to delete.
344///
345/// # Returns
346///
347/// A result indicating success or failure.
348#[allow(dead_code)]
349pub async fn delete_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
350 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}", channel_id, message_id);
351
352 client.delete(&url)
353 .bearer_auth(token)
354 .send()
355 .await?
356 .error_for_status()?;
357
358 Ok(())
359}
360
361/// Bulk deletes messages in a specified Discord channel.
362///
363/// # Arguments
364///
365/// * `client` - The HTTP client used to send the request.
366/// * `token` - The bot token for authentication.
367/// * `channel_id` - The ID of the channel where the messages are located.
368/// * `message_ids` - A list of message IDs to delete.
369///
370/// # Returns
371///
372/// A result indicating success or failure.
373#[allow(dead_code)]
374pub async fn bulk_delete_messages(client: &Client, token: &str, channel_id: &str, message_ids: Vec<&str>) -> Result<(), Box<dyn Error>> {
375 let url = format!("https://discord.com/api/v9/channels/{}/messages/bulk-delete", channel_id);
376 let body = serde_json::json!({ "messages": message_ids });
377
378 client.post(&url)
379 .bearer_auth(token)
380 .json(&body)
381 .send()
382 .await?
383 .error_for_status()?;
384
385 Ok(())
386}
387
388/// Edits channel permissions.
389///
390/// # Arguments
391///
392/// * `client` - The HTTP client used to send the request.
393/// * `token` - The bot token for authentication.
394/// * `channel_id` - The ID of the channel to edit permissions for.
395/// * `overwrite_id` - The ID of the overwrite to edit.
396/// * `permissions` - The JSON value of the permissions to update.
397///
398/// # Returns
399///
400/// A result indicating success or failure.
401#[allow(dead_code)]
402pub async fn edit_channel_permissions(client: &Client, token: &str, channel_id: &str, overwrite_id: &str, permissions: Value) -> Result<(), Box<dyn Error>> {
403 let url = format!("https://discord.com/api/v9/channels/{}/permissions/{}", channel_id, overwrite_id);
404
405 client.put(&url)
406 .bearer_auth(token)
407 .json(&permissions)
408 .send()
409 .await?
410 .error_for_status()?;
411
412 Ok(())
413}
414
415/// Fetches channel invites.
416///
417/// # Arguments
418///
419/// * `client` - The HTTP client used to send the request.
420/// * `token` - The bot token for authentication.
421/// * `channel_id` - The ID of the channel to fetch invites for.
422///
423/// # Returns
424///
425/// A result containing the channel invites as a JSON value.
426#[allow(dead_code)]
427pub async fn get_channel_invites(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
428 let url = format!("https://discord.com/api/v9/channels/{}/invites", channel_id);
429 let response: Value = client.get(&url)
430 .bearer_auth(token)
431 .send()
432 .await?
433 .json()
434 .await?;
435
436 Ok(response)
437}
438
439/// Creates a channel invite.
440///
441/// # Arguments
442///
443/// * `client` - The HTTP client used to send the request.
444/// * `token` - The bot token for authentication.
445/// * `channel_id` - The ID of the channel to create an invite for.
446/// * `invite_settings` - The JSON value of the invite settings.
447///
448/// # Returns
449///
450/// A result containing the created invite as a JSON value.
451#[allow(dead_code)]
452pub async fn create_channel_invite(client: &Client, token: &str, channel_id: &str, invite_settings: Value) -> Result<Value, Box<dyn Error>> {
453 let url = format!("https://discord.com/api/v9/channels/{}/invites", channel_id);
454 let response: Value = client.post(&url)
455 .bearer_auth(token)
456 .json(&invite_settings)
457 .send()
458 .await?
459 .json()
460 .await?;
461
462 Ok(response)
463}
464
465/// Deletes a channel permission overwrite.
466///
467/// # Arguments
468///
469/// * `client` - The HTTP client used to send the request.
470/// * `token` - The bot token for authentication.
471/// * `channel_id` - The ID of the channel to delete the permission overwrite for.
472/// * `overwrite_id` - The ID of the overwrite to delete.
473///
474/// # Returns
475///
476/// A result indicating success or failure.
477#[allow(dead_code)]
478pub async fn delete_channel_permission(client: &Client, token: &str, channel_id: &str, overwrite_id: &str) -> Result<(), Box<dyn Error>> {
479 let url = format!("https://discord.com/api/v9/channels/{}/permissions/{}", channel_id, overwrite_id);
480
481 client.delete(&url)
482 .bearer_auth(token)
483 .send()
484 .await?
485 .error_for_status()?;
486
487 Ok(())
488}
489
490/// Follows an announcement channel.
491///
492/// # Arguments
493///
494/// * `client` - The HTTP client used to send the request.
495/// * `token` - The bot token for authentication.
496/// * `channel_id` - The ID of the announcement channel to follow.
497/// * `webhook_channel_id` - The ID of the channel to send messages to.
498///
499/// # Returns
500///
501/// A result containing the follow response as a JSON value.
502#[allow(dead_code)]
503pub async fn follow_announcement_channel(client: &Client, token: &str, channel_id: &str, webhook_channel_id: &str) -> Result<Value, Box<dyn Error>> {
504 let url = format!("https://discord.com/api/v9/channels/{}/followers", channel_id);
505 let body = serde_json::json!({ "webhook_channel_id": webhook_channel_id });
506 let response: Value = client.post(&url)
507 .bearer_auth(token)
508 .json(&body)
509 .send()
510 .await?
511 .json()
512 .await?;
513
514 Ok(response)
515}
516
517/// Triggers a typing indicator in a specified Discord channel.
518///
519/// # Arguments
520///
521/// * `client` - The HTTP client used to send the request.
522/// * `token` - The bot token for authentication.
523/// * `channel_id` - The ID of the channel to trigger the typing indicator in.
524///
525/// # Returns
526///
527/// A result indicating success or failure.
528#[allow(dead_code)]
529pub async fn trigger_typing_indicator(client: &Client, token: &str, channel_id: &str) -> Result<(), Box<dyn Error>> {
530 let url = format!("https://discord.com/api/v9/channels/{}/typing", channel_id);
531
532 client.post(&url)
533 .bearer_auth(token)
534 .send()
535 .await?
536 .error_for_status()?;
537
538 Ok(())
539}
540
541/// Fetches pinned messages from a Discord channel.
542///
543/// # Arguments
544///
545/// * `client` - The HTTP client used to send the request.
546/// * `token` - The bot token for authentication.
547/// * `channel_id` - The ID of the channel to fetch pinned messages from.
548///
549/// # Returns
550///
551/// A result containing the pinned messages as a JSON value.
552#[allow(dead_code)]
553pub async fn get_pinned_messages(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
554 let url = format!("https://discord.com/api/v9/channels/{}/pins", channel_id);
555 let response: Value = client.get(&url)
556 .bearer_auth(token)
557 .send()
558 .await?
559 .json()
560 .await?;
561
562 Ok(response)
563}
564
565/// Pins a message in a specified Discord channel.
566///
567/// # Arguments
568///
569/// * `client` - The HTTP client used to send the request.
570/// * `token` - The bot token for authentication.
571/// * `channel_id` - The ID of the channel where the message is located.
572/// * `message_id` - The ID of the message to pin.
573///
574/// # Returns
575///
576/// A result indicating success or failure.
577#[allow(dead_code)]
578pub async fn pin_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
579 let url = format!("https://discord.com/api/v9/channels/{}/pins/{}", channel_id, message_id);
580
581 client.put(&url)
582 .bearer_auth(token)
583 .send()
584 .await?
585 .error_for_status()?;
586
587 Ok(())
588}
589
590/// Unpins a message in a specified Discord channel.
591///
592/// # Arguments
593///
594/// * `client` - The HTTP client used to send the request.
595/// * `token` - The bot token for authentication.
596/// * `channel_id` - The ID of the channel where the message is located.
597/// * `message_id` - The ID of the message to unpin.
598///
599/// # Returns
600///
601/// A result indicating success or failure.
602#[allow(dead_code)]
603pub async fn unpin_message(client: &Client, token: &str, channel_id: &str, message_id: &str) -> Result<(), Box<dyn Error>> {
604 let url = format!("https://discord.com/api/v9/channels/{}/pins/{}", channel_id, message_id);
605
606 client.delete(&url)
607 .bearer_auth(token)
608 .send()
609 .await?
610 .error_for_status()?;
611
612 Ok(())
613}
614
615/// Adds a recipient to a Group DM.
616///
617/// # Arguments
618///
619/// * `client` - The HTTP client used to send the request.
620/// * `token` - The bot token for authentication.
621/// * `channel_id` - The ID of the Group DM.
622/// * `user_id` - The ID of the user to add.
623/// * `access_token` - The OAuth2 access token of the user.
624/// * `nick` - The nickname of the user.
625///
626/// # Returns
627///
628/// A result indicating success or failure.
629#[allow(dead_code)]
630pub async fn group_dm_add_recipient(client: &Client, token: &str, channel_id: &str, user_id: &str, access_token: &str, nick: &str) -> Result<(), Box<dyn Error>> {
631 let url = format!("https://discord.com/api/v9/channels/{}/recipients/{}", channel_id, user_id);
632 let body = serde_json::json!({ "access_token": access_token, "nick": nick });
633
634 client.put(&url)
635 .bearer_auth(token)
636 .json(&body)
637 .send()
638 .await?
639 .error_for_status()?;
640
641 Ok(())
642}
643
644/// Removes a recipient from a Group DM.
645///
646/// # Arguments
647///
648/// * `client` - The HTTP client used to send the request.
649/// * `token` - The bot token for authentication.
650/// * `channel_id` - The ID of the Group DM.
651/// * `user_id` - The ID of the user to remove.
652///
653/// # Returns
654///
655/// A result indicating success or failure.
656#[allow(dead_code)]
657pub async fn group_dm_remove_recipient(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
658 let url = format!("https://discord.com/api/v9/channels/{}/recipients/{}", channel_id, user_id);
659
660 client.delete(&url)
661 .bearer_auth(token)
662 .send()
663 .await?
664 .error_for_status()?;
665
666 Ok(())
667}
668
669/// Starts a thread from an existing message.
670///
671/// # Arguments
672///
673/// * `client` - The HTTP client used to send the request.
674/// * `token` - The bot token for authentication.
675/// * `channel_id` - The ID of the channel where the message is located.
676/// * `message_id` - The ID of the message to start the thread from.
677/// * `thread_settings` - The JSON value of the thread settings.
678///
679/// # Returns
680///
681/// A result containing the created thread information as a JSON value.
682#[allow(dead_code)]
683pub async fn start_thread_from_message(client: &Client, token: &str, channel_id: &str, message_id: &str, thread_settings: Value) -> Result<Value, Box<dyn Error>> {
684 let url = format!("https://discord.com/api/v9/channels/{}/messages/{}/threads", channel_id, message_id);
685 let response: Value = client.post(&url)
686 .bearer_auth(token)
687 .json(&thread_settings)
688 .send()
689 .await?
690 .json()
691 .await?;
692
693 Ok(response)
694}
695
696/// Starts a thread without an existing message.
697///
698/// # Arguments
699///
700/// * `client` - The HTTP client used to send the request.
701/// * `token` - The bot token for authentication.
702/// * `channel_id` - The ID of the channel to start the thread in.
703/// * `thread_settings` - The JSON value of the thread settings.
704///
705/// # Returns
706///
707/// A result containing the created thread information as a JSON value.
708#[allow(dead_code)]
709pub async fn start_thread_without_message(client: &Client, token: &str, channel_id: &str, thread_settings: Value) -> Result<Value, Box<dyn Error>> {
710 let url = format!("https://discord.com/api/v9/channels/{}/threads", channel_id);
711 let response: Value = client.post(&url)
712 .bearer_auth(token)
713 .json(&thread_settings)
714 .send()
715 .await?
716 .json()
717 .await?;
718
719 Ok(response)
720}
721
722/// Joins a thread.
723///
724/// # Arguments
725///
726/// * `client` - The HTTP client used to send the request.
727/// * `token` - The bot token for authentication.
728/// * `channel_id` - The ID of the thread to join.
729///
730/// # Returns
731///
732/// A result indicating success or failure.
733#[allow(dead_code)]
734pub async fn join_thread(client: &Client, token: &str, channel_id: &str) -> Result<(), Box<dyn Error>> {
735 let url = format!("https://discord.com/api/v9/channels/{}/thread-members/@me", channel_id);
736
737 client.put(&url)
738 .bearer_auth(token)
739 .send()
740 .await?
741 .error_for_status()?;
742
743 Ok(())
744}
745
746/// Adds a member to a thread.
747///
748/// # Arguments
749///
750/// * `client` - The HTTP client used to send the request.
751/// * `token` - The bot token for authentication.
752/// * `channel_id` - The ID of the thread.
753/// * `user_id` - The ID of the user to add.
754///
755/// # Returns
756///
757/// A result indicating success or failure.
758#[allow(dead_code)]
759pub async fn add_thread_member(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
760 let url = format!("https://discord.com/api/v9/channels/{}/thread-members/{}", channel_id, user_id);
761
762 client.put(&url)
763 .bearer_auth(token)
764 .send()
765 .await?
766 .error_for_status()?;
767
768 Ok(())
769}
770
771/// Removes a member from a thread.
772///
773/// # Arguments
774///
775/// * `client` - The HTTP client used to send the request.
776/// * `token` - The bot token for authentication.
777/// * `channel_id` - The ID of the thread.
778/// * `user_id` - The ID of the user to remove.
779///
780/// # Returns
781///
782/// A result indicating success or failure.
783#[allow(dead_code)]
784pub async fn remove_thread_member(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
785 let url = format!("https://discord.com/api/v9/channels/{}/thread-members/{}", channel_id, user_id);
786
787 client.delete(&url)
788 .bearer_auth(token)
789 .send()
790 .await?
791 .error_for_status()?;
792
793 Ok(())
794}
795
796/// Gets information about a thread member.
797///
798/// # Arguments
799///
800/// * `client` - The HTTP client used to send the request.
801/// * `token` - The bot token for authentication.
802/// * `channel_id` - The ID of the thread.
803/// * `user_id` - The ID of the user to get information for.
804///
805/// # Returns
806///
807/// A result containing the thread member information as a JSON value.
808#[allow(dead_code)]
809pub async fn get_thread_member(client: &Client, token: &str, channel_id: &str, user_id: &str) -> Result<Value, Box<dyn Error>> {
810 let url = format!("https://discord.com/api/v9/channels/{}/thread-members/{}", channel_id, user_id);
811 let response: Value = client.get(&url)
812 .bearer_auth(token)
813 .send()
814 .await?
815 .json()
816 .await?;
817
818 Ok(response)
819}
820
821/// Lists members of a thread.
822///
823/// # Arguments
824///
825/// * `client` - The HTTP client used to send the request.
826/// * `token` - The bot token for authentication.
827/// * `channel_id` - The ID of the thread.
828///
829/// # Returns
830///
831/// A result containing the list of thread members as a JSON value.
832#[allow(dead_code)]
833pub async fn list_thread_members(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
834 let url = format!("https://discord.com/api/v9/channels/{}/thread-members", channel_id);
835 let response: Value = client.get(&url)
836 .bearer_auth(token)
837 .send()
838 .await?
839 .json()
840 .await?;
841
842 Ok(response)
843}
844
845/// Lists public archived threads in a channel.
846///
847/// # Arguments
848///
849/// * `client` - The HTTP client used to send the request.
850/// * `token` - The bot token for authentication.
851/// * `channel_id` - The ID of the channel.
852///
853/// # Returns
854///
855/// A result containing the list of public archived threads as a JSON value.
856#[allow(dead_code)]
857pub async fn list_public_archived_threads(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
858 let url = format!("https://discord.com/api/v9/channels/{}/threads/archived/public", channel_id);
859 let response: Value = client.get(&url)
860 .bearer_auth(token)
861 .send()
862 .await?
863 .json()
864 .await?;
865
866 Ok(response)
867}
868
869/// Lists private archived threads in a channel.
870///
871/// # Arguments
872///
873/// * `client` - The HTTP client used to send the request.
874/// * `token` - The bot token for authentication.
875/// * `channel_id` - The ID of the channel.
876///
877/// # Returns
878///
879/// A result containing the list of private archived threads as a JSON value.
880#[allow(dead_code)]
881pub async fn list_private_archived_threads(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
882 let url = format!("https://discord.com/api/v9/channels/{}/threads/archived/private", channel_id);
883 let response: Value = client.get(&url)
884 .bearer_auth(token)
885 .send()
886 .await?
887 .json()
888 .await?;
889
890 Ok(response)
891}
892
893/// Lists joined private archived threads.
894///
895/// # Arguments
896///
897/// * `client` - The HTTP client used to send the request.
898/// * `token` - The bot token for authentication.
899/// * `channel_id` - The ID of the channel.
900///
901/// # Returns
902///
903/// A result containing the list of joined private archived threads as a JSON value.
904#[allow(dead_code)]
905pub async fn list_joined_private_archived_threads(client: &Client, token: &str, channel_id: &str) -> Result<Value, Box<dyn Error>> {
906 let url = format!("https://discord.com/api/v9/channels/{}/users/@me/threads/archived/private", channel_id);
907 let response: Value = client.get(&url)
908 .bearer_auth(token)
909 .send()
910 .await?
911 .json()
912 .await?;
913
914 Ok(response)
915}