mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-04 08:56:19 +00:00
Add support for voice messages
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
This commit is contained in:
@ -183,6 +183,14 @@ class Attachment(Hashable):
|
||||
Whether the attachment is ephemeral.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
duration: Optional[:class:`float`]
|
||||
The duration of the audio file in seconds. Returns ``None`` if it's not a voice message.
|
||||
|
||||
.. versionadded:: 2.3
|
||||
waveform: Optional[:class:`bytes`]
|
||||
The waveform (amplitudes) of the audio in bytes. Returns ``None`` if it's not a voice message.
|
||||
|
||||
.. versionadded:: 2.3
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
@ -197,6 +205,8 @@ class Attachment(Hashable):
|
||||
'content_type',
|
||||
'description',
|
||||
'ephemeral',
|
||||
'duration',
|
||||
'waveform',
|
||||
)
|
||||
|
||||
def __init__(self, *, data: AttachmentPayload, state: ConnectionState):
|
||||
@ -211,11 +221,19 @@ class Attachment(Hashable):
|
||||
self.content_type: Optional[str] = data.get('content_type')
|
||||
self.description: Optional[str] = data.get('description')
|
||||
self.ephemeral: bool = data.get('ephemeral', False)
|
||||
self.duration: Optional[float] = data.get('duration_secs')
|
||||
|
||||
waveform = data.get('waveform')
|
||||
self.waveform: Optional[bytes] = utils._base64_to_bytes(waveform) if waveform is not None else None
|
||||
|
||||
def is_spoiler(self) -> bool:
|
||||
""":class:`bool`: Whether this attachment contains a spoiler."""
|
||||
return self.filename.startswith('SPOILER_')
|
||||
|
||||
def is_voice_message(self) -> bool:
|
||||
""":class:`bool`: Whether this attachment is a voice message."""
|
||||
return self.duration is not None and 'voice-message' in self.url
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'<Attachment id={self.id} filename={self.filename!r} url={self.url!r}>'
|
||||
|
||||
|
Reference in New Issue
Block a user