djs_model/rest/voice.rs
1//! Bodies of the [voice endpoints](https://docs.discord.com/developers/resources/voice).
2//!
3//! Both bodies only work in stage channels the user has already joined.
4
5use serde::Serialize;
6
7use crate::{
8 id::ChannelId,
9 util::{Patch, Timestamp},
10};
11
12/// The body of [Modify Current User Voice State](https://docs.discord.com/developers/resources/voice#modify-current-user-voice-state).
13///
14/// Every field is optional. Unsuppressing needs `MUTE_MEMBERS` and requesting to speak needs
15/// `REQUEST_TO_SPEAK`; suppressing oneself and withdrawing a request always work.
16///
17/// discord.js counterpart: the argument of `VoiceState#edit` for the client user
18/// (`setSuppressed`, `setRequestToSpeak`).
19///
20/// # Examples
21///
22/// ```
23/// use djs_model::{
24/// id::ChannelId,
25/// rest::ModifyCurrentUserVoiceState,
26/// util::{Patch, Timestamp},
27/// };
28///
29/// let mut body = ModifyCurrentUserVoiceState::default();
30/// body.channel_id = Some(ChannelId::new(5));
31/// body.request_to_speak_timestamp = Patch::Set(Timestamp::parse("2026-11-12T18:00:00Z")?);
32/// assert_eq!(
33/// serde_json::to_string(&body)?,
34/// r#"{"channel_id":"5","request_to_speak_timestamp":"2026-11-12T18:00:00.000000+00:00"}"#
35/// );
36/// # Ok::<(), Box<dyn std::error::Error>>(())
37/// ```
38#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize)]
39#[non_exhaustive]
40pub struct ModifyCurrentUserVoiceState {
41 /// The stage channel the bot is in.
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub channel_id: Option<ChannelId>,
44 /// Whether the bot is suppressed (an audience member rather than a speaker).
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub suppress: Option<bool>,
47 /// Requests to speak (any present or future time); [`Patch::Clear`] withdraws the request.
48 #[serde(skip_serializing_if = "Patch::is_keep")]
49 pub request_to_speak_timestamp: Patch<Timestamp>,
50}
51
52/// The body of [Modify User Voice State](https://docs.discord.com/developers/resources/voice#modify-user-voice-state).
53///
54/// Every field is optional; needs `MUTE_MEMBERS`. Unsuppressing a user who is not a bot also
55/// sets their request to speak to now; suppressing removes it.
56///
57/// discord.js counterpart: the argument of `VoiceState#edit` for other members
58/// (`setSuppressed`).
59#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize)]
60#[non_exhaustive]
61pub struct ModifyUserVoiceState {
62 /// The stage channel the user is in.
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub channel_id: Option<ChannelId>,
65 /// Whether the user is suppressed.
66 #[serde(skip_serializing_if = "Option::is_none")]
67 pub suppress: Option<bool>,
68}