Skip to main content

djs_model/
soundboard.rs

1//! [Soundboard](https://docs.discord.com/developers/resources/soundboard): short sounds users
2//! play in voice channels — Discord's default sounds and each guild's own.
3
4use compact_str::CompactString;
5use serde::{Deserialize, Serialize};
6
7use crate::{
8    id::{EmojiId, GuildId, SoundboardSoundId},
9    user::User,
10};
11
12/// A [soundboard sound](https://docs.discord.com/developers/resources/soundboard#soundboard-sound-object).
13///
14/// The sound file is at `https://cdn.discordapp.com/soundboard-sounds/{sound_id}`. Default
15/// sounds have no [`guild_id`](Self::guild_id).
16///
17/// Contains a float ([`volume`](Self::volume)), so it is `PartialEq` but not `Eq` (D-064).
18///
19/// discord.js counterpart: `SoundboardSound`.
20#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
21#[non_exhaustive]
22pub struct SoundboardSound {
23    /// The sound's name.
24    pub name: CompactString,
25    /// The sound's ID.
26    pub sound_id: SoundboardSoundId,
27    /// The volume, from 0 to 1.
28    pub volume: f64,
29    /// The sound's custom emoji.
30    pub emoji_id: Option<EmojiId>,
31    /// The sound's standard (Unicode) emoji.
32    pub emoji_name: Option<CompactString>,
33    /// The guild the sound belongs to (absent for default sounds).
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub guild_id: Option<GuildId>,
36    /// Whether the sound can be used (`false` e.g. after the guild lost Server Boosts).
37    #[serde(default = "crate::serde_util::default_true")]
38    pub available: bool,
39    /// The user who uploaded the sound (with the `CREATE_GUILD_EXPRESSIONS` or
40    /// `MANAGE_GUILD_EXPRESSIONS` permission).
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub user: Option<Box<User>>,
43}