serenity/builder/
edit_stage_instance.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/// Edits a [`StageInstance`].
10///
11/// [Discord docs](https://discord.com/developers/docs/resources/stage-instance#modify-stage-instance)
12#[derive(Clone, Debug, Default, Serialize)]
13#[must_use]
14pub struct EditStageInstance<'a> {
15    #[serde(skip_serializing_if = "Option::is_none")]
16    topic: Option<String>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    privacy_level: Option<StageInstancePrivacyLevel>,
19
20    #[serde(skip)]
21    audit_log_reason: Option<&'a str>,
22}
23
24impl<'a> EditStageInstance<'a> {
25    /// Equivalent to [`Self::default`].
26    pub fn new() -> Self {
27        Self::default()
28    }
29
30    /// Sets the topic of the stage channel instance.
31    pub fn topic(mut self, topic: impl Into<String>) -> Self {
32        self.topic = Some(topic.into());
33        self
34    }
35
36    /// Sets the privacy level of the stage instance
37    pub fn privacy_level(mut self, privacy_level: StageInstancePrivacyLevel) -> Self {
38        self.privacy_level = Some(privacy_level);
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 EditStageInstance<'_> {
52    type Context<'ctx> = ChannelId;
53    type Built = StageInstance;
54
55    /// Edits the stage instance
56    ///
57    /// # Errors
58    ///
59    /// Returns [`Error::Http`] if the channel is not a stage channel, or there is no stage
60    /// instance currently.
61    async fn execute(
62        self,
63        cache_http: impl CacheHttp,
64        ctx: Self::Context<'_>,
65    ) -> Result<Self::Built> {
66        cache_http.http().edit_stage_instance(ctx, &self, self.audit_log_reason).await
67    }
68}