Rust_Discord_API/utils/guild.rs
1use reqwest::Client;
2use serde_json::Value;
3use std::error::Error;
4
5/// Creates a new Discord guild.
6///
7/// # Arguments
8///
9/// * `client` - The HTTP client used to send the request.
10/// * `token` - The bot token for authentication.
11/// * `guild_settings` - The JSON value of the guild settings.
12///
13/// # Returns
14///
15/// A result containing the created guild information as a JSON value.
16#[allow(dead_code)]
17pub async fn create_guild(client: &Client, token: &str, guild_settings: Value) -> Result<Value, Box<dyn Error>> {
18 let url = "https://discord.com/api/v9/guilds";
19 let response: Value = client.post(url)
20 .bearer_auth(token)
21 .json(&guild_settings)
22 .send()
23 .await?
24 .json()
25 .await?;
26
27 Ok(response)
28}
29
30/// Fetches information about a Discord guild.
31///
32/// # Arguments
33///
34/// * `client` - The HTTP client used to send the request.
35/// * `token` - The bot token for authentication.
36/// * `guild_id` - The ID of the guild to fetch information for.
37///
38/// # Returns
39///
40/// A result containing the guild information as a JSON value.
41#[allow(dead_code)]
42pub async fn get_guild(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
43 let url = format!("https://discord.com/api/v9/guilds/{}", guild_id);
44 let response: Value = client.get(&url)
45 .bearer_auth(token)
46 .send()
47 .await?
48 .json()
49 .await?;
50
51 Ok(response)
52}
53
54/// Fetches a preview of a Discord guild.
55///
56/// # Arguments
57///
58/// * `client` - The HTTP client used to send the request.
59/// * `token` - The bot token for authentication.
60/// * `guild_id` - The ID of the guild to fetch a preview for.
61///
62/// # Returns
63///
64/// A result containing the guild preview as a JSON value.
65#[allow(dead_code)]
66pub async fn get_guild_preview(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
67 let url = format!("https://discord.com/api/v9/guilds/{}/preview", guild_id);
68 let response: Value = client.get(&url)
69 .bearer_auth(token)
70 .send()
71 .await?
72 .json()
73 .await?;
74
75 Ok(response)
76}
77
78/// Modifies a Discord guild.
79///
80/// # Arguments
81///
82/// * `client` - The HTTP client used to send the request.
83/// * `token` - The bot token for authentication.
84/// * `guild_id` - The ID of the guild to modify.
85/// * `settings` - The JSON value of the settings to update.
86///
87/// # Returns
88///
89/// A result indicating success or failure.
90#[allow(dead_code)]
91pub async fn modify_guild(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
92 let url = format!("https://discord.com/api/v9/guilds/{}", guild_id);
93
94 client.patch(&url)
95 .bearer_auth(token)
96 .json(&settings)
97 .send()
98 .await?
99 .error_for_status()?;
100
101 Ok(())
102}
103
104/// Deletes a Discord guild.
105///
106/// # Arguments
107///
108/// * `client` - The HTTP client used to send the request.
109/// * `token` - The bot token for authentication.
110/// * `guild_id` - The ID of the guild to delete.
111///
112/// # Returns
113///
114/// A result indicating success or failure.
115#[allow(dead_code)]
116pub async fn delete_guild(client: &Client, token: &str, guild_id: &str) -> Result<(), Box<dyn Error>> {
117 let url = format!("https://discord.com/api/v9/guilds/{}", guild_id);
118
119 client.delete(&url)
120 .bearer_auth(token)
121 .send()
122 .await?
123 .error_for_status()?;
124
125 Ok(())
126}
127
128/// Fetches channels of a Discord guild.
129///
130/// # Arguments
131///
132/// * `client` - The HTTP client used to send the request.
133/// * `token` - The bot token for authentication.
134/// * `guild_id` - The ID of the guild to fetch channels for.
135///
136/// # Returns
137///
138/// A result containing the guild channels as a JSON value.
139#[allow(dead_code)]
140pub async fn get_guild_channels(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
141 let url = format!("https://discord.com/api/v9/guilds/{}/channels", guild_id);
142 let response: Value = client.get(&url)
143 .bearer_auth(token)
144 .send()
145 .await?
146 .json()
147 .await?;
148
149 Ok(response)
150}
151
152/// Creates a new channel in a Discord guild.
153///
154/// # Arguments
155///
156/// * `client` - The HTTP client used to send the request.
157/// * `token` - The bot token for authentication.
158/// * `guild_id` - The ID of the guild to create the channel in.
159/// * `channel_settings` - The JSON value of the channel settings.
160///
161/// # Returns
162///
163/// A result containing the created channel information as a JSON value.
164#[allow(dead_code)]
165pub async fn create_guild_channel(client: &Client, token: &str, guild_id: &str, channel_settings: Value) -> Result<Value, Box<dyn Error>> {
166 let url = format!("https://discord.com/api/v9/guilds/{}/channels", guild_id);
167 let response: Value = client.post(&url)
168 .bearer_auth(token)
169 .json(&channel_settings)
170 .send()
171 .await?
172 .json()
173 .await?;
174
175 Ok(response)
176}
177
178/// Modifies the positions of channels in a Discord guild.
179///
180/// # Arguments
181///
182/// * `client` - The HTTP client used to send the request.
183/// * `token` - The bot token for authentication.
184/// * `guild_id` - The ID of the guild to modify channel positions for.
185/// * `positions` - The JSON value of the new positions.
186///
187/// # Returns
188///
189/// A result indicating success or failure.
190#[allow(dead_code)]
191pub async fn modify_guild_channel_positions(client: &Client, token: &str, guild_id: &str, positions: Value) -> Result<(), Box<dyn Error>> {
192 let url = format!("https://discord.com/api/v9/guilds/{}/channels", guild_id);
193
194 client.patch(&url)
195 .bearer_auth(token)
196 .json(&positions)
197 .send()
198 .await?
199 .error_for_status()?;
200
201 Ok(())
202}
203
204/// Lists active threads in a Discord guild.
205///
206/// # Arguments
207///
208/// * `client` - The HTTP client used to send the request.
209/// * `token` - The bot token for authentication.
210/// * `guild_id` - The ID of the guild to list active threads for.
211///
212/// # Returns
213///
214/// A result containing the list of active threads as a JSON value.
215#[allow(dead_code)]
216pub async fn list_active_guild_threads(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
217 let url = format!("https://discord.com/api/v9/guilds/{}/threads/active", guild_id);
218 let response: Value = client.get(&url)
219 .bearer_auth(token)
220 .send()
221 .await?
222 .json()
223 .await?;
224
225 Ok(response)
226}
227
228/// Fetches a member of a Discord guild.
229///
230/// # Arguments
231///
232/// * `client` - The HTTP client used to send the request.
233/// * `token` - The bot token for authentication.
234/// * `guild_id` - The ID of the guild.
235/// * `user_id` - The ID of the member to fetch.
236///
237/// # Returns
238///
239/// A result containing the member information as a JSON value.
240#[allow(dead_code)]
241pub async fn get_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<Value, Box<dyn Error>> {
242 let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
243 let response: Value = client.get(&url)
244 .bearer_auth(token)
245 .send()
246 .await?
247 .json()
248 .await?;
249
250 Ok(response)
251}
252
253/// Lists members of a Discord guild.
254///
255/// # Arguments
256///
257/// * `client` - The HTTP client used to send the request.
258/// * `token` - The bot token for authentication.
259/// * `guild_id` - The ID of the guild.
260///
261/// # Returns
262///
263/// A result containing the list of members as a JSON value.
264#[allow(dead_code)]
265pub async fn list_guild_members(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
266 let url = format!("https://discord.com/api/v9/guilds/{}/members", guild_id);
267 let response: Value = client.get(&url)
268 .bearer_auth(token)
269 .send()
270 .await?
271 .json()
272 .await?;
273
274 Ok(response)
275}
276
277/// Searches for members in a Discord guild.
278///
279/// # Arguments
280///
281/// * `client` - The HTTP client used to send the request.
282/// * `token` - The bot token for authentication.
283/// * `guild_id` - The ID of the guild.
284/// * `query` - The search query string.
285///
286/// # Returns
287///
288/// A result containing the search results as a JSON value.
289#[allow(dead_code)]
290pub async fn search_guild_members(client: &Client, token: &str, guild_id: &str, query: &str) -> Result<Value, Box<dyn Error>> {
291 let url = format!("https://discord.com/api/v9/guilds/{}/members/search?query={}", guild_id, query);
292 let response: Value = client.get(&url)
293 .bearer_auth(token)
294 .send()
295 .await?
296 .json()
297 .await?;
298
299 Ok(response)
300}
301
302/// Adds a member to a Discord guild.
303///
304/// # Arguments
305///
306/// * `client` - The HTTP client used to send the request.
307/// * `token` - The bot token for authentication.
308/// * `guild_id` - The ID of the guild.
309/// * `user_id` - The ID of the user to add.
310/// * `member_settings` - The JSON value of the member settings.
311///
312/// # Returns
313///
314/// A result containing the added member information as a JSON value.
315#[allow(dead_code)]
316pub async fn add_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str, member_settings: Value) -> Result<Value, Box<dyn Error>> {
317 let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
318 let response: Value = client.put(&url)
319 .bearer_auth(token)
320 .json(&member_settings)
321 .send()
322 .await?
323 .json()
324 .await?;
325
326 Ok(response)
327}
328
329/// Modifies a member in a Discord guild.
330///
331/// # Arguments
332///
333/// * `client` - The HTTP client used to send the request.
334/// * `token` - The bot token for authentication.
335/// * `guild_id` - The ID of the guild.
336/// * `user_id` - The ID of the member to modify.
337/// * `settings` - The JSON value of the settings to update.
338///
339/// # Returns
340///
341/// A result indicating success or failure.
342#[allow(dead_code)]
343pub async fn modify_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
344 let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
345
346 client.patch(&url)
347 .bearer_auth(token)
348 .json(&settings)
349 .send()
350 .await?
351 .error_for_status()?;
352
353 Ok(())
354}
355
356/// Modifies the current member in a Discord guild.
357///
358/// # Arguments
359///
360/// * `client` - The HTTP client used to send the request.
361/// * `token` - The bot token for authentication.
362/// * `guild_id` - The ID of the guild.
363/// * `settings` - The JSON value of the settings to update.
364///
365/// # Returns
366///
367/// A result indicating success or failure.
368#[allow(dead_code)]
369pub async fn modify_current_member(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
370 let url = format!("https://discord.com/api/v9/guilds/{}/members/@me", guild_id);
371
372 client.patch(&url)
373 .bearer_auth(token)
374 .json(&settings)
375 .send()
376 .await?
377 .error_for_status()?;
378
379 Ok(())
380}
381
382/// Modifies the current user's nickname in a Discord guild.
383///
384/// # Arguments
385///
386/// * `client` - The HTTP client used to send the request.
387/// * `token` - The bot token for authentication.
388/// * `guild_id` - The ID of the guild.
389/// * `nick` - The new nickname.
390///
391/// # Returns
392///
393/// A result indicating success or failure.
394#[allow(dead_code)]
395pub async fn modify_current_user_nick(client: &Client, token: &str, guild_id: &str, nick: &str) -> Result<(), Box<dyn Error>> {
396 let url = format!("https://discord.com/api/v9/guilds/{}/members/@me/nick", guild_id);
397 let body = serde_json::json!({ "nick": nick });
398
399 client.patch(&url)
400 .bearer_auth(token)
401 .json(&body)
402 .send()
403 .await?
404 .error_for_status()?;
405
406 Ok(())
407}
408
409/// Adds a role to a member in a Discord guild.
410///
411/// # Arguments
412///
413/// * `client` - The HTTP client used to send the request.
414/// * `token` - The bot token for authentication.
415/// * `guild_id` - The ID of the guild.
416/// * `user_id` - The ID of the member to add the role to.
417/// * `role_id` - The ID of the role to add.
418///
419/// # Returns
420///
421/// A result indicating success or failure.
422#[allow(dead_code)]
423pub async fn add_guild_member_role(client: &Client, token: &str, guild_id: &str, user_id: &str, role_id: &str) -> Result<(), Box<dyn Error>> {
424 let url = format!("https://discord.com/api/v9/guilds/{}/members/{}/roles/{}", guild_id, user_id, role_id);
425
426 client.put(&url)
427 .bearer_auth(token)
428 .send()
429 .await?
430 .error_for_status()?;
431
432 Ok(())
433}
434
435/// Removes a role from a member in a Discord guild.
436///
437/// # Arguments
438///
439/// * `client` - The HTTP client used to send the request.
440/// * `token` - The bot token for authentication.
441/// * `guild_id` - The ID of the guild.
442/// * `user_id` - The ID of the member to remove the role from.
443/// * `role_id` - The ID of the role to remove.
444///
445/// # Returns
446///
447/// A result indicating success or failure.
448#[allow(dead_code)]
449pub async fn remove_guild_member_role(client: &Client, token: &str, guild_id: &str, user_id: &str, role_id: &str) -> Result<(), Box<dyn Error>> {
450 let url = format!("https://discord.com/api/v9/guilds/{}/members/{}/roles/{}", guild_id, user_id, role_id);
451
452 client.delete(&url)
453 .bearer_auth(token)
454 .send()
455 .await?
456 .error_for_status()?;
457
458 Ok(())
459}
460
461/// Removes a member from a Discord guild.
462///
463/// # Arguments
464///
465/// * `client` - The HTTP client used to send the request.
466/// * `token` - The bot token for authentication.
467/// * `guild_id` - The ID of the guild.
468/// * `user_id` - The ID of the member to remove.
469///
470/// # Returns
471///
472/// A result indicating success or failure.
473#[allow(dead_code)]
474pub async fn remove_guild_member(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
475 let url = format!("https://discord.com/api/v9/guilds/{}/members/{}", guild_id, user_id);
476
477 client.delete(&url)
478 .bearer_auth(token)
479 .send()
480 .await?
481 .error_for_status()?;
482
483 Ok(())
484}
485
486/// Fetches bans of a Discord guild.
487///
488/// # Arguments
489///
490/// * `client` - The HTTP client used to send the request.
491/// * `token` - The bot token for authentication.
492/// * `guild_id` - The ID of the guild to fetch bans for.
493///
494/// # Returns
495///
496/// A result containing the guild bans as a JSON value.
497#[allow(dead_code)]
498pub async fn get_guild_bans(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
499 let url = format!("https://discord.com/api/v9/guilds/{}/bans", guild_id);
500 let response: Value = client.get(&url)
501 .bearer_auth(token)
502 .send()
503 .await?
504 .json()
505 .await?;
506
507 Ok(response)
508}
509
510/// Fetches a specific ban in a Discord guild.
511///
512/// # Arguments
513///
514/// * `client` - The HTTP client used to send the request.
515/// * `token` - The bot token for authentication.
516/// * `guild_id` - The ID of the guild.
517/// * `user_id` - The ID of the user to fetch the ban for.
518///
519/// # Returns
520///
521/// A result containing the ban information as a JSON value.
522#[allow(dead_code)]
523pub async fn get_guild_ban(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<Value, Box<dyn Error>> {
524 let url = format!("https://discord.com/api/v9/guilds/{}/bans/{}", guild_id, user_id);
525 let response: Value = client.get(&url)
526 .bearer_auth(token)
527 .send()
528 .await?
529 .json()
530 .await?;
531
532 Ok(response)
533}
534
535/// Creates a ban in a Discord guild.
536///
537/// # Arguments
538///
539/// * `client` - The HTTP client used to send the request.
540/// * `token` - The bot token for authentication.
541/// * `guild_id` - The ID of the guild.
542/// * `user_id` - The ID of the user to ban.
543/// * `ban_settings` - The JSON value of the ban settings.
544///
545/// # Returns
546///
547/// A result indicating success or failure.
548#[allow(dead_code)]
549pub async fn create_guild_ban(client: &Client, token: &str, guild_id: &str, user_id: &str, ban_settings: Value) -> Result<(), Box<dyn Error>> {
550 let url = format!("https://discord.com/api/v9/guilds/{}/bans/{}", guild_id, user_id);
551
552 client.put(&url)
553 .bearer_auth(token)
554 .json(&ban_settings)
555 .send()
556 .await?
557 .error_for_status()?;
558
559 Ok(())
560}
561
562/// Removes a ban in a Discord guild.
563///
564/// # Arguments
565///
566/// * `client` - The HTTP client used to send the request.
567/// * `token` - The bot token for authentication.
568/// * `guild_id` - The ID of the guild.
569/// * `user_id` - The ID of the user to unban.
570///
571/// # Returns
572///
573/// A result indicating success or failure.
574#[allow(dead_code)]
575pub async fn remove_guild_ban(client: &Client, token: &str, guild_id: &str, user_id: &str) -> Result<(), Box<dyn Error>> {
576 let url = format!("https://discord.com/api/v9/guilds/{}/bans/{}", guild_id, user_id);
577
578 client.delete(&url)
579 .bearer_auth(token)
580 .send()
581 .await?
582 .error_for_status()?;
583
584 Ok(())
585}
586
587/// Bulk bans users in a Discord guild.
588///
589/// # Arguments
590///
591/// * `client` - The HTTP client used to send the request.
592/// * `token` - The bot token for authentication.
593/// * `guild_id` - The ID of the guild.
594/// * `user_ids` - A list of user IDs to ban.
595///
596/// # Returns
597///
598/// A result indicating success or failure.
599#[allow(dead_code)]
600pub async fn bulk_guild_ban(client: &Client, token: &str, guild_id: &str, user_ids: Vec<&str>) -> Result<(), Box<dyn Error>> {
601 let url = format!("https://discord.com/api/v9/guilds/{}/bans", guild_id);
602 let body = serde_json::json!({ "user_ids": user_ids });
603
604 client.post(&url)
605 .bearer_auth(token)
606 .json(&body)
607 .send()
608 .await?
609 .error_for_status()?;
610
611 Ok(())
612}
613
614/// Fetches roles of a Discord guild.
615///
616/// # Arguments
617///
618/// * `client` - The HTTP client used to send the request.
619/// * `token` - The bot token for authentication.
620/// * `guild_id` - The ID of the guild to fetch roles for.
621///
622/// # Returns
623///
624/// A result containing the guild roles as a JSON value.
625#[allow(dead_code)]
626pub async fn get_guild_roles(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
627 let url = format!("https://discord.com/api/v9/guilds/{}/roles", guild_id);
628 let response: Value = client.get(&url)
629 .bearer_auth(token)
630 .send()
631 .await?
632 .json()
633 .await?;
634
635 Ok(response)
636}
637
638/// Creates a new role in a Discord guild.
639///
640/// # Arguments
641///
642/// * `client` - The HTTP client used to send the request.
643/// * `token` - The bot token for authentication.
644/// * `guild_id` - The ID of the guild to create the role in.
645/// * `role_settings` - The JSON value of the role settings.
646///
647/// # Returns
648///
649/// A result containing the created role information as a JSON value.
650#[allow(dead_code)]
651pub async fn create_guild_role(client: &Client, token: &str, guild_id: &str, role_settings: Value) -> Result<Value, Box<dyn Error>> {
652 let url = format!("https://discord.com/api/v9/guilds/{}/roles", guild_id);
653 let response: Value = client.post(&url)
654 .bearer_auth(token)
655 .json(&role_settings)
656 .send()
657 .await?
658 .json()
659 .await?;
660
661 Ok(response)
662}
663
664/// Modifies the positions of roles in a Discord guild.
665///
666/// # Arguments
667///
668/// * `client` - The HTTP client used to send the request.
669/// * `token` - The bot token for authentication.
670/// * `guild_id` - The ID of the guild to modify role positions for.
671/// * `positions` - The JSON value of the new positions.
672///
673/// # Returns
674///
675/// A result indicating success or failure.
676#[allow(dead_code)]
677pub async fn modify_guild_role_positions(client: &Client, token: &str, guild_id: &str, positions: Value) -> Result<(), Box<dyn Error>> {
678 let url = format!("https://discord.com/api/v9/guilds/{}/roles", guild_id);
679
680 client.patch(&url)
681 .bearer_auth(token)
682 .json(&positions)
683 .send()
684 .await?
685 .error_for_status()?;
686
687 Ok(())
688}
689
690/// Modifies a role in a Discord guild.
691///
692/// # Arguments
693///
694/// * `client` - The HTTP client used to send the request.
695/// * `token` - The bot token for authentication.
696/// * `guild_id` - The ID of the guild.
697/// * `role_id` - The ID of the role to modify.
698/// * `settings` - The JSON value of the settings to update.
699///
700/// # Returns
701///
702/// A result indicating success or failure.
703#[allow(dead_code)]
704pub async fn modify_guild_role(client: &Client, token: &str, guild_id: &str, role_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
705 let url = format!("https://discord.com/api/v9/guilds/{}/roles/{}", guild_id, role_id);
706
707 client.patch(&url)
708 .bearer_auth(token)
709 .json(&settings)
710 .send()
711 .await?
712 .error_for_status()?;
713
714 Ok(())
715}
716
717/// Modifies the MFA level of a Discord guild.
718///
719/// # Arguments
720///
721/// * `client` - The HTTP client used to send the request.
722/// * `token` - The bot token for authentication.
723/// * `guild_id` - The ID of the guild.
724/// * `level` - The new MFA level.
725///
726/// # Returns
727///
728/// A result indicating success or failure.
729#[allow(dead_code)]
730pub async fn modify_guild_mfa_level(client: &Client, token: &str, guild_id: &str, level: u8) -> Result<(), Box<dyn Error>> {
731 let url = format!("https://discord.com/api/v9/guilds/{}/mfa", guild_id);
732 let body = serde_json::json!({ "level": level });
733
734 client.post(&url)
735 .bearer_auth(token)
736 .json(&body)
737 .send()
738 .await?
739 .error_for_status()?;
740
741 Ok(())
742}
743
744/// Deletes a role from a Discord guild.
745///
746/// # Arguments
747///
748/// * `client` - The HTTP client used to send the request.
749/// * `token` - The bot token for authentication.
750/// * `guild_id` - The ID of the guild.
751/// * `role_id` - The ID of the role to delete.
752///
753/// # Returns
754///
755/// A result indicating success or failure.
756#[allow(dead_code)]
757pub async fn delete_guild_role(client: &Client, token: &str, guild_id: &str, role_id: &str) -> Result<(), Box<dyn Error>> {
758 let url = format!("https://discord.com/api/v9/guilds/{}/roles/{}", guild_id, role_id);
759
760 client.delete(&url)
761 .bearer_auth(token)
762 .send()
763 .await?
764 .error_for_status()?;
765
766 Ok(())
767}
768
769/// Fetches the prune count of a Discord guild.
770///
771/// # Arguments
772///
773/// * `client` - The HTTP client used to send the request.
774/// * `token` - The bot token for authentication.
775/// * `guild_id` - The ID of the guild to fetch prune count for.
776/// * `days` - The number of days to count members without activity.
777///
778/// # Returns
779///
780/// A result containing the prune count as a JSON value.
781#[allow(dead_code)]
782pub async fn get_guild_prune_count(client: &Client, token: &str, guild_id: &str, days: u8) -> Result<Value, Box<dyn Error>> {
783 let url = format!("https://discord.com/api/v9/guilds/{}/prune?days={}", guild_id, days);
784 let response: Value = client.get(&url)
785 .bearer_auth(token)
786 .send()
787 .await?
788 .json()
789 .await?;
790
791 Ok(response)
792}
793
794/// Begins pruning members in a Discord guild.
795///
796/// # Arguments
797///
798/// * `client` - The HTTP client used to send the request.
799/// * `token` - The bot token for authentication.
800/// * `guild_id` - The ID of the guild to prune members in.
801/// * `days` - The number of days to count members without activity.
802///
803/// # Returns
804///
805/// A result containing the prune count as a JSON value.
806#[allow(dead_code)]
807pub async fn begin_guild_prune(client: &Client, token: &str, guild_id: &str, days: u8) -> Result<Value, Box<dyn Error>> {
808 let url = format!("https://discord.com/api/v9/guilds/{}/prune", guild_id);
809 let body = serde_json::json!({ "days": days });
810 let response: Value = client.post(&url)
811 .bearer_auth(token)
812 .json(&body)
813 .send()
814 .await?
815 .json()
816 .await?;
817
818 Ok(response)
819}
820
821/// Fetches voice regions of a Discord guild.
822///
823/// # Arguments
824///
825/// * `client` - The HTTP client used to send the request.
826/// * `token` - The bot token for authentication.
827/// * `guild_id` - The ID of the guild to fetch voice regions for.
828///
829/// # Returns
830///
831/// A result containing the voice regions as a JSON value.
832#[allow(dead_code)]
833pub async fn get_guild_voice_regions(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
834 let url = format!("https://discord.com/api/v9/guilds/{}/regions", guild_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/// Fetches invites of a Discord guild.
846///
847/// # Arguments
848///
849/// * `client` - The HTTP client used to send the request.
850/// * `token` - The bot token for authentication.
851/// * `guild_id` - The ID of the guild to fetch invites for.
852///
853/// # Returns
854///
855/// A result containing the guild invites as a JSON value.
856#[allow(dead_code)]
857pub async fn get_guild_invites(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
858 let url = format!("https://discord.com/api/v9/guilds/{}/invites", guild_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/// Fetches integrations of a Discord guild.
870///
871/// # Arguments
872///
873/// * `client` - The HTTP client used to send the request.
874/// * `token` - The bot token for authentication.
875/// * `guild_id` - The ID of the guild to fetch integrations for.
876///
877/// # Returns
878///
879/// A result containing the guild integrations as a JSON value.
880#[allow(dead_code)]
881pub async fn get_guild_integrations(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
882 let url = format!("https://discord.com/api/v9/guilds/{}/integrations", guild_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/// Deletes an integration from a Discord guild.
894///
895/// # Arguments
896///
897/// * `client` - The HTTP client used to send the request.
898/// * `token` - The bot token for authentication.
899/// * `guild_id` - The ID of the guild.
900/// * `integration_id` - The ID of the integration to delete.
901///
902/// # Returns
903///
904/// A result indicating success or failure.
905#[allow(dead_code)]
906pub async fn delete_guild_integration(client: &Client, token: &str, guild_id: &str, integration_id: &str) -> Result<(), Box<dyn Error>> {
907 let url = format!("https://discord.com/api/v9/guilds/{}/integrations/{}", guild_id, integration_id);
908
909 client.delete(&url)
910 .bearer_auth(token)
911 .send()
912 .await?
913 .error_for_status()?;
914
915 Ok(())
916}
917
918/// Fetches widget settings of a Discord guild.
919///
920/// # Arguments
921///
922/// * `client` - The HTTP client used to send the request.
923/// * `token` - The bot token for authentication.
924/// * `guild_id` - The ID of the guild to fetch widget settings for.
925///
926/// # Returns
927///
928/// A result containing the widget settings as a JSON value.
929#[allow(dead_code)]
930pub async fn get_guild_widget_settings(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
931 let url = format!("https://discord.com/api/v9/guilds/{}/widget", guild_id);
932 let response: Value = client.get(&url)
933 .bearer_auth(token)
934 .send()
935 .await?
936 .json()
937 .await?;
938
939 Ok(response)
940}
941
942/// Modifies widget settings of a Discord guild.
943///
944/// # Arguments
945///
946/// * `client` - The HTTP client used to send the request.
947/// * `token` - The bot token for authentication.
948/// * `guild_id` - The ID of the guild to modify widget settings for.
949/// * `settings` - The JSON value of the settings to update.
950///
951/// # Returns
952///
953/// A result indicating success or failure.
954#[allow(dead_code)]
955pub async fn modify_guild_widget_settings(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
956 let url = format!("https://discord.com/api/v9/guilds/{}/widget", guild_id);
957
958 client.patch(&url)
959 .bearer_auth(token)
960 .json(&settings)
961 .send()
962 .await?
963 .error_for_status()?;
964
965 Ok(())
966}
967
968/// Fetches the widget of a Discord guild.
969///
970/// # Arguments
971///
972/// * `client` - The HTTP client used to send the request.
973/// * `token` - The bot token for authentication.
974/// * `guild_id` - The ID of the guild to fetch the widget for.
975///
976/// # Returns
977///
978/// A result containing the guild widget as a JSON value.
979#[allow(dead_code)]
980#[allow(unused_variables)] // Token is 'unused', crate identified.
981pub async fn get_guild_widget(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
982 let url = format!("https://discord.com/api/v9/guilds/{}/widget.json", guild_id);
983 let response: Value = client.get(&url)
984 .send()
985 .await?
986 .json()
987 .await?;
988
989 Ok(response)
990}
991
992/// Fetches the vanity URL of a Discord guild.
993///
994/// # Arguments
995///
996/// * `client` - The HTTP client used to send the request.
997/// * `token` - The bot token for authentication.
998/// * `guild_id` - The ID of the guild to fetch the vanity URL for.
999///
1000/// # Returns
1001///
1002/// A result containing the vanity URL as a JSON value.
1003#[allow(dead_code)]
1004pub async fn get_guild_vanity_url(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
1005 let url = format!("https://discord.com/api/v9/guilds/{}/vanity-url", guild_id);
1006 let response: Value = client.get(&url)
1007 .bearer_auth(token)
1008 .send()
1009 .await?
1010 .json()
1011 .await?;
1012
1013 Ok(response)
1014}
1015
1016/// Fetches the widget image of a Discord guild.
1017///
1018/// # Arguments
1019///
1020/// * `client` - The HTTP client used to send the request.
1021/// * `token` - The bot token for authentication.
1022/// * `guild_id` - The ID of the guild to fetch the widget image for.
1023///
1024/// # Returns
1025///
1026/// A result containing the widget image as a JSON value.
1027#[allow(dead_code)]
1028#[allow(unused_variables)] // Token is 'unused', crate identified.
1029pub async fn get_guild_widget_image(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
1030 let url = format!("https://discord.com/api/v9/guilds/{}/widget.png", guild_id);
1031 let response: Value = client.get(&url)
1032 .send()
1033 .await?
1034 .json()
1035 .await?;
1036
1037 Ok(response)
1038}
1039
1040/// Fetches the welcome screen of a Discord guild.
1041///
1042/// # Arguments
1043///
1044/// * `client` - The HTTP client used to send the request.
1045/// * `token` - The bot token for authentication.
1046/// * `guild_id` - The ID of the guild to fetch the welcome screen for.
1047///
1048/// # Returns
1049///
1050/// A result containing the welcome screen as a JSON value.
1051#[allow(dead_code)]
1052pub async fn get_guild_welcome_screen(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
1053 let url = format!("https://discord.com/api/v9/guilds/{}/welcome-screen", guild_id);
1054 let response: Value = client.get(&url)
1055 .bearer_auth(token)
1056 .send()
1057 .await?
1058 .json()
1059 .await?;
1060
1061 Ok(response)
1062}
1063
1064/// Modifies the welcome screen of a Discord guild.
1065///
1066/// # Arguments
1067///
1068/// * `client` - The HTTP client used to send the request.
1069/// * `token` - The bot token for authentication.
1070/// * `guild_id` - The ID of the guild to modify the welcome screen for.
1071/// * `settings` - The JSON value of the settings to update.
1072///
1073/// # Returns
1074///
1075/// A result indicating success or failure.
1076#[allow(dead_code)]
1077pub async fn modify_guild_welcome_screen(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
1078 let url = format!("https://discord.com/api/v9/guilds/{}/welcome-screen", guild_id);
1079
1080 client.patch(&url)
1081 .bearer_auth(token)
1082 .json(&settings)
1083 .send()
1084 .await?
1085 .error_for_status()?;
1086
1087 Ok(())
1088}
1089
1090/// Fetches the onboarding settings of a Discord guild.
1091///
1092/// # Arguments
1093///
1094/// * `client` - The HTTP client used to send the request.
1095/// * `token` - The bot token for authentication.
1096/// * `guild_id` - The ID of the guild to fetch the onboarding settings for.
1097///
1098/// # Returns
1099///
1100/// A result containing the onboarding settings as a JSON value.
1101#[allow(dead_code)]
1102pub async fn get_guild_onboarding(client: &Client, token: &str, guild_id: &str) -> Result<Value, Box<dyn Error>> {
1103 let url = format!("https://discord.com/api/v9/guilds/{}/onboarding", guild_id);
1104 let response: Value = client.get(&url)
1105 .bearer_auth(token)
1106 .send()
1107 .await?
1108 .json()
1109 .await?;
1110
1111 Ok(response)
1112}
1113
1114/// Modifies the onboarding settings of a Discord guild.
1115///
1116/// # Arguments
1117///
1118/// * `client` - The HTTP client used to send the request.
1119/// * `token` - The bot token for authentication.
1120/// * `guild_id` - The ID of the guild to modify the onboarding settings for.
1121/// * `settings` - The JSON value of the settings to update.
1122///
1123/// # Returns
1124///
1125/// A result indicating success or failure.
1126#[allow(dead_code)]
1127pub async fn modify_guild_onboarding(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
1128 let url = format!("https://discord.com/api/v9/guilds/{}/onboarding", guild_id);
1129
1130 client.put(&url)
1131 .bearer_auth(token)
1132 .json(&settings)
1133 .send()
1134 .await?
1135 .error_for_status()?;
1136
1137 Ok(())
1138}
1139
1140/// Modifies the current user's voice state in a Discord guild.
1141///
1142/// # Arguments
1143///
1144/// * `client` - The HTTP client used to send the request.
1145/// * `token` - The bot token for authentication.
1146/// * `guild_id` - The ID of the guild.
1147/// * `settings` - The JSON value of the voice state settings.
1148///
1149/// # Returns
1150///
1151/// A result indicating success or failure.
1152#[allow(dead_code)]
1153pub async fn modify_current_user_voice_state(client: &Client, token: &str, guild_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
1154 let url = format!("https://discord.com/api/v9/guilds/{}/voice-states/@me", guild_id);
1155
1156 client.patch(&url)
1157 .bearer_auth(token)
1158 .json(&settings)
1159 .send()
1160 .await?
1161 .error_for_status()?;
1162
1163 Ok(())
1164}
1165
1166/// Modifies a user's voice state in a Discord guild.
1167///
1168/// # Arguments
1169///
1170/// * `client` - The HTTP client used to send the request.
1171/// * `token` - The bot token for authentication.
1172/// * `guild_id` - The ID of the guild.
1173/// * `user_id` - The ID of the user.
1174/// * `settings` - The JSON value of the voice state settings.
1175///
1176/// # Returns
1177///
1178/// A result indicating success or failure.
1179#[allow(dead_code)]
1180pub async fn modify_user_voice_state(client: &Client, token: &str, guild_id: &str, user_id: &str, settings: Value) -> Result<(), Box<dyn Error>> {
1181 let url = format!("https://discord.com/api/v9/guilds/{}/voice-states/{}", guild_id, user_id);
1182
1183 client.patch(&url)
1184 .bearer_auth(token)
1185 .json(&settings)
1186 .send()
1187 .await?
1188 .error_for_status()?;
1189
1190 Ok(())
1191}