serenity/builder/
edit_guild_widget.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 specify the fields to edit in a [`GuildWidget`].
10///
11/// [Discord docs](https://discord.com/developers/docs/resources/guild#modify-guild-widget)
12#[derive(Clone, Debug, Default, Serialize)]
13#[must_use]
14pub struct EditGuildWidget<'a> {
15    #[serde(skip_serializing_if = "Option::is_none")]
16    enabled: Option<bool>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    channel_id: Option<ChannelId>,
19
20    #[serde(skip)]
21    audit_log_reason: Option<&'a str>,
22}
23
24impl<'a> EditGuildWidget<'a> {
25    /// Equivalent to [`Self::default`].
26    pub fn new() -> Self {
27        Self::default()
28    }
29
30    /// Whether the widget is enabled or not.
31    pub fn enabled(mut self, enabled: bool) -> Self {
32        self.enabled = Some(enabled);
33        self
34    }
35
36    /// The server description shown in the welcome screen.
37    pub fn channel_id(mut self, id: impl Into<ChannelId>) -> Self {
38        self.channel_id = Some(id.into());
39        self
40    }
41
42    /// Sets the request's audit log reason.
43    pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
44        self.audit_log_reason = Some(reason);
45        self
46    }
47}
48
49#[cfg(feature = "http")]
50#[async_trait::async_trait]
51impl Builder for EditGuildWidget<'_> {
52    type Context<'ctx> = GuildId;
53    type Built = GuildWidget;
54
55    /// Edits the guild's widget.
56    ///
57    /// **Note**: Requires the [Manage Guild] permission.
58    ///
59    /// # Errors
60    ///
61    /// Returns [`Error::Http`] if the current user lacks permission.
62    ///
63    /// [Manage Guild]: Permissions::MANAGE_GUILD
64    async fn execute(
65        self,
66        cache_http: impl CacheHttp,
67        ctx: Self::Context<'_>,
68    ) -> Result<Self::Built> {
69        cache_http.http().edit_guild_widget(ctx, &self, self.audit_log_reason).await
70    }
71}