Skip to main content

djs_rest/endpoints/
guild.rs

1//! [Guild endpoints](https://docs.discord.com/developers/resources/guild): the guild, its
2//! channels, members, bans, roles, prune, voice regions, invites, integrations, widget,
3//! vanity URL, welcome screen, onboarding and incident actions.
4//!
5//! Deprecated: Modify Current User Nick is left out (D-105; use
6//! [`modify_current_member`](Rest::modify_current_member)). Get Guild Widget Image is a public
7//! URL, not a request (D-116).
8
9use std::collections::HashMap;
10
11use djs_model::{
12    channel::Channel,
13    guild::{
14        Ban, Guild, IncidentsData, Integration, Member, Onboarding, Preview, Role, WelcomeScreen,
15        Widget, WidgetSettings,
16    },
17    id::{GuildId, IntegrationId, RoleId, UserId},
18    invite::InviteWithMetadata,
19    permissions::Permissions,
20    rest::{
21        ActiveThreads, AddGuildMember, BeginGuildPrune, BulkBanResponse, BulkGuildBan,
22        CreateGuildBan, CreateGuildChannel, CreateGuildRole, GetGuild, GetGuildBans,
23        GetGuildPruneCount, ListGuildMembers, ModifyCurrentMember, ModifyGuild,
24        ModifyGuildChannelPosition, ModifyGuildIncidentActions, ModifyGuildMember,
25        ModifyGuildOnboarding, ModifyGuildRole, ModifyGuildRolePosition, ModifyGuildWelcomeScreen,
26        ModifyGuildWidget, SearchGuildMembers, VanityUrl,
27    },
28    voice::VoiceRegion,
29};
30use serde::Deserialize;
31
32use super::PermissionsResponse;
33use crate::client::boxed;
34use crate::{Error, Request, Rest, Route};
35
36/// The response of the prune endpoints, unwrapped by the methods.
37#[derive(Deserialize)]
38struct PruneResponse {
39    pruned: Option<u32>,
40}
41
42/// The guild itself, its channels and active threads.
43impl Rest {
44    /// [Get Guild](https://docs.discord.com/developers/resources/guild#get-guild): returns a
45    /// guild the bot is in; with [`with_counts`](GetGuild::with_counts) also the approximate
46    /// member and presence counts.
47    ///
48    /// discord.js counterpart: `GuildManager#fetch`.
49    ///
50    /// # Errors
51    ///
52    /// See [`Rest::request`]; `10004` Unknown Guild.
53    pub fn get_guild<'a>(
54        &'a self,
55        guild_id: GuildId,
56        query: &'a GetGuild,
57    ) -> impl Future<Output = Result<Guild, Error>> + Send + 'a {
58        boxed(async move {
59            self.call(Request::new(Route::GetGuild { guild_id }).query(query))
60                .await
61        })
62    }
63
64    /// [Get Guild Preview](https://docs.discord.com/developers/resources/guild#get-guild-preview):
65    /// returns the public preview of a guild (one the bot is not in must be discoverable).
66    ///
67    /// discord.js counterpart: `Client#fetchGuildPreview`.
68    ///
69    /// # Errors
70    ///
71    /// See [`Rest::request`]; `10004` Unknown Guild.
72    pub fn get_guild_preview(
73        &self,
74        guild_id: GuildId,
75    ) -> impl Future<Output = Result<Preview, Error>> + Send + '_ {
76        boxed(async move {
77            self.call(Request::new(Route::GetGuildPreview { guild_id }))
78                .await
79        })
80    }
81
82    /// [Modify Guild](https://docs.discord.com/developers/resources/guild#modify-guild):
83    /// changes the settings set in `body`. Needs `MANAGE_GUILD`.
84    ///
85    /// `reason` is shown in the audit log (D-086).
86    ///
87    /// discord.js counterpart: `Guild#edit`.
88    ///
89    /// # Errors
90    ///
91    /// See [`Rest::request`]; `50035` for an invalid field (see
92    /// [`ApiError::field_errors`](crate::ApiError::field_errors)).
93    pub fn modify_guild<'a>(
94        &'a self,
95        guild_id: GuildId,
96        body: &'a ModifyGuild,
97        reason: Option<&'a str>,
98    ) -> impl Future<Output = Result<Guild, Error>> + Send + 'a {
99        boxed(async move {
100            self.call(
101                Request::new(Route::ModifyGuild { guild_id })
102                    .json(body)?
103                    .reason(reason),
104            )
105            .await
106        })
107    }
108
109    /// [Get Guild Channels](https://docs.discord.com/developers/resources/guild#get-guild-channels):
110    /// returns the guild's channels, without threads. From 2026-11-16 Discord leaves out the
111    /// channels the bot cannot view.
112    ///
113    /// discord.js counterpart: `GuildChannelManager#fetch()`.
114    ///
115    /// # Errors
116    ///
117    /// See [`Rest::request`].
118    pub fn get_guild_channels(
119        &self,
120        guild_id: GuildId,
121    ) -> impl Future<Output = Result<Vec<Channel>, Error>> + Send + '_ {
122        boxed(async move {
123            self.call(Request::new(Route::GetGuildChannels { guild_id }))
124                .await
125        })
126    }
127
128    /// [Create Guild Channel](https://docs.discord.com/developers/resources/guild#create-guild-channel):
129    /// creates a channel. Needs `MANAGE_CHANNELS`; only permissions the bot has can be set in
130    /// its overwrites.
131    ///
132    /// `reason` is shown in the audit log (D-086).
133    ///
134    /// discord.js counterpart: `GuildChannelManager#create`.
135    ///
136    /// # Examples
137    ///
138    /// ```no_run
139    /// # async fn example(rest: djs_rest::Rest, guild_id: djs_model::id::GuildId) -> Result<(), djs_rest::Error> {
140    /// use djs_model::{
141    ///     channel::Overwrite, id::RoleId, permissions::Permissions, rest::CreateGuildChannel,
142    /// };
143    ///
144    /// let mut announcements = CreateGuildChannel::new("announcements");
145    /// // `@everyone` (the guild's ID) can read but not write.
146    /// announcements.permission_overwrites.push(Overwrite::role(
147    ///     guild_id.cast(),
148    ///     Permissions::VIEW_CHANNEL,
149    ///     Permissions::SEND_MESSAGES,
150    /// ));
151    /// rest.create_guild_channel(guild_id, &announcements, None).await?;
152    /// # Ok(())
153    /// # }
154    /// ```
155    ///
156    /// # Errors
157    ///
158    /// See [`Rest::request`]; `30013` at the maximum number of channels (500).
159    pub fn create_guild_channel<'a>(
160        &'a self,
161        guild_id: GuildId,
162        body: &'a CreateGuildChannel,
163        reason: Option<&'a str>,
164    ) -> impl Future<Output = Result<Channel, Error>> + Send + 'a {
165        boxed(async move {
166            self.call(
167                Request::new(Route::CreateGuildChannel { guild_id })
168                    .json(body)?
169                    .reason(reason),
170            )
171            .await
172        })
173    }
174
175    /// [Modify Guild Channel Positions](https://docs.discord.com/developers/resources/guild#modify-guild-channel-positions):
176    /// moves channels within the list or between categories (only the listed channels).
177    /// Needs `MANAGE_CHANNELS`.
178    ///
179    /// `reason` is shown in the audit log (D-086).
180    ///
181    /// discord.js counterpart: `GuildChannelManager#setPositions`.
182    ///
183    /// # Errors
184    ///
185    /// See [`Rest::request`]; `40009` when more than one entry changes its parent.
186    pub fn modify_guild_channel_positions<'a>(
187        &'a self,
188        guild_id: GuildId,
189        positions: &'a [ModifyGuildChannelPosition],
190        reason: Option<&'a str>,
191    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
192        boxed(async move {
193            self.call(
194                Request::new(Route::ModifyGuildChannelPositions { guild_id })
195                    .json(positions)?
196                    .reason(reason),
197            )
198            .await
199        })
200    }
201
202    /// [List Active Guild Threads](https://docs.discord.com/developers/resources/guild#list-active-guild-threads):
203    /// returns the active public and private threads of the guild, highest ID first.
204    ///
205    /// discord.js counterpart: `GuildChannelManager#fetchActiveThreads`.
206    ///
207    /// # Errors
208    ///
209    /// See [`Rest::request`].
210    pub fn list_active_guild_threads(
211        &self,
212        guild_id: GuildId,
213    ) -> impl Future<Output = Result<ActiveThreads, Error>> + Send + '_ {
214        boxed(async move {
215            self.call(Request::new(Route::ListActiveGuildThreads { guild_id }))
216                .await
217        })
218    }
219}
220
221/// Members.
222impl Rest {
223    /// [Get Guild Member](https://docs.discord.com/developers/resources/guild#get-guild-member):
224    /// returns a member of the guild.
225    ///
226    /// discord.js counterpart: `GuildMemberManager#fetch`.
227    ///
228    /// # Errors
229    ///
230    /// See [`Rest::request`]; `10007` Unknown Member.
231    pub fn get_guild_member(
232        &self,
233        guild_id: GuildId,
234        user_id: UserId,
235    ) -> impl Future<Output = Result<Member, Error>> + Send + '_ {
236        boxed(async move {
237            self.call(Request::new(Route::GetGuildMember { guild_id, user_id }))
238                .await
239        })
240    }
241
242    /// [List Guild Members](https://docs.discord.com/developers/resources/guild#list-guild-members):
243    /// returns a page of members, sorted by user ID. Needs the `GUILD_MEMBERS` privileged
244    /// intent.
245    ///
246    /// For all members of a large guild, the gateway's Request Guild Members is usually
247    /// better.
248    ///
249    /// discord.js counterpart: `GuildMemberManager#list`.
250    ///
251    /// # Errors
252    ///
253    /// See [`Rest::request`]; `50001` Missing Access without the intent.
254    pub fn list_guild_members<'a>(
255        &'a self,
256        guild_id: GuildId,
257        query: &'a ListGuildMembers,
258    ) -> impl Future<Output = Result<Vec<Member>, Error>> + Send + 'a {
259        boxed(async move {
260            self.call(Request::new(Route::ListGuildMembers { guild_id }).query(query))
261                .await
262        })
263    }
264
265    /// [Search Guild Members](https://docs.discord.com/developers/resources/guild#search-guild-members):
266    /// returns members whose username or nickname starts with the query.
267    ///
268    /// discord.js counterpart: `GuildMemberManager#search`.
269    ///
270    /// # Errors
271    ///
272    /// See [`Rest::request`].
273    pub fn search_guild_members<'a>(
274        &'a self,
275        guild_id: GuildId,
276        query: &'a SearchGuildMembers,
277    ) -> impl Future<Output = Result<Vec<Member>, Error>> + Send + 'a {
278        boxed(async move {
279            self.call(Request::new(Route::SearchGuildMembers { guild_id }).query(query))
280                .await
281        })
282    }
283
284    /// [Get Guild Member Permissions](https://docs.discord.com/developers/resources/guild#get-guild-member-permissions):
285    /// returns a member's guild-wide permissions (their roles with `@everyone`; D-110).
286    ///
287    /// discord.js counterpart: `GuildMember#permissions` (computed locally).
288    ///
289    /// # Errors
290    ///
291    /// See [`Rest::request`]; `10007` Unknown Member.
292    pub fn get_guild_member_permissions(
293        &self,
294        guild_id: GuildId,
295        user_id: UserId,
296    ) -> impl Future<Output = Result<Permissions, Error>> + Send + '_ {
297        boxed(async move {
298            let response: PermissionsResponse = self
299                .request(Request::new(Route::GetGuildMemberPermissions {
300                    guild_id,
301                    user_id,
302                }))
303                .await?;
304            Ok(response.permissions)
305        })
306    }
307
308    /// [Add Guild Member](https://docs.discord.com/developers/resources/guild#add-guild-member):
309    /// adds a user to the guild with an `OAuth2` access token they granted the bot's
310    /// application (`guilds.join` scope). Returns the new member, or `None` when the user
311    /// already is one. The bot must be in the guild with `CREATE_INSTANT_INVITE`.
312    ///
313    /// discord.js counterpart: `GuildMemberManager#add`.
314    ///
315    /// # Errors
316    ///
317    /// See [`Rest::request`]; `40007` when the user is banned, `30001` when they are in 100
318    /// guilds.
319    pub fn add_guild_member<'a>(
320        &'a self,
321        guild_id: GuildId,
322        user_id: UserId,
323        body: &'a AddGuildMember,
324    ) -> impl Future<Output = Result<Option<Member>, Error>> + Send + 'a {
325        boxed(async move {
326            self.call(Request::new(Route::AddGuildMember { guild_id, user_id }).json(body)?)
327                .await
328        })
329    }
330
331    /// [Modify Guild Member](https://docs.discord.com/developers/resources/guild#modify-guild-member):
332    /// changes a member's nickname, roles, voice state or timeout (each needs its own
333    /// permission; see [`ModifyGuildMember`]).
334    ///
335    /// `reason` is shown in the audit log (D-086).
336    ///
337    /// discord.js counterpart: `GuildMember#edit`, `#timeout`, `#setNickname`, …
338    ///
339    /// # Examples
340    ///
341    /// ```no_run
342    /// # async fn example(rest: djs_rest::Rest, guild_id: djs_model::id::GuildId, user_id: djs_model::id::UserId) -> Result<(), djs_rest::Error> {
343    /// use djs_model::{rest::ModifyGuildMember, util::{Patch, Timestamp}};
344    ///
345    /// // Time the member out for ten minutes.
346    /// let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap();
347    /// let until = Timestamp::from_unix_secs(now.as_secs() as i64 + 600).unwrap();
348    /// let mut body = ModifyGuildMember::default();
349    /// body.communication_disabled_until = Patch::Set(until);
350    /// rest.modify_guild_member(guild_id, user_id, &body, Some("Spam"))
351    ///     .await?;
352    /// # Ok(())
353    /// # }
354    /// ```
355    ///
356    /// # Errors
357    ///
358    /// See [`Rest::request`]; `50013` Missing Permissions (also for members above the bot's
359    /// highest role).
360    pub fn modify_guild_member<'a>(
361        &'a self,
362        guild_id: GuildId,
363        user_id: UserId,
364        body: &'a ModifyGuildMember,
365        reason: Option<&'a str>,
366    ) -> impl Future<Output = Result<Member, Error>> + Send + 'a {
367        boxed(async move {
368            self.call(
369                Request::new(Route::ModifyGuildMember { guild_id, user_id })
370                    .json(body)?
371                    .reason(reason),
372            )
373            .await
374        })
375    }
376
377    /// [Modify Current Member](https://docs.discord.com/developers/resources/guild#modify-current-member):
378    /// changes the bot's own nickname, guild avatar, banner or bio.
379    ///
380    /// `reason` is shown in the audit log (D-086).
381    ///
382    /// discord.js counterpart: `GuildMemberManager#editMe`.
383    ///
384    /// # Errors
385    ///
386    /// See [`Rest::request`].
387    pub fn modify_current_member<'a>(
388        &'a self,
389        guild_id: GuildId,
390        body: &'a ModifyCurrentMember,
391        reason: Option<&'a str>,
392    ) -> impl Future<Output = Result<Member, Error>> + Send + 'a {
393        boxed(async move {
394            self.call(
395                Request::new(Route::ModifyCurrentMember { guild_id })
396                    .json(body)?
397                    .reason(reason),
398            )
399            .await
400        })
401    }
402
403    /// [Add Guild Member Role](https://docs.discord.com/developers/resources/guild#add-guild-member-role):
404    /// gives a member a role. Needs `MANAGE_ROLES` and a higher role than the one given.
405    ///
406    /// `reason` is shown in the audit log (D-086).
407    ///
408    /// discord.js counterpart: `GuildMemberRoleManager#add`.
409    ///
410    /// # Errors
411    ///
412    /// See [`Rest::request`]; `10011` Unknown Role.
413    pub fn add_guild_member_role<'a>(
414        &'a self,
415        guild_id: GuildId,
416        user_id: UserId,
417        role_id: RoleId,
418        reason: Option<&'a str>,
419    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
420        boxed(async move {
421            self.call(
422                Request::new(Route::AddGuildMemberRole {
423                    guild_id,
424                    user_id,
425                    role_id,
426                })
427                .reason(reason),
428            )
429            .await
430        })
431    }
432
433    /// [Remove Guild Member Role](https://docs.discord.com/developers/resources/guild#remove-guild-member-role):
434    /// takes a role from a member. Needs `MANAGE_ROLES`.
435    ///
436    /// `reason` is shown in the audit log (D-086).
437    ///
438    /// discord.js counterpart: `GuildMemberRoleManager#remove`.
439    ///
440    /// # Errors
441    ///
442    /// See [`Rest::request`].
443    pub fn remove_guild_member_role<'a>(
444        &'a self,
445        guild_id: GuildId,
446        user_id: UserId,
447        role_id: RoleId,
448        reason: Option<&'a str>,
449    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
450        boxed(async move {
451            self.call(
452                Request::new(Route::RemoveGuildMemberRole {
453                    guild_id,
454                    user_id,
455                    role_id,
456                })
457                .reason(reason),
458            )
459            .await
460        })
461    }
462
463    /// [Remove Guild Member](https://docs.discord.com/developers/resources/guild#remove-guild-member):
464    /// kicks a member. Needs `KICK_MEMBERS`.
465    ///
466    /// `reason` is shown in the audit log (D-086).
467    ///
468    /// discord.js counterpart: `GuildMember#kick`.
469    ///
470    /// # Errors
471    ///
472    /// See [`Rest::request`]; `50013` Missing Permissions.
473    pub fn remove_guild_member<'a>(
474        &'a self,
475        guild_id: GuildId,
476        user_id: UserId,
477        reason: Option<&'a str>,
478    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
479        boxed(async move {
480            self.call(Request::new(Route::RemoveGuildMember { guild_id, user_id }).reason(reason))
481                .await
482        })
483    }
484}
485
486/// Bans.
487impl Rest {
488    /// [Get Guild Bans](https://docs.discord.com/developers/resources/guild#get-guild-bans):
489    /// returns a page of bans, sorted by user ID. Needs `BAN_MEMBERS` or `VIEW_AUDIT_LOG`.
490    ///
491    /// discord.js counterpart: `GuildBanManager#fetch()`.
492    ///
493    /// # Errors
494    ///
495    /// See [`Rest::request`].
496    pub fn get_guild_bans<'a>(
497        &'a self,
498        guild_id: GuildId,
499        query: &'a GetGuildBans,
500    ) -> impl Future<Output = Result<Vec<Ban>, Error>> + Send + 'a {
501        boxed(async move {
502            self.call(Request::new(Route::GetGuildBans { guild_id }).query(query))
503                .await
504        })
505    }
506
507    /// [Get Guild Ban](https://docs.discord.com/developers/resources/guild#get-guild-ban):
508    /// returns the ban of a user. Needs `BAN_MEMBERS` or `VIEW_AUDIT_LOG`.
509    ///
510    /// discord.js counterpart: `GuildBanManager#fetch(user)`.
511    ///
512    /// # Errors
513    ///
514    /// See [`Rest::request`]; `10026` Unknown Ban.
515    pub fn get_guild_ban(
516        &self,
517        guild_id: GuildId,
518        user_id: UserId,
519    ) -> impl Future<Output = Result<Ban, Error>> + Send + '_ {
520        boxed(async move {
521            self.call(Request::new(Route::GetGuildBan { guild_id, user_id }))
522                .await
523        })
524    }
525
526    /// [Create Guild Ban](https://docs.discord.com/developers/resources/guild#create-guild-ban):
527    /// bans a user (member or not), optionally deleting their recent messages. Needs
528    /// `BAN_MEMBERS`.
529    ///
530    /// `reason` is shown in the audit log (D-086).
531    ///
532    /// discord.js counterpart: `GuildBanManager#create`.
533    ///
534    /// # Examples
535    ///
536    /// ```no_run
537    /// # async fn example(rest: djs_rest::Rest, guild_id: djs_model::id::GuildId, user_id: djs_model::id::UserId) -> Result<(), djs_rest::Error> {
538    /// use djs_model::rest::CreateGuildBan;
539    ///
540    /// let mut body = CreateGuildBan::default();
541    /// body.delete_message_seconds = Some(24 * 60 * 60);
542    /// rest.create_guild_ban(guild_id, user_id, &body, Some("Raid"))
543    ///     .await?;
544    /// # Ok(())
545    /// # }
546    /// ```
547    ///
548    /// # Errors
549    ///
550    /// See [`Rest::request`]; `50013` Missing Permissions.
551    pub fn create_guild_ban<'a>(
552        &'a self,
553        guild_id: GuildId,
554        user_id: UserId,
555        body: &'a CreateGuildBan,
556        reason: Option<&'a str>,
557    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
558        boxed(async move {
559            self.call(
560                Request::new(Route::CreateGuildBan { guild_id, user_id })
561                    .json(body)?
562                    .reason(reason),
563            )
564            .await
565        })
566    }
567
568    /// [Remove Guild Ban](https://docs.discord.com/developers/resources/guild#remove-guild-ban):
569    /// unbans a user. Needs `BAN_MEMBERS`.
570    ///
571    /// `reason` is shown in the audit log (D-086).
572    ///
573    /// discord.js counterpart: `GuildBanManager#remove`.
574    ///
575    /// # Errors
576    ///
577    /// See [`Rest::request`]; `10026` Unknown Ban.
578    pub fn remove_guild_ban<'a>(
579        &'a self,
580        guild_id: GuildId,
581        user_id: UserId,
582        reason: Option<&'a str>,
583    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
584        boxed(async move {
585            self.call(Request::new(Route::RemoveGuildBan { guild_id, user_id }).reason(reason))
586                .await
587        })
588    }
589
590    /// [Bulk Guild Ban](https://docs.discord.com/developers/resources/guild#bulk-guild-ban):
591    /// bans up to 200 users at once, returning who was and was not banned. Needs
592    /// `BAN_MEMBERS` and `MANAGE_GUILD`.
593    ///
594    /// `reason` is shown in the audit log (D-086).
595    ///
596    /// discord.js counterpart: `GuildBanManager#bulkCreate`.
597    ///
598    /// # Errors
599    ///
600    /// See [`Rest::request`]; `500000` when none of the users could be banned.
601    pub fn bulk_guild_ban<'a>(
602        &'a self,
603        guild_id: GuildId,
604        body: &'a BulkGuildBan,
605        reason: Option<&'a str>,
606    ) -> impl Future<Output = Result<BulkBanResponse, Error>> + Send + 'a {
607        boxed(async move {
608            self.call(
609                Request::new(Route::BulkGuildBan { guild_id })
610                    .json(body)?
611                    .reason(reason),
612            )
613            .await
614        })
615    }
616}
617
618/// Roles.
619impl Rest {
620    /// [Get Guild Roles](https://docs.discord.com/developers/resources/guild#get-guild-roles):
621    /// returns the guild's roles.
622    ///
623    /// discord.js counterpart: `RoleManager#fetch()`.
624    ///
625    /// # Errors
626    ///
627    /// See [`Rest::request`].
628    pub fn get_guild_roles(
629        &self,
630        guild_id: GuildId,
631    ) -> impl Future<Output = Result<Vec<Role>, Error>> + Send + '_ {
632        boxed(async move {
633            self.call(Request::new(Route::GetGuildRoles { guild_id }))
634                .await
635        })
636    }
637
638    /// [Get Guild Role](https://docs.discord.com/developers/resources/guild#get-guild-role):
639    /// returns one role.
640    ///
641    /// discord.js counterpart: `RoleManager#fetch(id)`.
642    ///
643    /// # Errors
644    ///
645    /// See [`Rest::request`]; `10011` Unknown Role.
646    pub fn get_guild_role(
647        &self,
648        guild_id: GuildId,
649        role_id: RoleId,
650    ) -> impl Future<Output = Result<Role, Error>> + Send + '_ {
651        boxed(async move {
652            self.call(Request::new(Route::GetGuildRole { guild_id, role_id }))
653                .await
654        })
655    }
656
657    /// [Get Guild Role Permissions](https://docs.discord.com/developers/resources/guild#get-guild-role-permissions):
658    /// returns the guild-wide permissions of a role together with `@everyone` (D-110).
659    ///
660    /// discord.js counterpart: `Role#permissions` (computed locally).
661    ///
662    /// # Errors
663    ///
664    /// See [`Rest::request`]; `10011` Unknown Role.
665    pub fn get_guild_role_permissions(
666        &self,
667        guild_id: GuildId,
668        role_id: RoleId,
669    ) -> impl Future<Output = Result<Permissions, Error>> + Send + '_ {
670        boxed(async move {
671            let response: PermissionsResponse = self
672                .request(Request::new(Route::GetGuildRolePermissions {
673                    guild_id,
674                    role_id,
675                }))
676                .await?;
677            Ok(response.permissions)
678        })
679    }
680
681    /// [Get Guild Role Member Counts](https://docs.discord.com/developers/resources/guild#get-guild-role-member-counts):
682    /// returns how many members have each role (without `@everyone`).
683    ///
684    /// discord.js counterpart: `RoleManager#fetchMemberCounts`.
685    ///
686    /// # Errors
687    ///
688    /// See [`Rest::request`].
689    pub fn get_guild_role_member_counts(
690        &self,
691        guild_id: GuildId,
692    ) -> impl Future<Output = Result<HashMap<RoleId, u32>, Error>> + Send + '_ {
693        boxed(async move {
694            self.call(Request::new(Route::GetGuildRoleMemberCounts { guild_id }))
695                .await
696        })
697    }
698
699    /// [Create Guild Role](https://docs.discord.com/developers/resources/guild#create-guild-role):
700    /// creates a role. Needs `MANAGE_ROLES`.
701    ///
702    /// `reason` is shown in the audit log (D-086).
703    ///
704    /// discord.js counterpart: `RoleManager#create`.
705    ///
706    /// # Examples
707    ///
708    /// ```no_run
709    /// # async fn example(rest: djs_rest::Rest, guild_id: djs_model::id::GuildId) -> Result<(), djs_rest::Error> {
710    /// use djs_model::{guild::RoleColors, rest::CreateGuildRole};
711    ///
712    /// let mut body = CreateGuildRole::default();
713    /// body.name = Some("Rustacean".into());
714    /// body.colors = Some(RoleColors::solid(0xdea5_84));
715    /// body.mentionable = true;
716    /// let role = rest.create_guild_role(guild_id, &body, None).await?;
717    /// # Ok(())
718    /// # }
719    /// ```
720    ///
721    /// # Errors
722    ///
723    /// See [`Rest::request`]; `30005` at the maximum number of roles (250).
724    pub fn create_guild_role<'a>(
725        &'a self,
726        guild_id: GuildId,
727        body: &'a CreateGuildRole,
728        reason: Option<&'a str>,
729    ) -> impl Future<Output = Result<Role, Error>> + Send + 'a {
730        boxed(async move {
731            self.call(
732                Request::new(Route::CreateGuildRole { guild_id })
733                    .json(body)?
734                    .reason(reason),
735            )
736            .await
737        })
738    }
739
740    /// [Modify Guild Role Positions](https://docs.discord.com/developers/resources/guild#modify-guild-role-positions):
741    /// reorders roles and returns all of them. Needs `MANAGE_ROLES`.
742    ///
743    /// `reason` is shown in the audit log (D-086).
744    ///
745    /// discord.js counterpart: `RoleManager#setPositions`.
746    ///
747    /// # Errors
748    ///
749    /// See [`Rest::request`].
750    pub fn modify_guild_role_positions<'a>(
751        &'a self,
752        guild_id: GuildId,
753        positions: &'a [ModifyGuildRolePosition],
754        reason: Option<&'a str>,
755    ) -> impl Future<Output = Result<Vec<Role>, Error>> + Send + 'a {
756        boxed(async move {
757            self.call(
758                Request::new(Route::ModifyGuildRolePositions { guild_id })
759                    .json(positions)?
760                    .reason(reason),
761            )
762            .await
763        })
764    }
765
766    /// [Modify Guild Role](https://docs.discord.com/developers/resources/guild#modify-guild-role):
767    /// changes the fields set in `body`. Needs `MANAGE_ROLES` and a higher role.
768    ///
769    /// `reason` is shown in the audit log (D-086).
770    ///
771    /// discord.js counterpart: `Role#edit`.
772    ///
773    /// # Errors
774    ///
775    /// See [`Rest::request`].
776    pub fn modify_guild_role<'a>(
777        &'a self,
778        guild_id: GuildId,
779        role_id: RoleId,
780        body: &'a ModifyGuildRole,
781        reason: Option<&'a str>,
782    ) -> impl Future<Output = Result<Role, Error>> + Send + 'a {
783        boxed(async move {
784            self.call(
785                Request::new(Route::ModifyGuildRole { guild_id, role_id })
786                    .json(body)?
787                    .reason(reason),
788            )
789            .await
790        })
791    }
792
793    /// [Delete Guild Role](https://docs.discord.com/developers/resources/guild#delete-guild-role):
794    /// deletes a role. Needs `MANAGE_ROLES`.
795    ///
796    /// `reason` is shown in the audit log (D-086).
797    ///
798    /// discord.js counterpart: `Role#delete`.
799    ///
800    /// # Errors
801    ///
802    /// See [`Rest::request`]; `10011` Unknown Role.
803    pub fn delete_guild_role<'a>(
804        &'a self,
805        guild_id: GuildId,
806        role_id: RoleId,
807        reason: Option<&'a str>,
808    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
809        boxed(async move {
810            self.call(Request::new(Route::DeleteGuildRole { guild_id, role_id }).reason(reason))
811                .await
812        })
813    }
814}
815
816/// Prune, voice regions, invites and integrations.
817impl Rest {
818    /// [Get Guild Prune Count](https://docs.discord.com/developers/resources/guild#get-guild-prune-count):
819    /// returns how many members a prune would kick. Needs `MANAGE_GUILD` and `KICK_MEMBERS`
820    /// (`ADMINISTRATOR` with the `PRUNE_REQUIRES_ADMIN` feature).
821    ///
822    /// discord.js counterpart: `GuildMemberManager#prune({ dry: true })`.
823    ///
824    /// # Errors
825    ///
826    /// See [`Rest::request`].
827    pub fn get_guild_prune_count<'a>(
828        &'a self,
829        guild_id: GuildId,
830        query: &'a GetGuildPruneCount,
831    ) -> impl Future<Output = Result<u32, Error>> + Send + 'a {
832        boxed(async move {
833            let response: PruneResponse = self
834                .request(Request::new(Route::GetGuildPruneCount { guild_id }).query(query))
835                .await?;
836            Ok(response.pruned.unwrap_or(0))
837        })
838    }
839
840    /// [Begin Guild Prune](https://docs.discord.com/developers/resources/guild#begin-guild-prune):
841    /// kicks the inactive members and returns how many, unless
842    /// [`compute_prune_count`](BeginGuildPrune::compute_prune_count) is `false`. Needs the
843    /// permissions of [`get_guild_prune_count`](Self::get_guild_prune_count).
844    ///
845    /// `reason` is shown in the audit log (D-086).
846    ///
847    /// discord.js counterpart: `GuildMemberManager#prune`.
848    ///
849    /// # Errors
850    ///
851    /// See [`Rest::request`].
852    pub fn begin_guild_prune<'a>(
853        &'a self,
854        guild_id: GuildId,
855        body: &'a BeginGuildPrune,
856        reason: Option<&'a str>,
857    ) -> impl Future<Output = Result<Option<u32>, Error>> + Send + 'a {
858        boxed(async move {
859            let response: PruneResponse = self
860                .request(
861                    Request::new(Route::BeginGuildPrune { guild_id })
862                        .json(body)?
863                        .reason(reason),
864                )
865                .await?;
866            Ok(response.pruned)
867        })
868    }
869
870    /// [Get Guild Voice Regions](https://docs.discord.com/developers/resources/guild#get-guild-voice-regions):
871    /// returns the voice regions available to the guild (including VIP ones).
872    ///
873    /// discord.js counterpart: `Guild#fetchVoiceRegions`.
874    ///
875    /// # Errors
876    ///
877    /// See [`Rest::request`].
878    pub fn get_guild_voice_regions(
879        &self,
880        guild_id: GuildId,
881    ) -> impl Future<Output = Result<Vec<VoiceRegion>, Error>> + Send + '_ {
882        boxed(async move {
883            self.call(Request::new(Route::GetGuildVoiceRegions { guild_id }))
884                .await
885        })
886    }
887
888    /// [Get Guild Invites](https://docs.discord.com/developers/resources/guild#get-guild-invites):
889    /// returns the guild's invites. Needs `MANAGE_GUILD` or `VIEW_AUDIT_LOG`; the
890    /// [`metadata`](InviteWithMetadata::metadata) is only included with `MANAGE_GUILD`
891    /// (D-117).
892    ///
893    /// discord.js counterpart: `GuildInviteManager#fetch()`.
894    ///
895    /// # Errors
896    ///
897    /// See [`Rest::request`].
898    pub fn get_guild_invites(
899        &self,
900        guild_id: GuildId,
901    ) -> impl Future<Output = Result<Vec<InviteWithMetadata>, Error>> + Send + '_ {
902        boxed(async move {
903            self.call(Request::new(Route::GetGuildInvites { guild_id }))
904                .await
905        })
906    }
907
908    /// [Get Guild Integrations](https://docs.discord.com/developers/resources/guild#get-guild-integrations):
909    /// returns up to 50 integrations of the guild. Needs `MANAGE_GUILD`.
910    ///
911    /// discord.js counterpart: `Guild#fetchIntegrations`.
912    ///
913    /// # Errors
914    ///
915    /// See [`Rest::request`].
916    pub fn get_guild_integrations(
917        &self,
918        guild_id: GuildId,
919    ) -> impl Future<Output = Result<Vec<Integration>, Error>> + Send + '_ {
920        boxed(async move {
921            self.call(Request::new(Route::GetGuildIntegrations { guild_id }))
922                .await
923        })
924    }
925
926    /// [Delete Guild Integration](https://docs.discord.com/developers/resources/guild#delete-guild-integration):
927    /// removes an integration with its webhooks, kicking its bot. Needs `MANAGE_GUILD`.
928    ///
929    /// `reason` is shown in the audit log (D-086).
930    ///
931    /// discord.js counterpart: `Integration#delete`.
932    ///
933    /// # Errors
934    ///
935    /// See [`Rest::request`].
936    pub fn delete_guild_integration<'a>(
937        &'a self,
938        guild_id: GuildId,
939        integration_id: IntegrationId,
940        reason: Option<&'a str>,
941    ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
942        boxed(async move {
943            self.call(
944                Request::new(Route::DeleteGuildIntegration {
945                    guild_id,
946                    integration_id,
947                })
948                .reason(reason),
949            )
950            .await
951        })
952    }
953}
954
955/// Widget, vanity URL, welcome screen, onboarding and incident actions.
956impl Rest {
957    /// [Get Guild Widget Settings](https://docs.discord.com/developers/resources/guild#get-guild-widget-settings):
958    /// returns whether the widget is enabled and its invite channel. Needs `MANAGE_GUILD`.
959    ///
960    /// discord.js counterpart: `Guild#fetchWidgetSettings`.
961    ///
962    /// # Errors
963    ///
964    /// See [`Rest::request`].
965    pub fn get_guild_widget_settings(
966        &self,
967        guild_id: GuildId,
968    ) -> impl Future<Output = Result<WidgetSettings, Error>> + Send + '_ {
969        boxed(async move {
970            self.call(Request::new(Route::GetGuildWidgetSettings { guild_id }))
971                .await
972        })
973    }
974
975    /// [Modify Guild Widget](https://docs.discord.com/developers/resources/guild#modify-guild-widget):
976    /// changes the widget settings. Needs `MANAGE_GUILD`.
977    ///
978    /// `reason` is shown in the audit log (D-086).
979    ///
980    /// discord.js counterpart: `Guild#setWidgetSettings`.
981    ///
982    /// # Errors
983    ///
984    /// See [`Rest::request`].
985    pub fn modify_guild_widget<'a>(
986        &'a self,
987        guild_id: GuildId,
988        body: &'a ModifyGuildWidget,
989        reason: Option<&'a str>,
990    ) -> impl Future<Output = Result<WidgetSettings, Error>> + Send + 'a {
991        boxed(async move {
992            self.call(
993                Request::new(Route::ModifyGuildWidget { guild_id })
994                    .json(body)?
995                    .reason(reason),
996            )
997            .await
998        })
999    }
1000
1001    /// [Get Guild Widget](https://docs.discord.com/developers/resources/guild#get-guild-widget):
1002    /// returns the public widget data (online members, voice channels, invite).
1003    ///
1004    /// discord.js counterpart: `Client#fetchGuildWidget`.
1005    ///
1006    /// # Errors
1007    ///
1008    /// See [`Rest::request`]; `50004` when the widget is disabled.
1009    pub fn get_guild_widget(
1010        &self,
1011        guild_id: GuildId,
1012    ) -> impl Future<Output = Result<Widget, Error>> + Send + '_ {
1013        boxed(async move {
1014            self.call(Request::new(Route::GetGuildWidget { guild_id }))
1015                .await
1016        })
1017    }
1018
1019    /// [Get Guild Vanity URL](https://docs.discord.com/developers/resources/guild#get-guild-vanity-url):
1020    /// returns the vanity invite code and its uses. Needs `MANAGE_GUILD`.
1021    ///
1022    /// discord.js counterpart: `Guild#fetchVanityData`.
1023    ///
1024    /// # Errors
1025    ///
1026    /// See [`Rest::request`].
1027    pub fn get_guild_vanity_url(
1028        &self,
1029        guild_id: GuildId,
1030    ) -> impl Future<Output = Result<VanityUrl, Error>> + Send + '_ {
1031        boxed(async move {
1032            self.call(Request::new(Route::GetGuildVanityUrl { guild_id }))
1033                .await
1034        })
1035    }
1036
1037    /// [Get Guild Welcome Screen](https://docs.discord.com/developers/resources/guild#get-guild-welcome-screen):
1038    /// returns the welcome screen (needs `MANAGE_GUILD` when it is disabled).
1039    ///
1040    /// discord.js counterpart: `Guild#fetchWelcomeScreen`.
1041    ///
1042    /// # Errors
1043    ///
1044    /// See [`Rest::request`].
1045    pub fn get_guild_welcome_screen(
1046        &self,
1047        guild_id: GuildId,
1048    ) -> impl Future<Output = Result<WelcomeScreen, Error>> + Send + '_ {
1049        boxed(async move {
1050            self.call(Request::new(Route::GetGuildWelcomeScreen { guild_id }))
1051                .await
1052        })
1053    }
1054
1055    /// [Modify Guild Welcome Screen](https://docs.discord.com/developers/resources/guild#modify-guild-welcome-screen):
1056    /// changes the welcome screen. Needs `MANAGE_GUILD`.
1057    ///
1058    /// `reason` is shown in the audit log (D-086).
1059    ///
1060    /// discord.js counterpart: `Guild#editWelcomeScreen`.
1061    ///
1062    /// # Errors
1063    ///
1064    /// See [`Rest::request`].
1065    pub fn modify_guild_welcome_screen<'a>(
1066        &'a self,
1067        guild_id: GuildId,
1068        body: &'a ModifyGuildWelcomeScreen,
1069        reason: Option<&'a str>,
1070    ) -> impl Future<Output = Result<WelcomeScreen, Error>> + Send + 'a {
1071        boxed(async move {
1072            self.call(
1073                Request::new(Route::ModifyGuildWelcomeScreen { guild_id })
1074                    .json(body)?
1075                    .reason(reason),
1076            )
1077            .await
1078        })
1079    }
1080
1081    /// [Get Guild Onboarding](https://docs.discord.com/developers/resources/guild#get-guild-onboarding):
1082    /// returns the onboarding flow.
1083    ///
1084    /// discord.js counterpart: `Guild#fetchOnboarding`.
1085    ///
1086    /// # Errors
1087    ///
1088    /// See [`Rest::request`].
1089    pub fn get_guild_onboarding(
1090        &self,
1091        guild_id: GuildId,
1092    ) -> impl Future<Output = Result<Onboarding, Error>> + Send + '_ {
1093        boxed(async move {
1094            self.call(Request::new(Route::GetGuildOnboarding { guild_id }))
1095                .await
1096        })
1097    }
1098
1099    /// [Modify Guild Onboarding](https://docs.discord.com/developers/resources/guild#modify-guild-onboarding):
1100    /// replaces the onboarding configuration. Needs `MANAGE_GUILD` and `MANAGE_ROLES`. New
1101    /// prompts get generated IDs (D-118).
1102    ///
1103    /// `reason` is shown in the audit log (D-086).
1104    ///
1105    /// discord.js counterpart: `Guild#editOnboarding`.
1106    ///
1107    /// # Errors
1108    ///
1109    /// See [`Rest::request`]; `50035` when the enabled flow lacks default channels.
1110    pub fn modify_guild_onboarding<'a>(
1111        &'a self,
1112        guild_id: GuildId,
1113        body: &'a ModifyGuildOnboarding,
1114        reason: Option<&'a str>,
1115    ) -> impl Future<Output = Result<Onboarding, Error>> + Send + 'a {
1116        boxed(async move {
1117            self.call(
1118                Request::new(Route::ModifyGuildOnboarding { guild_id })
1119                    .json(body)?
1120                    .reason(reason),
1121            )
1122            .await
1123        })
1124    }
1125
1126    /// [Modify Guild Incident Actions](https://docs.discord.com/developers/resources/guild#modify-guild-incident-actions):
1127    /// pauses invites or direct messages for up to 24 hours (e.g. during a raid), or ends a
1128    /// pause. Needs `MANAGE_GUILD`.
1129    ///
1130    /// discord.js counterpart: `Guild#setIncidentActions`.
1131    ///
1132    /// # Errors
1133    ///
1134    /// See [`Rest::request`].
1135    pub fn modify_guild_incident_actions<'a>(
1136        &'a self,
1137        guild_id: GuildId,
1138        body: &'a ModifyGuildIncidentActions,
1139    ) -> impl Future<Output = Result<IncidentsData, Error>> + Send + 'a {
1140        boxed(async move {
1141            self.call(Request::new(Route::ModifyGuildIncidentActions { guild_id }).json(body)?)
1142                .await
1143        })
1144    }
1145}