[docs]classPartialSoundboardSound(PartialBase):def__init__(self,*,state:"DiscordAPI",id:int,guild_id:int|None=None):super().__init__(id=int(id))self._state=stateself.sound_id:int=self.idself.guild_id:int|None=guild_iddef__repr__(self)->str:returnf"<PartialSoundboardSound id={self.id} guild_id={self.guild_id}>"@propertydefguild(self)->"Guild | PartialGuild | None":""" Returns the guild this soundboard sound is in Returns ------- `PartialGuild` The guild this soundboard sound is in Raises ------ `ValueError` guild_id is not defined, unable to create PartialGuild """ifnotself.guild_id:returnNonecache=self._state.cache.get_guild(self.guild_id)ifcache:returncachefrom.guildimportPartialGuildreturnPartialGuild(state=self._state,id=self.guild_id)
[docs]asyncdeffetch(self)->"SoundboardSound":""" Returns the soundboard sound data Returns ------- `SoundboardSound` The soundboard sound data Raises ------ `ValueError` Soundboard sound does not belong to a guild """ifself.guildisNone:raiseValueError("Soundboard sound does not belong to a guild")r=awaitself._state.query("GET",f"/guild/{self.guild_id}/soundboard-sounds/{self.id}")returnSoundboardSound(state=self._state,data=r.response,guild=self.guild,)
[docs]asyncdefdelete(self,*,reason:str|None=None)->None:""" Delete the soundboard sound Parameters ---------- reason: `str | None` The reason for deleting the soundboard sound Raises ------ `ValueError` Soundboard sound does not belong to a guild """ifself.guild_idisNone:raiseValueError("Soundboard sound does not belong to a guild")awaitself._state.query("DELETE",f"/guilds/{self.guild_id}/soundboard-sounds/{self.id}",reason=reason,res_method="text")
[docs]asyncdefedit(self,*,name:"str | MISSING"=MISSING,volume:"int | MISSING"=MISSING,emoji_name:"str | MISSING"=MISSING,emoji_id:"str | MISSING"=MISSING,icon:"File | bytes | MISSING"=MISSING,reason:str|None=None,)->"SoundboardSound":""" Edit the soundboard sound Parameters ---------- name: `Optional[str]` The new name of the soundboard sound volume: `Optional[int]` The new volume of the soundboard sound emoji_name: `Optional[str]` The new unicode emoji of the soundboard sound emoji_id: `Optional[str]` The ID of the new custom emoji of the soundboard sound reason: `Union[str]` The reason for editing the soundboard sound Returns ------- `Union[SoundboardSound, PartialSoundboardSound]` The edited soundboard sound and its data Raises ------ `ValueError` - If both `emoji_name` and `emoji_id` are set - If there were no changes applied to the soundboard sound - Soundboard sound does not belong to a guild """payload={}_sound:"SoundboardSound | None"=Noneifself.guildisNone:raiseValueError("Soundboard sound does not belong to a guild")ifnameisnotMISSING:payload["name"]=nameifvolumeisnotMISSING:payload["volume"]=volumeifemoji_nameisnotMISSING:payload["emoji_name"]=emoji_nameifemoji_idisnotMISSING:payload["emoji_id"]=emoji_idificonisnotMISSING:payload["icon"]=utils.bytes_to_base64(icon)if(emoji_nameisnotMISSINGandemoji_idisnotMISSING):raiseValueError("Cannot set both emoji_name and emoji_id")ifpayload:r=awaitself._state.query("PATCH",f"/guilds/{self.guild_id}/soundboard-sounds/{self.id}",json=payload,reason=reason)_sound=SoundboardSound(state=self._state,guild=self.guild,data=r.response)ifnot_sound:raiseValueError("There were no changes applied to the soundboard sound. ""No edits were taken")return_sound