serenity/builder/
edit_guild_welcome_screen.rs

1#[cfg(feature = "http")]
2use super::Builder;
3#[cfg(feature = "http")]
4use crate::http::CacheHttp;
5#[cfg(feature = "http")]
6use crate::internal::prelude::*;
7use crate::model::prelude::*;
8
9/// A builder to edit the welcome screen of a guild
10///
11/// [Discord docs](https://discord.com/developers/docs/resources/guild#modify-guild-welcome-screen)
12#[derive(Clone, Debug, Default, Serialize)]
13#[must_use]
14pub struct EditGuildWelcomeScreen<'a> {
15    #[serde(skip_serializing_if = "Option::is_none")]
16    enabled: Option<bool>,
17    #[serde(skip_serializing_if = "Vec::is_empty")]
18    welcome_channels: Vec<CreateGuildWelcomeChannel>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    description: Option<String>,
21
22    #[serde(skip)]
23    audit_log_reason: Option<&'a str>,
24}
25
26impl<'a> EditGuildWelcomeScreen<'a> {
27    /// Equivalent to [`Self::default`].
28    pub fn new() -> Self {
29        Self::default()
30    }
31
32    /// Whether the welcome screen is enabled or not.
33    pub fn enabled(mut self, enabled: bool) -> Self {
34        self.enabled = Some(enabled);
35        self
36    }
37
38    /// The server description shown in the welcome screen.
39    pub fn description(mut self, description: impl Into<String>) -> Self {
40        self.description = Some(description.into());
41        self
42    }
43
44    pub fn add_welcome_channel(mut self, channel: CreateGuildWelcomeChannel) -> Self {
45        self.welcome_channels.push(channel);
46        self
47    }
48
49    /// Channels linked in the welcome screen and their display options
50    pub fn set_welcome_channels(mut self, channels: Vec<CreateGuildWelcomeChannel>) -> Self {
51        self.welcome_channels = channels;
52        self
53    }
54
55    /// Sets the request's audit log reason.
56    pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
57        self.audit_log_reason = Some(reason);
58        self
59    }
60}
61
62#[cfg(feature = "http")]
63#[async_trait::async_trait]
64impl Builder for EditGuildWelcomeScreen<'_> {
65    type Context<'ctx> = GuildId;
66    type Built = GuildWelcomeScreen;
67
68    /// Edits the guild's welcome screen.
69    ///
70    /// **Note**: Requires the [Manage Guild] permission.
71    ///
72    /// # Errors
73    ///
74    /// Returns [`Error::Http`] if the current user lacks permission.
75    ///
76    /// [Manage Guild]: Permissions::MANAGE_GUILD
77    async fn execute(
78        self,
79        cache_http: impl CacheHttp,
80        ctx: Self::Context<'_>,
81    ) -> Result<Self::Built> {
82        cache_http.http().edit_guild_welcome_screen(ctx, &self, self.audit_log_reason).await
83    }
84}
85
86/// A builder for creating a [`GuildWelcomeChannel`].
87///
88/// [Discord docs](https://discord.com/developers/docs/resources/guild#welcome-screen-object-welcome-screen-channel-structure)
89#[derive(Clone, Debug, Serialize)]
90#[must_use]
91pub struct CreateGuildWelcomeChannel(GuildWelcomeChannel);
92
93impl CreateGuildWelcomeChannel {
94    pub fn new(channel_id: ChannelId, description: String) -> Self {
95        Self(GuildWelcomeChannel {
96            channel_id,
97            description,
98            emoji: None,
99        })
100    }
101
102    /// The Id of the channel to show.
103    pub fn id(mut self, id: impl Into<ChannelId>) -> Self {
104        self.0.channel_id = id.into();
105        self
106    }
107
108    /// The description shown for the channel.
109    pub fn description(mut self, description: impl Into<String>) -> Self {
110        self.0.description = description.into();
111        self
112    }
113
114    /// The emoji shown for the channel.
115    pub fn emoji(mut self, emoji: GuildWelcomeChannelEmoji) -> Self {
116        self.0.emoji = Some(emoji);
117        self
118    }
119}