Skip to main content

serenity/model/guild/
partial_guild.rs

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