serenity/model/soundboard.rs
1#[cfg(feature = "model")]
2use crate::http::Http;
3use crate::model::prelude::*;
4
5/// A representation of a soundboard sound, a kind of audio that users can play
6/// in voice channels.
7///
8/// [Discord docs](https://discord.com/developers/docs/resources/soundboard#soundboard-resource).
9#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
10#[derive(Clone, Debug, Default, Deserialize, Serialize)]
11pub struct Soundboard {
12 /// The unique Id of the soundboard sound. Can be used to calculate the
13 /// creation date of the soundboard sound.
14 #[serde(rename = "sound_id")]
15 pub id: SoundId,
16 /// The name of this soundboard sound.
17 pub name: String,
18 /// Volume of this soundboard sound. The valid range is from `0` to `1`.
19 pub volume: f64,
20 /// Id of the emoji for this soundboard sound.
21 pub emoji_id: Option<EmojiId>,
22 /// Unicode character of the emoji for this soundboard sound.
23 pub emoji_name: Option<String>,
24 /// Id of the guild this soundboard sound belongs to.
25 pub guild_id: Option<GuildId>,
26 /// Whether this soundboard sound may be used. Can be `false` if the guild
27 /// lost Nitro boosts, for instance.
28 pub available: bool,
29 /// User who created this soundboard sound.
30 pub user: Option<User>,
31}
32
33#[cfg(feature = "model")]
34impl SoundId {
35 /// Performs a HTTP request to fetch soundboard sound data from a guild.
36 ///
37 /// # Errors
38 ///
39 /// Returns [`Error::Http`] if there is an error in the deserialization, or if the bot issuing
40 /// the request is not in the guild.
41 pub async fn to_soundboard(
42 self,
43 http: impl AsRef<Http>,
44 guild_id: GuildId,
45 ) -> Result<Soundboard> {
46 guild_id.get_soundboard(http, self).await
47 }
48}