serenity/model/guild/
partial_guild.rs

1use serde::Serialize;
2
3#[cfg(feature = "model")]
4use crate::builder::{
5    CreateChannel,
6    CreateCommand,
7    CreateSticker,
8    EditAutoModRule,
9    EditCommandPermissions,
10    EditGuild,
11    EditGuildWelcomeScreen,
12    EditGuildWidget,
13    EditMember,
14    EditRole,
15    EditSticker,
16};
17#[cfg(all(feature = "cache", feature = "utils", feature = "client"))]
18use crate::cache::Cache;
19#[cfg(feature = "collector")]
20use crate::collector::{MessageCollector, ReactionCollector};
21#[cfg(feature = "collector")]
22use crate::gateway::ShardMessenger;
23#[cfg(feature = "model")]
24use crate::http::{CacheHttp, Http, UserPagination};
25use crate::model::prelude::*;
26#[cfg(feature = "model")]
27use crate::model::utils::icon_url;
28use crate::model::utils::{emojis, roles, stickers};
29
30/// Partial information about a [`Guild`]. This does not include information like member data.
31///
32/// [Discord docs](https://discord.com/developers/docs/resources/guild#guild-object).
33#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
34#[derive(Clone, Debug, Deserialize, Serialize)]
35#[serde(remote = "Self")]
36#[non_exhaustive]
37pub struct PartialGuild {
38    // ======
39    // These fields are copy-pasted from the top part of Guild, and the omitted fields filled in
40    // ======
41    /// The unique Id identifying the guild.
42    ///
43    /// This is equivalent to the Id of the default role (`@everyone`).
44    pub id: GuildId,
45    /// The name of the guild.
46    pub name: String,
47    /// The hash of the icon used by the guild.
48    ///
49    /// In the client, this appears on the guild list on the left-hand side.
50    pub icon: Option<ImageHash>,
51    /// Icon hash, returned when in the template object
52    pub icon_hash: Option<ImageHash>,
53    /// An identifying hash of the guild's splash icon.
54    ///
55    /// If the `InviteSplash` feature is enabled, this can be used to generate a URL to a splash
56    /// image.
57    pub splash: Option<ImageHash>,
58    /// An identifying hash of the guild discovery's splash icon.
59    ///
60    /// **Note**: Only present for guilds with the `DISCOVERABLE` feature.
61    pub discovery_splash: Option<ImageHash>,
62    // Omitted `owner` field because only Http::get_guilds uses it, which returns GuildInfo
63    /// The Id of the [`User`] who owns the guild.
64    pub owner_id: UserId,
65    // Omitted `permissions` field because only Http::get_guilds uses it, which returns GuildInfo
66    // Omitted `region` field because it is deprecated (see Discord docs)
67    /// Information about the voice afk channel.
68    #[serde(flatten)]
69    pub afk_metadata: Option<AfkMetadata>,
70    /// Whether or not the guild widget is enabled.
71    pub widget_enabled: Option<bool>,
72    /// The channel id that the widget will generate an invite to, or null if set to no invite
73    pub widget_channel_id: Option<ChannelId>,
74    /// Indicator of the current verification level of the guild.
75    pub verification_level: VerificationLevel,
76    /// Indicator of whether notifications for all messages are enabled by
77    /// default in the guild.
78    pub default_message_notifications: DefaultMessageNotificationLevel,
79    /// Default explicit content filter level.
80    pub explicit_content_filter: ExplicitContentFilter,
81    /// A mapping of the guild's roles.
82    #[serde(with = "roles")]
83    pub roles: HashMap<RoleId, Role>,
84    /// All of the guild's custom emojis.
85    #[serde(with = "emojis")]
86    pub emojis: HashMap<EmojiId, Emoji>,
87    /// The guild features. More information available at [`discord documentation`].
88    ///
89    /// The following is a list of known features:
90    /// - `ANIMATED_ICON`
91    /// - `BANNER`
92    /// - `COMMERCE`
93    /// - `COMMUNITY`
94    /// - `DISCOVERABLE`
95    /// - `FEATURABLE`
96    /// - `INVITE_SPLASH`
97    /// - `MEMBER_VERIFICATION_GATE_ENABLED`
98    /// - `MONETIZATION_ENABLED`
99    /// - `MORE_STICKERS`
100    /// - `NEWS`
101    /// - `PARTNERED`
102    /// - `PREVIEW_ENABLED`
103    /// - `PRIVATE_THREADS`
104    /// - `ROLE_ICONS`
105    /// - `SEVEN_DAY_THREAD_ARCHIVE`
106    /// - `THREE_DAY_THREAD_ARCHIVE`
107    /// - `TICKETED_EVENTS_ENABLED`
108    /// - `VANITY_URL`
109    /// - `VERIFIED`
110    /// - `VIP_REGIONS`
111    /// - `WELCOME_SCREEN_ENABLED`
112    /// - `THREE_DAY_THREAD_ARCHIVE`
113    /// - `SEVEN_DAY_THREAD_ARCHIVE`
114    /// - `PRIVATE_THREADS`
115    ///
116    ///
117    /// [`discord documentation`]: https://discord.com/developers/docs/resources/guild#guild-object-guild-features
118    pub features: Vec<String>,
119    /// Indicator of whether the guild requires multi-factor authentication for [`Role`]s or
120    /// [`User`]s with moderation permissions.
121    pub mfa_level: MfaLevel,
122    /// Application ID of the guild creator if it is bot-created.
123    pub application_id: Option<ApplicationId>,
124    /// The ID of the channel to which system messages are sent.
125    pub system_channel_id: Option<ChannelId>,
126    /// System channel flags.
127    pub system_channel_flags: SystemChannelFlags,
128    /// The id of the channel where rules and/or guidelines are displayed.
129    ///
130    /// **Note**: Only available on `COMMUNITY` guild, see [`Self::features`].
131    pub rules_channel_id: Option<ChannelId>,
132    /// The maximum number of presences for the guild. The default value is currently 25000.
133    ///
134    /// **Note**: It is in effect when it is `None`.
135    pub max_presences: Option<u64>,
136    /// The maximum number of members for the guild.
137    pub max_members: Option<u64>,
138    /// The vanity url code for the guild, if it has one.
139    pub vanity_url_code: Option<String>,
140    /// The server's description, if it has one.
141    pub description: Option<String>,
142    /// The guild's banner, if it has one.
143    pub banner: Option<String>,
144    /// The server's premium boosting level.
145    pub premium_tier: PremiumTier,
146    /// The total number of users currently boosting this server.
147    pub premium_subscription_count: Option<u64>,
148    /// The preferred locale of this guild only set if guild has the "DISCOVERABLE" feature,
149    /// defaults to en-US.
150    pub preferred_locale: String,
151    /// The id of the channel where admins and moderators of Community guilds receive notices from
152    /// Discord.
153    ///
154    /// **Note**: Only available on `COMMUNITY` guild, see [`Self::features`].
155    pub public_updates_channel_id: Option<ChannelId>,
156    /// The maximum amount of users in a video channel.
157    pub max_video_channel_users: Option<u64>,
158    /// The maximum amount of users in a stage video channel
159    pub max_stage_video_channel_users: Option<u64>,
160    /// Approximate number of members in this guild.
161    pub approximate_member_count: Option<u64>,
162    /// Approximate number of non-offline members in this guild.
163    pub approximate_presence_count: Option<u64>,
164    /// The welcome screen of the guild.
165    ///
166    /// **Note**: Only available on `COMMUNITY` guild, see [`Self::features`].
167    pub welcome_screen: Option<GuildWelcomeScreen>,
168    /// The guild NSFW state. See [`discord support article`].
169    ///
170    /// [`discord support article`]: https://support.discord.com/hc/en-us/articles/1500005389362-NSFW-Server-Designation
171    pub nsfw_level: NsfwLevel,
172    /// All of the guild's custom stickers.
173    #[serde(with = "stickers")]
174    pub stickers: HashMap<StickerId, Sticker>,
175    /// Whether the guild has the boost progress bar enabled
176    pub premium_progress_bar_enabled: bool,
177}
178
179#[cfg(feature = "model")]
180impl PartialGuild {
181    /// Gets all auto moderation [`Rule`]s of this guild via HTTP.
182    ///
183    /// **Note**: Requires the [Manage Guild] permission.
184    ///
185    /// # Errors
186    ///
187    /// Returns [`Error::Http`] if the guild is unavailable.
188    ///
189    /// [Manage Guild]: Permissions::MANAGE_GUILD
190    #[inline]
191    pub async fn automod_rules(self, http: impl AsRef<Http>) -> Result<Vec<Rule>> {
192        self.id.automod_rules(http).await
193    }
194
195    /// Gets an auto moderation [`Rule`] of this guild by its ID via HTTP.
196    ///
197    /// **Note**: Requires the [Manage Guild] permission.
198    ///
199    /// # Errors
200    ///
201    /// Returns [`Error::Http`] if a rule with the given ID does not exist.
202    ///
203    /// [Manage Guild]: Permissions::MANAGE_GUILD
204    #[inline]
205    pub async fn automod_rule(
206        &self,
207        http: impl AsRef<Http>,
208        rule_id: impl Into<RuleId>,
209    ) -> Result<Rule> {
210        self.id.automod_rule(http, rule_id).await
211    }
212
213    /// Creates an auto moderation [`Rule`] in the guild.
214    ///
215    /// **Note**: Requires the [Manage Guild] permission.
216    ///
217    /// # Examples
218    ///
219    /// See [`GuildId::create_automod_rule`] for details.
220    ///
221    /// # Errors
222    ///
223    /// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
224    ///
225    /// [Manage Guild]: Permissions::MANAGE_GUILD
226    #[inline]
227    pub async fn create_automod_rule(
228        &self,
229        cache_http: impl CacheHttp,
230        builder: EditAutoModRule<'_>,
231    ) -> Result<Rule> {
232        self.id.create_automod_rule(cache_http, builder).await
233    }
234
235    /// Edit an auto moderation [`Rule`], given its Id.
236    ///
237    /// **Note**: Requires the [Manage Guild] permission.
238    ///
239    /// # Errors
240    ///
241    /// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
242    ///
243    /// [Manage Guild]: Permissions::MANAGE_GUILD
244    #[inline]
245    pub async fn edit_automod_rule(
246        &self,
247        cache_http: impl CacheHttp,
248        rule_id: impl Into<RuleId>,
249        builder: EditAutoModRule<'_>,
250    ) -> Result<Rule> {
251        self.id.edit_automod_rule(cache_http, rule_id, builder).await
252    }
253
254    /// Deletes an auto moderation [`Rule`] from the guild.
255    ///
256    /// **Note**: Requires the [Manage Guild] permission.
257    ///
258    /// # Errors
259    ///
260    /// Returns [`Error::Http`] if the current user lacks permission, or if a rule with that Id
261    /// does not exist.
262    ///
263    /// [Manage Guild]: Permissions::MANAGE_GUILD
264    #[inline]
265    pub async fn delete_automod_rule(
266        &self,
267        http: impl AsRef<Http>,
268        rule_id: impl Into<RuleId>,
269    ) -> Result<()> {
270        self.id.delete_automod_rule(http, rule_id).await
271    }
272
273    /// Ban a [`User`] from the guild, deleting a number of days' worth of messages (`dmd`) between
274    /// the range 0 and 7.
275    ///
276    /// **Note**: Requires the [Ban Members] permission.
277    ///
278    /// # Examples
279    ///
280    /// Ban a member and remove all messages they've sent in the last 4 days:
281    ///
282    /// ```rust,ignore
283    /// // assumes a `user` and `guild` have already been bound
284    /// let _ = guild.ban(user, 4);
285    /// ```
286    ///
287    /// # Errors
288    ///
289    /// Returns a [`ModelError::DeleteMessageDaysAmount`] if the number of days' worth of messages
290    /// to delete is over the maximum.
291    ///
292    /// Also may return [`Error::Http`] if the current user lacks permission.
293    ///
294    /// [Ban Members]: Permissions::BAN_MEMBERS
295    #[inline]
296    pub async fn ban(
297        &self,
298        http: impl AsRef<Http>,
299        user: impl Into<UserId>,
300        dmd: u8,
301    ) -> Result<()> {
302        self.ban_with_reason(http, user, dmd, "").await
303    }
304
305    /// Ban a [`User`] from the guild with a reason. Refer to [`Self::ban`] to further
306    /// documentation.
307    ///
308    /// # Errors
309    ///
310    /// In addition to the reasons [`Self::ban`] may return an error, can also return an error if
311    /// the reason is too long.
312    #[inline]
313    pub async fn ban_with_reason(
314        &self,
315        http: impl AsRef<Http>,
316        user: impl Into<UserId>,
317        dmd: u8,
318        reason: impl AsRef<str>,
319    ) -> Result<()> {
320        self.id.ban_with_reason(http, user, dmd, reason).await
321    }
322
323    /// Gets a list of the guild's bans, with additional options and filtering. See
324    /// [`Http::get_bans`] for details.
325    ///
326    /// Requires the [Ban Members] permission.
327    ///
328    /// # Errors
329    ///
330    /// Returns [`Error::Http`] if the current user lacks permission.
331    ///
332    /// [Ban Members]: Permissions::BAN_MEMBERS
333    #[inline]
334    pub async fn bans(
335        &self,
336        http: impl AsRef<Http>,
337        target: Option<UserPagination>,
338        limit: Option<u8>,
339    ) -> Result<Vec<Ban>> {
340        self.id.bans(http, target, limit).await
341    }
342
343    /// Gets a list of the guild's audit log entries
344    ///
345    /// **Note**: Requires the [View Audit Log] permission.
346    ///
347    /// # Errors
348    ///
349    /// Returns [`Error::Http`] if the current user lacks permission, or if an invalid value is
350    /// given.
351    ///
352    /// [View Audit Log]: Permissions::VIEW_AUDIT_LOG
353    #[inline]
354    pub async fn audit_logs(
355        &self,
356        http: impl AsRef<Http>,
357        action_type: Option<audit_log::Action>,
358        user_id: Option<UserId>,
359        before: Option<AuditLogEntryId>,
360        limit: Option<u8>,
361    ) -> Result<AuditLogs> {
362        self.id.audit_logs(http, action_type, user_id, before, limit).await
363    }
364
365    /// Gets all of the guild's channels over the REST API.
366    ///
367    /// # Errors
368    ///
369    /// Returns [`Error::Http`] if the current user is not in the guild or if the guild is
370    /// otherwise unavailable.
371    #[inline]
372    pub async fn channels(
373        &self,
374        http: impl AsRef<Http>,
375    ) -> Result<HashMap<ChannelId, GuildChannel>> {
376        self.id.channels(http).await
377    }
378
379    #[cfg(feature = "cache")]
380    #[deprecated = "Use Cache::guild and Guild::channels"]
381    pub fn channel_id_from_name(
382        &self,
383        cache: impl AsRef<Cache>,
384        name: impl AsRef<str>,
385    ) -> Option<ChannelId> {
386        let cache = cache.as_ref();
387        let guild = cache.guild(self.id)?;
388        #[allow(deprecated)]
389        guild.channel_id_from_name(cache, name)
390    }
391
392    /// Creates a [`GuildChannel`] in the guild.
393    ///
394    /// Refer to [`Http::create_channel`] for more information.
395    ///
396    /// **Note**: Requires the [Manage Channels] permission.
397    ///
398    /// # Examples
399    ///
400    /// Create a voice channel in a guild with the name `test`:
401    ///
402    /// ```rust,no_run
403    /// # use serenity::http::Http;
404    /// # use serenity::model::guild::PartialGuild;
405    /// # use serenity::model::id::GuildId;
406    /// use serenity::builder::CreateChannel;
407    /// use serenity::model::channel::ChannelType;
408    ///
409    /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
410    /// # let http: Http = unimplemented!();
411    /// # let guild = PartialGuild::get(&http, GuildId::new(7)).await?;
412    /// let builder = CreateChannel::new("my-test-channel").kind(ChannelType::Text);
413    ///
414    /// // assuming a `guild` has already been bound
415    /// let _channel = guild.create_channel(&http, builder).await?;
416    /// # Ok(())
417    /// # }
418    /// ```
419    ///
420    /// # Errors
421    ///
422    /// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
423    /// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
424    ///
425    /// [Manage Channels]: Permissions::MANAGE_CHANNELS
426    pub async fn create_channel(
427        &self,
428        cache_http: impl CacheHttp,
429        builder: CreateChannel<'_>,
430    ) -> Result<GuildChannel> {
431        self.id.create_channel(cache_http, builder).await
432    }
433
434    /// Creates an emoji in the guild with a name and base64-encoded image.
435    ///
436    /// Refer to the documentation for [`Guild::create_emoji`] for more information.
437    ///
438    /// Requires the [Create Guild Expressions] permission.
439    ///
440    /// # Examples
441    ///
442    /// See the [`EditProfile::avatar`] example for an in-depth example as to how to read an image
443    /// from the filesystem and encode it as base64. Most of the example can be applied similarly
444    /// for this method.
445    ///
446    /// # Errors
447    ///
448    /// Returns [`Error::Http`] if the current user lacks permission, if the emoji name is too
449    /// long, or if the image is too large.
450    ///
451    /// [`EditProfile::avatar`]: crate::builder::EditProfile::avatar
452    /// [`utils::read_image`]: crate::utils::read_image
453    /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
454    #[inline]
455    pub async fn create_emoji(
456        &self,
457        http: impl AsRef<Http>,
458        name: &str,
459        image: &str,
460    ) -> Result<Emoji> {
461        self.id.create_emoji(http, name, image).await
462    }
463
464    /// Creates an integration for the guild.
465    ///
466    /// Requires the [Manage Guild] permission.
467    ///
468    /// # Errors
469    ///
470    /// Returns [`Error::Http`] if the current user lacks permission.
471    ///
472    /// [Manage Guild]: Permissions::MANAGE_GUILD
473    #[inline]
474    pub async fn create_integration(
475        &self,
476        http: impl AsRef<Http>,
477        integration_id: impl Into<IntegrationId>,
478        kind: &str,
479    ) -> Result<()> {
480        self.id.create_integration(http, integration_id, kind).await
481    }
482
483    /// Create a guild specific application [`Command`].
484    ///
485    /// **Note**: Unlike global commands, guild commands will update instantly.
486    ///
487    /// # Errors
488    ///
489    /// See [`CreateCommand::execute`] for a list of possible errors.
490    ///
491    /// [`CreateCommand::execute`]: ../../builder/struct.CreateCommand.html#method.execute
492    #[inline]
493    pub async fn create_command(
494        &self,
495        cache_http: impl CacheHttp,
496        builder: CreateCommand,
497    ) -> Result<Command> {
498        self.id.create_command(cache_http, builder).await
499    }
500
501    /// Override all guild application commands.
502    ///
503    /// # Errors
504    ///
505    /// Returns the same errors as [`Self::create_command`].
506    pub async fn set_commands(
507        &self,
508        http: impl AsRef<Http>,
509        commands: Vec<CreateCommand>,
510    ) -> Result<Vec<Command>> {
511        self.id.set_commands(http, commands).await
512    }
513
514    /// Overwrites permissions for a specific command.
515    ///
516    /// **Note**: It will update instantly.
517    ///
518    /// # Errors
519    ///
520    /// See [`CreateCommandPermissionsData::execute`] for a list of possible errors.
521    ///
522    /// [`CreateCommandPermissionsData::execute`]: ../../builder/struct.CreateCommandPermissionsData.html#method.execute
523    pub async fn edit_command_permissions(
524        &self,
525        cache_http: impl CacheHttp,
526        command_id: CommandId,
527        builder: EditCommandPermissions,
528    ) -> Result<CommandPermissions> {
529        self.id.edit_command_permissions(cache_http, command_id, builder).await
530    }
531
532    /// Get all guild application commands.
533    ///
534    /// # Errors
535    ///
536    /// If there is an error, it will be either [`Error::Http`] or [`Error::Json`].
537    pub async fn get_commands(&self, http: impl AsRef<Http>) -> Result<Vec<Command>> {
538        self.id.get_commands(http).await
539    }
540
541    /// Get all guild application commands with localizations.
542    ///
543    /// # Errors
544    ///
545    /// If there is an error, it will be either [`Error::Http`] or [`Error::Json`].
546    pub async fn get_commands_with_localizations(
547        &self,
548        http: impl AsRef<Http>,
549    ) -> Result<Vec<Command>> {
550        self.id.get_commands_with_localizations(http).await
551    }
552
553    /// Get a specific guild application command by its Id.
554    ///
555    /// # Errors
556    ///
557    /// If there is an error, it will be either [`Error::Http`] or [`Error::Json`].
558    pub async fn get_command(
559        &self,
560        http: impl AsRef<Http>,
561        command_id: CommandId,
562    ) -> Result<Command> {
563        self.id.get_command(http, command_id).await
564    }
565
566    /// Edit a guild application command, given its Id.
567    ///
568    /// # Errors
569    ///
570    /// See [`CreateCommand::execute`] for a list of possible errors.
571    ///
572    /// [`CreateCommand::execute`]: ../../builder/struct.CreateCommand.html#method.execute
573    pub async fn edit_command(
574        &self,
575        cache_http: impl CacheHttp,
576        command_id: CommandId,
577        builder: CreateCommand,
578    ) -> Result<Command> {
579        self.id.edit_command(cache_http, command_id, builder).await
580    }
581
582    /// Delete guild application command by its Id.
583    ///
584    /// # Errors
585    ///
586    /// If there is an error, it will be either [`Error::Http`] or [`Error::Json`].
587    pub async fn delete_command(
588        &self,
589        http: impl AsRef<Http>,
590        command_id: CommandId,
591    ) -> Result<()> {
592        self.id.delete_command(http, command_id).await
593    }
594
595    /// Get all guild application commands permissions only.
596    ///
597    /// # Errors
598    ///
599    /// If there is an error, it will be either [`Error::Http`] or [`Error::Json`].
600    pub async fn get_commands_permissions(
601        &self,
602        http: impl AsRef<Http>,
603    ) -> Result<Vec<CommandPermissions>> {
604        self.id.get_commands_permissions(http).await
605    }
606
607    /// Get permissions for specific guild application command by its Id.
608    ///
609    /// # Errors
610    ///
611    /// If there is an error, it will be either [`Error::Http`] or [`Error::Json`].
612    pub async fn get_command_permissions(
613        &self,
614        http: impl AsRef<Http>,
615        command_id: CommandId,
616    ) -> Result<CommandPermissions> {
617        self.id.get_command_permissions(http, command_id).await
618    }
619
620    /// Creates a new role in the guild with the data set, if any.
621    ///
622    /// See the documentation for [`Guild::create_role`] on how to use this.
623    ///
624    /// **Note**: Requires the [Manage Roles] permission.
625    ///
626    /// # Errors
627    ///
628    /// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
629    /// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
630    ///
631    /// [Manage Roles]: Permissions::MANAGE_ROLES
632    #[inline]
633    pub async fn create_role(
634        &self,
635        cache_http: impl CacheHttp,
636        builder: EditRole<'_>,
637    ) -> Result<Role> {
638        self.id.create_role(cache_http, builder).await
639    }
640
641    /// Creates a new sticker in the guild with the data set, if any.
642    ///
643    /// **Note**: Requires the [Create Guild Expressions] permission.
644    ///
645    /// # Errors
646    ///
647    /// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
648    /// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
649    ///
650    /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
651    pub async fn create_sticker(
652        &self,
653        cache_http: impl CacheHttp,
654        builder: CreateSticker<'_>,
655    ) -> Result<Sticker> {
656        self.id.create_sticker(cache_http, builder).await
657    }
658
659    /// Deletes the current guild if the current user is the owner of the
660    /// guild.
661    ///
662    /// **Note**: Requires the current user to be the owner of the guild.
663    ///
664    /// # Errors
665    ///
666    /// Returns [`Error::Http`] if the current user is not the owner of
667    /// the guild.
668    #[inline]
669    pub async fn delete(&self, http: impl AsRef<Http>) -> Result<()> {
670        self.id.delete(http).await
671    }
672
673    /// Deletes an [`Emoji`] from the guild.
674    ///
675    /// **Note**: If the emoji was created by the current user, requires either the [Create Guild
676    /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
677    /// Expressions] permission is required.
678    ///
679    /// # Errors
680    ///
681    /// Returns [`Error::Http`] if the current user lacks permission, or if an emoji with the given
682    /// id does not exist in the guild.
683    ///
684    /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
685    /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS
686    #[inline]
687    pub async fn delete_emoji(
688        &self,
689        http: impl AsRef<Http>,
690        emoji_id: impl Into<EmojiId>,
691    ) -> Result<()> {
692        self.id.delete_emoji(http, emoji_id).await
693    }
694
695    /// Deletes an integration by Id from the guild.
696    ///
697    /// Requires the [Manage Guild] permission.
698    ///
699    /// # Errors
700    ///
701    /// Returns [`Error::Http`] if the current user lacks permission, or if an integration with
702    /// that Id does not exist in the guild.
703    ///
704    /// [Manage Guild]: Permissions::MANAGE_GUILD
705    #[inline]
706    pub async fn delete_integration(
707        &self,
708        http: impl AsRef<Http>,
709        integration_id: impl Into<IntegrationId>,
710    ) -> Result<()> {
711        self.id.delete_integration(http, integration_id).await
712    }
713
714    /// Deletes a [`Role`] by Id from the guild.
715    ///
716    /// Also see [`Role::delete`] if you have the `cache` and `model` features enabled.
717    ///
718    /// Requires the [Manage Roles] permission.
719    ///
720    /// # Errors
721    ///
722    /// Returns [`Error::Http`] if the current user lacks permission, or if a Role with that Id
723    /// does not exist in the Guild.
724    ///
725    /// [Manage Roles]: Permissions::MANAGE_ROLES
726    #[inline]
727    pub async fn delete_role(
728        &self,
729        http: impl AsRef<Http>,
730        role_id: impl Into<RoleId>,
731    ) -> Result<()> {
732        self.id.delete_role(http, role_id).await
733    }
734
735    /// Deletes a [`Sticker`] by Id from the guild.
736    ///
737    /// **Note**: If the sticker was created by the current user, requires either the [Create Guild
738    /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
739    /// Expressions] permission is required.
740    ///
741    /// # Errors
742    ///
743    /// Returns [`Error::Http`] if the current user lacks permission, or if a sticker with that id
744    /// does not exist.
745    ///
746    /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
747    /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS
748    #[inline]
749    pub async fn delete_sticker(
750        &self,
751        http: impl AsRef<Http>,
752        sticker_id: impl Into<StickerId>,
753    ) -> Result<()> {
754        self.id.delete_sticker(http, sticker_id).await
755    }
756
757    /// Edits the current guild with new data where specified.
758    ///
759    /// **Note**: Requires the [Manage Guild] permission.
760    ///
761    /// # Errors
762    ///
763    /// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
764    /// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
765    ///
766    /// [Manage Guild]: Permissions::MANAGE_GUILD
767    pub async fn edit(&mut self, cache_http: impl CacheHttp, builder: EditGuild<'_>) -> Result<()> {
768        let guild = self.id.edit(cache_http, builder).await?;
769
770        self.afk_metadata = guild.afk_metadata;
771        self.default_message_notifications = guild.default_message_notifications;
772        self.emojis = guild.emojis;
773        self.features = guild.features;
774        self.icon = guild.icon;
775        self.mfa_level = guild.mfa_level;
776        self.name = guild.name;
777        self.owner_id = guild.owner_id;
778        self.roles = guild.roles;
779        self.splash = guild.splash;
780        self.verification_level = guild.verification_level;
781
782        Ok(())
783    }
784
785    /// Edits an [`Emoji`]'s name in the guild.
786    ///
787    /// Also see [`Emoji::edit`] if you have the `cache` and `methods` features enabled.
788    ///
789    /// **Note**: If the emoji was created by the current user, requires either the [Create Guild
790    /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
791    /// Expressions] permission is required.
792    ///
793    /// # Errors
794    ///
795    /// Returns [`Error::Http`] if the current user lacks permission, or if an emoji with the given
796    /// id does not exist.
797    ///
798    /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
799    /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS
800    #[inline]
801    pub async fn edit_emoji(
802        &self,
803        http: impl AsRef<Http>,
804        emoji_id: impl Into<EmojiId>,
805        name: &str,
806    ) -> Result<Emoji> {
807        self.id.edit_emoji(http, emoji_id, name).await
808    }
809
810    /// Edits the properties a guild member, such as muting or nicknaming them. Returns the new
811    /// member.
812    ///
813    /// Refer to the documentation of [`EditMember`] for a full list of methods and permission
814    /// restrictions.
815    ///
816    /// # Examples
817    ///
818    /// See [`GuildId::edit_member`] for details.
819    ///
820    /// # Errors
821    ///
822    /// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
823    #[inline]
824    pub async fn edit_member(
825        &self,
826        cache_http: impl CacheHttp,
827        user_id: impl Into<UserId>,
828        builder: EditMember<'_>,
829    ) -> Result<Member> {
830        self.id.edit_member(cache_http, user_id, builder).await
831    }
832
833    /// Edits the guild's MFA level. Returns the new level on success.
834    ///
835    /// Requires guild ownership.
836    ///
837    /// # Errors
838    ///
839    /// Returns [`Error::Http`] if the current user lacks permission.
840    pub async fn edit_mfa_level(
841        &self,
842        http: impl AsRef<Http>,
843        mfa_level: MfaLevel,
844        audit_log_reason: Option<&str>,
845    ) -> Result<MfaLevel> {
846        self.id.edit_mfa_level(http, mfa_level, audit_log_reason).await
847    }
848
849    /// Edits the current user's nickname for the guild.
850    ///
851    /// Pass [`None`] to reset the nickname.
852    ///
853    /// **Note**: Requires the [Change Nickname] permission.
854    ///
855    /// # Errors
856    ///
857    /// Returns [`Error::Http`] if the current user lacks permission to change their nickname.
858    ///
859    /// [Change Nickname]: Permissions::CHANGE_NICKNAME
860    #[inline]
861    pub async fn edit_nickname(
862        &self,
863        http: impl AsRef<Http>,
864        new_nickname: Option<&str>,
865    ) -> Result<()> {
866        self.id.edit_nickname(http, new_nickname).await
867    }
868
869    /// Edits a role, optionally setting its fields.
870    ///
871    /// **Note**: Requires the [Manage Roles] permission.
872    ///
873    /// # Examples
874    ///
875    /// See the documentation of [`GuildId::edit_role`] for details.
876    ///
877    /// # Errors
878    ///
879    /// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
880    /// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
881    ///
882    /// [Manage Roles]: Permissions::MANAGE_ROLES
883    #[inline]
884    pub async fn edit_role(
885        &self,
886        cache_http: impl CacheHttp,
887        role_id: impl Into<RoleId>,
888        builder: EditRole<'_>,
889    ) -> Result<Role> {
890        self.id.edit_role(cache_http, role_id, builder).await
891    }
892
893    /// Edits the order of [`Role`]s. Requires the [Manage Roles] permission.
894    ///
895    /// # Examples
896    ///
897    /// Change the order of a role:
898    ///
899    /// ```rust,ignore
900    /// use serenity::model::id::RoleId;
901    /// partial_guild.edit_role_position(&context, RoleId::new(8), 2);
902    /// ```
903    ///
904    /// # Errors
905    ///
906    /// Returns [`Error::Http`] if the current user lacks permission.
907    ///
908    /// [Manage Roles]: Permissions::MANAGE_ROLES
909    #[inline]
910    pub async fn edit_role_position(
911        &self,
912        http: impl AsRef<Http>,
913        role_id: impl Into<RoleId>,
914        position: u16,
915    ) -> Result<Vec<Role>> {
916        self.id.edit_role_position(http, role_id, position).await
917    }
918
919    /// Edits a sticker.
920    ///
921    /// **Note**: If the sticker was created by the current user, requires either the [Create Guild
922    /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
923    /// Expressions] permission is required.
924    ///
925    /// # Examples
926    ///
927    /// Rename a sticker:
928    ///
929    /// ```rust,no_run
930    /// # use serenity::http::Http;
931    /// # use serenity::model::guild::PartialGuild;
932    /// # use serenity::model::id::GuildId;
933    /// use serenity::builder::EditSticker;
934    /// use serenity::model::id::StickerId;
935    ///
936    /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
937    /// # let http: Http = unimplemented!();
938    /// # let guild = PartialGuild::get(&http, GuildId::new(7)).await?;
939    /// let builder = EditSticker::new().name("Bun bun meow");
940    /// guild.edit_sticker(&http, StickerId::new(7), builder).await?;
941    /// # Ok(())
942    /// # }
943    /// ```
944    ///
945    /// # Errors
946    ///
947    /// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
948    ///
949    /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
950    /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS
951    #[inline]
952    pub async fn edit_sticker(
953        &self,
954        cache_http: impl CacheHttp,
955        sticker_id: impl Into<StickerId>,
956        builder: EditSticker<'_>,
957    ) -> Result<Sticker> {
958        self.id.edit_sticker(cache_http, sticker_id, builder).await
959    }
960
961    /// Edits the guild's welcome screen.
962    ///
963    /// **Note**: Requires the [Manage Guild] permission.
964    ///
965    /// # Errors
966    ///
967    /// Returns [`Error::Http`] if the current user lacks permission.
968    ///
969    /// [Manage Guild]: Permissions::MANAGE_GUILD
970    pub async fn edit_welcome_screen(
971        &self,
972        cache_http: impl CacheHttp,
973        builder: EditGuildWelcomeScreen<'_>,
974    ) -> Result<GuildWelcomeScreen> {
975        self.id.edit_welcome_screen(cache_http, builder).await
976    }
977
978    /// Edits the guild's widget.
979    ///
980    /// **Note**: Requires the [Manage Guild] permission.
981    ///
982    /// # Errors
983    ///
984    /// Returns [`Error::Http`] if the current user lacks permission.
985    ///
986    /// [Manage Guild]: Permissions::MANAGE_GUILD
987    pub async fn edit_widget(
988        &self,
989        cache_http: impl CacheHttp,
990        builder: EditGuildWidget<'_>,
991    ) -> Result<GuildWidget> {
992        self.id.edit_widget(cache_http, builder).await
993    }
994
995    /// Gets a partial amount of guild data by its Id.
996    ///
997    /// # Errors
998    ///
999    /// Returns [`Error::Http`] if the current user is not
1000    /// in the guild.
1001    #[inline]
1002    pub async fn get(
1003        cache_http: impl CacheHttp,
1004        guild_id: impl Into<GuildId>,
1005    ) -> Result<PartialGuild> {
1006        guild_id.into().to_partial_guild(cache_http).await
1007    }
1008
1009    /// Returns which of two [`User`]s has a higher [`Member`] hierarchy.
1010    ///
1011    /// Hierarchy is essentially who has the [`Role`] with the highest [`position`].
1012    ///
1013    /// Returns [`None`] if at least one of the given users' member instances is not present.
1014    /// Returns [`None`] if the users have the same hierarchy, as neither are greater than the
1015    /// other.
1016    ///
1017    /// If both user IDs are the same, [`None`] is returned. If one of the users is the guild
1018    /// owner, their ID is returned.
1019    ///
1020    /// [`position`]: Role::position
1021    #[cfg(feature = "cache")]
1022    #[inline]
1023    #[deprecated = "Use Cache::guild and Guild::greater_member_hierarchy"]
1024    pub fn greater_member_hierarchy(
1025        &self,
1026        cache: impl AsRef<Cache>,
1027        lhs_id: impl Into<UserId>,
1028        rhs_id: impl Into<UserId>,
1029    ) -> Option<UserId> {
1030        let cache = cache.as_ref();
1031        let guild = cache.guild(self.id)?;
1032        guild.greater_member_hierarchy(cache, lhs_id, rhs_id)
1033    }
1034
1035    /// Calculate a [`Member`]'s permissions in the guild.
1036    #[inline]
1037    #[must_use]
1038    #[deprecated = "Use PartialGuild::member_permissions_in, as this doesn't consider permission overwrites"]
1039    pub fn member_permissions(&self, member: &Member) -> Permissions {
1040        Guild::user_permissions_in_(
1041            None,
1042            member.user.id,
1043            &member.roles,
1044            self.id,
1045            &self.roles,
1046            self.owner_id,
1047        )
1048    }
1049
1050    /// Calculate a [`PartialMember`]'s permissions in the guild.
1051    ///
1052    /// # Panics
1053    ///
1054    /// Panics if the passed [`UserId`] does not match the [`PartialMember`] id, if user is Some.
1055    #[inline]
1056    #[must_use]
1057    #[deprecated = "Use PartialGuild::partial_member_permissions_in, as this doesn't consider permission overwrites"]
1058    pub fn partial_member_permissions(
1059        &self,
1060        member_id: UserId,
1061        member: &PartialMember,
1062    ) -> Permissions {
1063        if let Some(user) = &member.user {
1064            assert_eq!(user.id, member_id, "User::id does not match provided PartialMember");
1065        }
1066
1067        Guild::user_permissions_in_(
1068            None,
1069            member_id,
1070            &member.roles,
1071            self.id,
1072            &self.roles,
1073            self.owner_id,
1074        )
1075    }
1076
1077    /// Calculate a [`PartialMember`]'s permissions in a given channel in a guild.
1078    ///
1079    /// # Panics
1080    ///
1081    /// Panics if the passed [`UserId`] does not match the [`PartialMember`] id, if user is Some.
1082    #[must_use]
1083    pub fn partial_member_permissions_in(
1084        &self,
1085        channel: &GuildChannel,
1086        member_id: UserId,
1087        member: &PartialMember,
1088    ) -> Permissions {
1089        if let Some(user) = &member.user {
1090            assert_eq!(user.id, member_id, "User::id does not match provided PartialMember");
1091        }
1092
1093        Guild::user_permissions_in_(
1094            Some(channel),
1095            member_id,
1096            &member.roles,
1097            self.id,
1098            &self.roles,
1099            self.owner_id,
1100        )
1101    }
1102
1103    /// Re-orders the channels of the guild.
1104    ///
1105    /// Although not required, you should specify all channels' positions, regardless of whether
1106    /// they were updated. Otherwise, positioning can sometimes get weird.
1107    ///
1108    /// **Note**: Requires the [Manage Channels] permission.
1109    ///
1110    /// # Errors
1111    ///
1112    /// Returns an [`Error::Http`] if the current user is lacking permission.
1113    ///
1114    /// [Manage Channels]: Permissions::MANAGE_CHANNELS
1115    #[inline]
1116    pub async fn reorder_channels(
1117        &self,
1118        http: impl AsRef<Http>,
1119        channels: impl IntoIterator<Item = (ChannelId, u64)>,
1120    ) -> Result<()> {
1121        self.id.reorder_channels(http, channels).await
1122    }
1123
1124    /// Returns a list of [`Member`]s in a [`Guild`] whose username or nickname starts with a
1125    /// provided string.
1126    ///
1127    /// Optionally pass in the `limit` to limit the number of results. Minimum value is 1, maximum
1128    /// and default value is 1000.
1129    ///
1130    /// **Note**: Queries are case insensitive.
1131    ///
1132    /// # Errors
1133    ///
1134    /// Returns an [`Error::Http`] if the API returns an error.
1135    #[inline]
1136    pub async fn search_members(
1137        &self,
1138        http: impl AsRef<Http>,
1139        query: &str,
1140        limit: Option<u64>,
1141    ) -> Result<Vec<Member>> {
1142        self.id.search_members(http, query, limit).await
1143    }
1144
1145    /// Starts a prune of [`Member`]s.
1146    ///
1147    /// See the documentation on [`GuildPrune`] for more information.
1148    ///
1149    /// **Note**: Requires [Kick Members] and [Manage Guild] permissions.
1150    ///
1151    /// # Errors
1152    ///
1153    /// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
1154    /// does not have permission to kick members.
1155    ///
1156    /// Otherwise will return [`Error::Http`] if the current user does not have permission.
1157    ///
1158    /// Can also return an [`Error::Json`] if there is an error deserializing the API response.
1159    ///
1160    /// [Kick Members]: Permissions::KICK_MEMBERS
1161    /// [Manage Guild]: Permissions::MANAGE_GUILD
1162    /// [`Error::Http`]: crate::error::Error::Http
1163    /// [`Error::Json`]: crate::error::Error::Json
1164    pub async fn start_prune(&self, cache_http: impl CacheHttp, days: u8) -> Result<GuildPrune> {
1165        self.id.start_prune(cache_http.http(), days).await
1166    }
1167
1168    /// Kicks a [`Member`] from the guild.
1169    ///
1170    /// Requires the [Kick Members] permission.
1171    ///
1172    /// # Errors
1173    ///
1174    /// Returns [`Error::Http`] if the member cannot be kicked by the current user.
1175    ///
1176    /// [Kick Members]: Permissions::KICK_MEMBERS
1177    #[inline]
1178    pub async fn kick(&self, http: impl AsRef<Http>, user_id: impl Into<UserId>) -> Result<()> {
1179        self.id.kick(http, user_id).await
1180    }
1181
1182    /// # Errors
1183    ///
1184    /// In addition to the reasons [`Self::kick`] may return an error, can also return an error if
1185    /// the reason is too long.
1186    #[inline]
1187    pub async fn kick_with_reason(
1188        &self,
1189        http: impl AsRef<Http>,
1190        user_id: impl Into<UserId>,
1191        reason: &str,
1192    ) -> Result<()> {
1193        self.id.kick_with_reason(http, user_id, reason).await
1194    }
1195
1196    /// Returns a formatted URL of the guild's icon, if the guild has an icon.
1197    #[must_use]
1198    pub fn icon_url(&self) -> Option<String> {
1199        icon_url(self.id, self.icon.as_ref())
1200    }
1201
1202    /// Returns a formatted URL of the guild's banner, if the guild has a banner.
1203    #[must_use]
1204    pub fn banner_url(&self) -> Option<String> {
1205        self.banner.as_ref().map(|banner| cdn!("/banners/{}/{}.webp", self.id, banner))
1206    }
1207
1208    /// Gets all [`Emoji`]s of this guild via HTTP.
1209    ///
1210    /// # Errors
1211    ///
1212    /// Returns [`Error::Http`] if the guild is unavailable.
1213    #[inline]
1214    pub async fn emojis(&self, http: impl AsRef<Http>) -> Result<Vec<Emoji>> {
1215        self.id.emojis(http).await
1216    }
1217
1218    /// Gets an [`Emoji`] of this guild by its ID via HTTP.
1219    ///
1220    /// # Errors
1221    ///
1222    /// Returns [`Error::Http`] if an [`Emoji`] with the given Id does not exist for the guild.
1223    #[inline]
1224    pub async fn emoji(&self, http: impl AsRef<Http>, emoji_id: EmojiId) -> Result<Emoji> {
1225        self.id.emoji(http, emoji_id).await
1226    }
1227
1228    /// Gets all integration of the guild.
1229    ///
1230    /// Requires the [Manage Guild] permission.
1231    ///
1232    /// # Errors
1233    ///
1234    /// Returns [`Error::Http`] if the current user lacks permission.
1235    ///
1236    /// [Manage Guild]: Permissions::MANAGE_GUILD
1237    #[inline]
1238    pub async fn integrations(&self, http: impl AsRef<Http>) -> Result<Vec<Integration>> {
1239        self.id.integrations(http).await
1240    }
1241
1242    /// Gets all of the guild's invites.
1243    ///
1244    /// Requires the [Manage Guild] permission.
1245    ///
1246    /// # Errors
1247    ///
1248    /// Returns [`Error::Http`] if the current user lacks permission.
1249    ///
1250    /// [Manage Guild]: Permissions::MANAGE_GUILD
1251    #[inline]
1252    pub async fn invites(&self, http: impl AsRef<Http>) -> Result<Vec<RichInvite>> {
1253        self.id.invites(http).await
1254    }
1255
1256    /// Returns a guild [`Member`] object for the current user.
1257    ///
1258    /// See [`Http::get_current_user_guild_member`] for more.
1259    ///
1260    /// # Errors
1261    ///
1262    /// Returns an [`Error::Http`] if the current user is not in the guild or the access token
1263    /// lacks the necessary scope.
1264    #[inline]
1265    pub async fn current_user_member(&self, http: impl AsRef<Http>) -> Result<Member> {
1266        self.id.current_user_member(http).await
1267    }
1268
1269    /// Leaves the guild.
1270    ///
1271    /// # Errors
1272    ///
1273    /// Returns [`Error::Http`] if the current user is unable to leave the Guild, or currently is
1274    /// not in the guild.
1275    #[inline]
1276    pub async fn leave(&self, http: impl AsRef<Http>) -> Result<()> {
1277        self.id.leave(http).await
1278    }
1279
1280    /// Gets a user's [`Member`] for the guild by Id.
1281    ///
1282    /// # Errors
1283    ///
1284    /// Returns [`Error::Http`] if the member is not in the Guild, or if the Guild is otherwise
1285    /// unavailable.
1286    #[inline]
1287    pub async fn member(
1288        &self,
1289        cache_http: impl CacheHttp,
1290        user_id: impl Into<UserId>,
1291    ) -> Result<Member> {
1292        self.id.member(cache_http, user_id).await
1293    }
1294
1295    /// Gets a list of the guild's members.
1296    ///
1297    /// Optionally pass in the `limit` to limit the number of results. Minimum value is 1, maximum
1298    /// and default value is 1000.
1299    ///
1300    /// Optionally pass in `after` to offset the results by a [`User`]'s Id.
1301    ///
1302    /// # Errors
1303    ///
1304    /// Returns an [`Error::Http`] if the API returns an error, may also return
1305    /// [`Error::NotInRange`] if the input is not within range.
1306    ///
1307    /// [`User`]: crate::model::user::User
1308    #[inline]
1309    pub async fn members(
1310        &self,
1311        http: impl AsRef<Http>,
1312        limit: Option<u64>,
1313        after: impl Into<Option<UserId>>,
1314    ) -> Result<Vec<Member>> {
1315        self.id.members(http, limit, after).await
1316    }
1317
1318    /// Moves a member to a specific voice channel.
1319    ///
1320    /// Requires the [Move Members] permission.
1321    ///
1322    /// # Errors
1323    ///
1324    /// Returns an [`Error::Http`] if the current user lacks permission, or if the member is not
1325    /// currently in a voice channel for this Guild.
1326    ///
1327    /// [Move Members]: Permissions::MOVE_MEMBERS
1328    #[inline]
1329    pub async fn move_member(
1330        &self,
1331        cache_http: impl CacheHttp,
1332        user_id: impl Into<UserId>,
1333        channel_id: impl Into<ChannelId>,
1334    ) -> Result<Member> {
1335        self.id.move_member(cache_http, user_id, channel_id).await
1336    }
1337
1338    /// Calculate a [`Member`]'s permissions in a given channel in the guild.
1339    #[inline]
1340    #[must_use]
1341    pub fn user_permissions_in(&self, channel: &GuildChannel, member: &Member) -> Permissions {
1342        Guild::user_permissions_in_(
1343            Some(channel),
1344            member.user.id,
1345            &member.roles,
1346            self.id,
1347            &self.roles,
1348            self.owner_id,
1349        )
1350    }
1351
1352    /// Calculate a [`Role`]'s permissions in a given channel in the guild.
1353    ///
1354    /// # Errors
1355    ///
1356    /// Returns [`Error::Model`] if the [`Role`] or [`Channel`] is not from this [`Guild`].
1357    #[inline]
1358    #[deprecated = "this function ignores other roles the user may have as well as user-specific permissions; use user_permissions_in instead"]
1359    pub fn role_permissions_in(&self, channel: &GuildChannel, role: &Role) -> Result<Permissions> {
1360        Guild::role_permissions_in_(channel, role, self.id)
1361    }
1362
1363    /// Gets the number of [`Member`]s that would be pruned with the given number of days.
1364    ///
1365    /// Requires the [Kick Members] permission.
1366    ///
1367    /// See [`Guild::prune_count`].
1368    ///
1369    /// # Errors
1370    ///
1371    /// Returns [`Error::Http`] if the current user lacks permission.
1372    ///
1373    /// [Kick Members]: Permissions::KICK_MEMBERS
1374    /// [`Guild::prune_count`]: crate::model::guild::Guild::prune_count
1375    #[inline]
1376    pub async fn prune_count(&self, http: impl AsRef<Http>, days: u8) -> Result<GuildPrune> {
1377        self.id.prune_count(http, days).await
1378    }
1379
1380    /// Returns the Id of the shard associated with the guild.
1381    ///
1382    /// When the cache is enabled this will automatically retrieve the total number of shards.
1383    ///
1384    /// **Note**: When the cache is enabled, this function unlocks the cache to retrieve the total
1385    /// number of shards in use. If you already have the total, consider using [`utils::shard_id`].
1386    ///
1387    /// [`utils::shard_id`]: crate::utils::shard_id
1388    #[cfg(all(feature = "cache", feature = "utils"))]
1389    #[inline]
1390    #[must_use]
1391    pub fn shard_id(&self, cache: impl AsRef<Cache>) -> u32 {
1392        self.id.shard_id(cache)
1393    }
1394
1395    /// Returns the Id of the shard associated with the guild.
1396    ///
1397    /// When the cache is enabled this will automatically retrieve the total number of shards.
1398    ///
1399    /// When the cache is not enabled, the total number of shards being used will need to be
1400    /// passed.
1401    ///
1402    /// # Examples
1403    ///
1404    /// Retrieve the Id of the shard for a guild with Id `81384788765712384`, using 17 shards:
1405    ///
1406    /// ```rust,ignore
1407    /// use serenity::utils;
1408    ///
1409    /// // assumes a `guild` has already been bound
1410    ///
1411    /// assert_eq!(guild.shard_id(17), 7);
1412    /// ```
1413    #[cfg(all(feature = "utils", not(feature = "cache")))]
1414    #[inline]
1415    #[must_use]
1416    pub fn shard_id(&self, shard_count: u32) -> u32 {
1417        self.id.shard_id(shard_count)
1418    }
1419
1420    /// Returns the formatted URL of the guild's splash image, if one exists.
1421    #[inline]
1422    #[must_use]
1423    pub fn splash_url(&self) -> Option<String> {
1424        self.splash.as_ref().map(|splash| cdn!("/splashes/{}/{}.webp?size=4096", self.id, splash))
1425    }
1426
1427    /// Starts an integration sync for the given integration Id.
1428    ///
1429    /// Requires the [Manage Guild] permission.
1430    ///
1431    /// # Errors
1432    ///
1433    /// See [`Guild::start_integration_sync`].
1434    ///
1435    /// [Manage Guild]: Permissions::MANAGE_GUILD
1436    /// [`Guild::start_integration_sync`]: crate::model::guild::Guild::start_integration_sync
1437    #[inline]
1438    pub async fn start_integration_sync(
1439        &self,
1440        http: impl AsRef<Http>,
1441        integration_id: impl Into<IntegrationId>,
1442    ) -> Result<()> {
1443        self.id.start_integration_sync(http, integration_id).await
1444    }
1445
1446    /// Unbans a [`User`] from the guild.
1447    ///
1448    /// Requires the [Ban Members] permission.
1449    ///
1450    /// # Errors
1451    ///
1452    /// See [`Guild::unban`].
1453    ///
1454    /// [Ban Members]: Permissions::BAN_MEMBERS
1455    /// [`Guild::unban`]: crate::model::guild::Guild::unban
1456    #[inline]
1457    pub async fn unban(&self, http: impl AsRef<Http>, user_id: impl Into<UserId>) -> Result<()> {
1458        self.id.unban(http, user_id).await
1459    }
1460
1461    /// Retrieve's the guild's vanity URL.
1462    ///
1463    /// **Note**: Requires the [Manage Guild] permission.
1464    ///
1465    /// # Errors
1466    ///
1467    /// See [`Guild::vanity_url`].
1468    ///
1469    /// [Manage Guild]: Permissions::MANAGE_GUILD
1470    /// [`Guild::vanity_url`]: crate::model::guild::Guild::vanity_url
1471    #[inline]
1472    pub async fn vanity_url(&self, http: impl AsRef<Http>) -> Result<String> {
1473        self.id.vanity_url(http).await
1474    }
1475
1476    /// Retrieves the guild's webhooks.
1477    ///
1478    /// **Note**: Requires the [Manage Webhooks] permission.
1479    ///
1480    /// # Errors
1481    ///
1482    /// See [`Guild::webhooks`].
1483    ///
1484    /// [Manage Webhooks]: Permissions::MANAGE_WEBHOOKS
1485    /// [`Guild::webhooks`]: crate::model::guild::Guild::webhooks
1486    #[inline]
1487    pub async fn webhooks(&self, http: impl AsRef<Http>) -> Result<Vec<Webhook>> {
1488        self.id.webhooks(http).await
1489    }
1490
1491    /// Obtain a reference to a role by its name.
1492    ///
1493    /// **Note**: If two or more roles have the same name, obtained reference will be one of them.
1494    ///
1495    /// # Examples
1496    ///
1497    /// Obtain a reference to a [`Role`] by its name.
1498    ///
1499    /// ```rust,no_run
1500    /// # use serenity::model::prelude::*;
1501    /// # use serenity::prelude::*;
1502    /// # struct Handler;
1503    ///
1504    /// #[serenity::async_trait]
1505    /// #[cfg(all(feature = "cache", feature = "client"))]
1506    /// impl EventHandler for Handler {
1507    ///     async fn message(&self, context: Context, msg: Message) {
1508    ///         if let Some(guild_id) = msg.guild_id {
1509    ///             if let Some(guild) = guild_id.to_guild_cached(&context) {
1510    ///                 if let Some(role) = guild.role_by_name("role_name") {
1511    ///                     println!("Obtained role's reference: {:?}", role);
1512    ///                 }
1513    ///             }
1514    ///         }
1515    ///     }
1516    /// }
1517    /// ```
1518    #[inline]
1519    #[must_use]
1520    pub fn role_by_name(&self, role_name: &str) -> Option<&Role> {
1521        self.roles.values().find(|role| role_name == role.name)
1522    }
1523
1524    /// Returns a builder which can be awaited to obtain a message or stream of messages in this
1525    /// guild.
1526    #[cfg(feature = "collector")]
1527    pub fn await_reply(&self, shard_messenger: impl AsRef<ShardMessenger>) -> MessageCollector {
1528        MessageCollector::new(shard_messenger).guild_id(self.id)
1529    }
1530
1531    /// Same as [`Self::await_reply`].
1532    #[cfg(feature = "collector")]
1533    pub fn await_replies(&self, shard_messenger: impl AsRef<ShardMessenger>) -> MessageCollector {
1534        self.await_reply(shard_messenger)
1535    }
1536
1537    /// Returns a builder which can be awaited to obtain a message or stream of reactions sent in
1538    /// this guild.
1539    #[cfg(feature = "collector")]
1540    pub fn await_reaction(&self, shard_messenger: impl AsRef<ShardMessenger>) -> ReactionCollector {
1541        ReactionCollector::new(shard_messenger).guild_id(self.id)
1542    }
1543
1544    /// Same as [`Self::await_reaction`].
1545    #[cfg(feature = "collector")]
1546    pub fn await_reactions(
1547        &self,
1548        shard_messenger: impl AsRef<ShardMessenger>,
1549    ) -> ReactionCollector {
1550        self.await_reaction(shard_messenger)
1551    }
1552
1553    /// Gets the guild active threads.
1554    ///
1555    /// # Errors
1556    ///
1557    /// Returns [`Error::Http`] if there is an error in the deserialization, or if the bot issuing
1558    /// the request is not in the guild.
1559    pub async fn get_active_threads(&self, http: impl AsRef<Http>) -> Result<ThreadsData> {
1560        self.id.get_active_threads(http).await
1561    }
1562}
1563
1564// Manual impl needed to insert guild_id into Role's
1565impl<'de> Deserialize<'de> for PartialGuild {
1566    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
1567        let mut guild = Self::deserialize(deserializer)?; // calls #[serde(remote)]-generated inherent method
1568        guild.roles.values_mut().for_each(|r| r.guild_id = guild.id);
1569        Ok(guild)
1570    }
1571}
1572
1573impl Serialize for PartialGuild {
1574    fn serialize<S: serde::Serializer>(&self, serializer: S) -> StdResult<S::Ok, S::Error> {
1575        Self::serialize(self, serializer) // calls #[serde(remote)]-generated inherent method
1576    }
1577}
1578
1579impl From<Guild> for PartialGuild {
1580    /// Converts this [`Guild`] instance into a [`PartialGuild`]
1581    fn from(guild: Guild) -> Self {
1582        Self {
1583            application_id: guild.application_id,
1584            id: guild.id,
1585            afk_metadata: guild.afk_metadata,
1586            default_message_notifications: guild.default_message_notifications,
1587            widget_enabled: guild.widget_enabled,
1588            widget_channel_id: guild.widget_channel_id,
1589            emojis: guild.emojis,
1590            features: guild.features,
1591            icon: guild.icon,
1592            mfa_level: guild.mfa_level,
1593            name: guild.name,
1594            owner_id: guild.owner_id,
1595            roles: guild.roles,
1596            splash: guild.splash,
1597            discovery_splash: guild.discovery_splash,
1598            system_channel_id: guild.system_channel_id,
1599            system_channel_flags: guild.system_channel_flags,
1600            rules_channel_id: guild.rules_channel_id,
1601            public_updates_channel_id: guild.public_updates_channel_id,
1602            verification_level: guild.verification_level,
1603            description: guild.description,
1604            premium_tier: guild.premium_tier,
1605            premium_subscription_count: guild.premium_subscription_count,
1606            banner: guild.banner,
1607            vanity_url_code: guild.vanity_url_code,
1608            welcome_screen: guild.welcome_screen,
1609            approximate_member_count: guild.approximate_member_count,
1610            approximate_presence_count: guild.approximate_presence_count,
1611            nsfw_level: guild.nsfw_level,
1612            max_video_channel_users: guild.max_video_channel_users,
1613            max_presences: guild.max_presences,
1614            max_members: guild.max_members,
1615            stickers: guild.stickers,
1616            icon_hash: guild.icon_hash,
1617            explicit_content_filter: guild.explicit_content_filter,
1618            preferred_locale: guild.preferred_locale,
1619            max_stage_video_channel_users: guild.max_stage_video_channel_users,
1620            premium_progress_bar_enabled: guild.premium_progress_bar_enabled,
1621        }
1622    }
1623}