djs_rest/endpoints/stage_instance.rs
1//! [Stage instance endpoints](https://docs.discord.com/developers/resources/stage-instance):
2//! opening, changing and closing the live stage of a stage channel.
3//!
4//! Every endpoint needs the bot to be a stage moderator (`MANAGE_CHANNELS`, `MUTE_MEMBERS`
5//! and `MOVE_MEMBERS` in the channel).
6
7use djs_model::{
8 id::ChannelId,
9 rest::{CreateStageInstance, ModifyStageInstance},
10 stage_instance::StageInstance,
11};
12
13use crate::client::boxed;
14use crate::{Error, Request, Rest, Route};
15
16impl Rest {
17 /// [Create Stage Instance](https://docs.discord.com/developers/resources/stage-instance#create-stage-instance):
18 /// opens a stage in a stage channel.
19 ///
20 /// `reason` is shown in the audit log (D-086).
21 ///
22 /// discord.js counterpart: `StageInstanceManager#create`.
23 ///
24 /// # Examples
25 ///
26 /// ```no_run
27 /// # async fn example(rest: djs_rest::Rest, stage: djs_model::id::ChannelId) -> Result<(), djs_rest::Error> {
28 /// use djs_model::rest::CreateStageInstance;
29 ///
30 /// rest.create_stage_instance(&CreateStageInstance::new(stage, "Weekly Q&A"), None)
31 /// .await?;
32 /// # Ok(())
33 /// # }
34 /// ```
35 ///
36 /// # Errors
37 ///
38 /// See [`Rest::request`]; `150006` when the stage is already open.
39 pub fn create_stage_instance<'a>(
40 &'a self,
41 body: &'a CreateStageInstance,
42 reason: Option<&'a str>,
43 ) -> impl Future<Output = Result<StageInstance, Error>> + Send + 'a {
44 boxed(async move {
45 self.call(
46 Request::new(Route::CreateStageInstance)
47 .json(body)?
48 .reason(reason),
49 )
50 .await
51 })
52 }
53
54 /// [Get Stage Instance](https://docs.discord.com/developers/resources/stage-instance#get-stage-instance):
55 /// returns the open stage of a stage channel.
56 ///
57 /// discord.js counterpart: `StageInstanceManager#fetch`.
58 ///
59 /// # Errors
60 ///
61 /// See [`Rest::request`]; `10067` Unknown Stage Instance when no stage is open.
62 pub fn get_stage_instance(
63 &self,
64 channel_id: ChannelId,
65 ) -> impl Future<Output = Result<StageInstance, Error>> + Send + '_ {
66 boxed(async move {
67 self.call(Request::new(Route::GetStageInstance { channel_id }))
68 .await
69 })
70 }
71
72 /// [Modify Stage Instance](https://docs.discord.com/developers/resources/stage-instance#modify-stage-instance):
73 /// changes the topic or privacy of an open stage.
74 ///
75 /// `reason` is shown in the audit log (D-086).
76 ///
77 /// discord.js counterpart: `StageInstance#edit`, `#setTopic`, `StageInstanceManager#edit`.
78 ///
79 /// # Errors
80 ///
81 /// See [`Rest::request`]; `10067` Unknown Stage Instance.
82 pub fn modify_stage_instance<'a>(
83 &'a self,
84 channel_id: ChannelId,
85 body: &'a ModifyStageInstance,
86 reason: Option<&'a str>,
87 ) -> impl Future<Output = Result<StageInstance, Error>> + Send + 'a {
88 boxed(async move {
89 self.call(
90 Request::new(Route::ModifyStageInstance { channel_id })
91 .json(body)?
92 .reason(reason),
93 )
94 .await
95 })
96 }
97
98 /// [Delete Stage Instance](https://docs.discord.com/developers/resources/stage-instance#delete-stage-instance):
99 /// closes a stage.
100 ///
101 /// `reason` is shown in the audit log (D-086).
102 ///
103 /// discord.js counterpart: `StageInstance#delete`, `StageInstanceManager#delete`.
104 ///
105 /// # Errors
106 ///
107 /// See [`Rest::request`]; `10067` Unknown Stage Instance.
108 pub fn delete_stage_instance<'a>(
109 &'a self,
110 channel_id: ChannelId,
111 reason: Option<&'a str>,
112 ) -> impl Future<Output = Result<(), Error>> + Send + 'a {
113 boxed(async move {
114 self.call(Request::new(Route::DeleteStageInstance { channel_id }).reason(reason))
115 .await
116 })
117 }
118}