serenity/builder/
create_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/// Builder for creating a stage instance
10///
11/// [Discord docs](https://discord.com/developers/docs/resources/stage-instance#create-stage-instance)
12#[derive(Clone, Debug, Serialize)]
13#[must_use]
14pub struct CreateStageInstance<'a> {
15    channel_id: Option<ChannelId>, // required field, filled in Builder impl
16    topic: String,
17    privacy_level: StageInstancePrivacyLevel,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    send_start_notification: Option<bool>,
20
21    #[serde(skip)]
22    audit_log_reason: Option<&'a str>,
23}
24
25impl<'a> CreateStageInstance<'a> {
26    /// Creates a builder with the provided topic.
27    pub fn new(topic: impl Into<String>) -> Self {
28        Self {
29            channel_id: None,
30            topic: topic.into(),
31            privacy_level: StageInstancePrivacyLevel::default(),
32            send_start_notification: None,
33            audit_log_reason: None,
34        }
35    }
36
37    /// Sets the topic of the stage channel instance, replacing the current value as set in
38    /// [`Self::new`].
39    pub fn topic(mut self, topic: impl Into<String>) -> Self {
40        self.topic = topic.into();
41        self
42    }
43
44    /// Whether or not to notify @everyone that a stage instance has started.
45    pub fn send_start_notification(mut self, send_start_notification: bool) -> Self {
46        self.send_start_notification = Some(send_start_notification);
47        self
48    }
49
50    /// Sets the request's audit log reason.
51    pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
52        self.audit_log_reason = Some(reason);
53        self
54    }
55}
56
57#[cfg(feature = "http")]
58#[async_trait::async_trait]
59impl Builder for CreateStageInstance<'_> {
60    type Context<'ctx> = ChannelId;
61    type Built = StageInstance;
62
63    /// Creates the stage instance.
64    ///
65    /// # Errors
66    ///
67    /// Returns [`Error::Http`] if there is already a stage instance currently.
68    async fn execute(
69        mut self,
70        cache_http: impl CacheHttp,
71        ctx: Self::Context<'_>,
72    ) -> Result<StageInstance> {
73        self.channel_id = Some(ctx);
74        cache_http.http().create_stage_instance(&self, self.audit_log_reason).await
75    }
76}