Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4480fea
Add VoiceMessageFile class
Jul 16, 2025
31344ca
Add abc.channel.send_voice_message to allow sending voice messages
Jul 16, 2025
aa5c26f
Start work on sending the voice messages (not working)
Jul 16, 2025
a7270b2
First working version of sending voice messages
Jul 16, 2025
4a40683
Start cleaning up parts of the code
Jul 16, 2025
9a4617e
More cleanup
Jul 16, 2025
f9ca81a
Found a much simpler method to send voice messages
Jul 16, 2025
eb62338
`size` method no longer needed
Jul 17, 2025
27bca43
Remove unncessary code
Jul 17, 2025
d1747b9
Doc fixes and made `duration` a required field
Jul 17, 2025
2a96d13
Remove print statements
blord0 Jul 17, 2025
8332ca3
Move `VoiceMessageFile` into `File`
Jul 17, 2025
5231d51
Remove final reference to `VoiceMessageFile`
Jul 17, 2025
2e6bfd3
Merge branch 'Rapptz:master' into voice-messages
blord0 Jul 18, 2025
60030d8
Add error checking
Jul 18, 2025
1d2ab9c
Fix error checking
Jul 18, 2025
50cb4f6
Merge branch 'Rapptz:master' into voice-messages
blord0 Jul 23, 2025
3dd7f8f
Rename duation to duration
Jul 28, 2025
e5cca7d
Add File.voice attribute
Jul 28, 2025
8f1d548
Change checking for voice messages to use File.voice
Jul 28, 2025
9936b0d
Formatting change
Jul 28, 2025
8bc906e
Add real generation of waveforms for Opus files
Jul 28, 2025
dd2fd33
Formatting
Jul 28, 2025
bb4de89
Calculate correct number of points per sample
Jul 28, 2025
0f3bc42
Change TypeError to ValueError
Jul 28, 2025
8bea5c3
Change waveform data to be input as a list of ints
Jul 29, 2025
394b16e
Fix doc issues
Jul 29, 2025
0f1ded6
Merge branch 'Rapptz:master' into voice-messages
blord0 Jul 29, 2025
aa84304
Merge branch 'Rapptz:master' into voice-messages
blord0 Aug 19, 2025
45945b6
Incriment versionadded to 2.7
blord0 Aug 19, 2025
b43441c
Formatting
blord0 Aug 19, 2025
f4f5d93
Merge branch 'Rapptz:master' into voice-messages
blord0 Aug 26, 2025
9048e4d
Merge branch 'Rapptz:master' into voice-messages
blord0 Sep 20, 2025
2181f4a
Move waveform generation into init
blord0 Sep 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
T = TypeVar('T', bound=VoiceProtocol)

if TYPE_CHECKING:
from typing_extensions import Self

Check warning on line 77 in discord/abc.py

View workflow job for this annotation

GitHub Actions / check 3.x

Import "typing_extensions" could not be resolved from source (reportMissingModuleSource)

from .client import Client
from .user import ClientUser
Expand Down Expand Up @@ -1404,6 +1404,7 @@
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
voice: bool = ...,
) -> Message:
...

Expand All @@ -1425,6 +1426,7 @@
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
voice: bool = ...,
) -> Message:
...

Expand All @@ -1446,6 +1448,7 @@
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
voice: bool = ...,
) -> Message:
...

Expand All @@ -1467,6 +1470,7 @@
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
voice: bool = ...,
) -> Message:
...

Expand All @@ -1489,6 +1493,7 @@
suppress_embeds: bool = False,
silent: bool = False,
poll: Optional[Poll] = None,
voice: bool = False,
) -> Message:
"""|coro|

Expand Down Expand Up @@ -1579,6 +1584,13 @@
The poll to send with this message.

.. versionadded:: 2.4
voice: :class:`bool`
If the message is a voice message.

.. warning::

`file` attribute must be a :class:`discord.VoiceMessageFile` for this to work. Content must also be `None`
.. versionadded:: 2.6

Raises
--------
Expand Down Expand Up @@ -1624,12 +1636,13 @@
if view and not hasattr(view, '__discord_ui_view__'):
raise TypeError(f'view parameter must be View not {view.__class__.__name__}')

if suppress_embeds or silent:
if suppress_embeds or silent or voice:
from .message import MessageFlags # circular import

flags = MessageFlags._from_value(0)
flags.suppress_embeds = suppress_embeds
flags.suppress_notifications = silent
flags.voice = voice
else:
flags = MISSING

Expand Down
40 changes: 40 additions & 0 deletions discord/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@

import os
import io
import base64

from .utils import MISSING

# fmt: off
__all__ = (
'File',
'VoiceMessageFile',
)
# fmt: on

Expand Down Expand Up @@ -157,3 +159,41 @@ def to_dict(self, index: int) -> Dict[str, Any]:
payload['description'] = self.description

return payload


class VoiceMessageFile(File):
"""A file object used for sending voice messages.

This is a subclass of :class:`File` that is specifically used for sending voice messages.

.. versionadded:: 2.6

Attributes
-----------
duration: :class:`float`
The duration of the voice message in seconds. Does not need to be accurate

"""

def __init__(
self,
fp: Union[str, bytes, os.PathLike[Any], io.BufferedIOBase],
duration: float,
waveform: Optional[str] = None,
):
super().__init__(fp, filename="voice-message.ogg", spoiler=False)
self.duration = duration
self._waveform = waveform

def to_dict(self, index: int) -> Dict[str, Any]:
payload = super().to_dict(index)
payload['duration_secs'] = self.duration
payload['waveform'] = self.waveform
return payload

@property
def waveform(self) -> str:
""":class:`bytes`: The waveform data for the voice message."""
if self._waveform is None:
return base64.b64encode(os.urandom(256)).decode('utf-8')
return self._waveform
1 change: 0 additions & 1 deletion discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ async def request(
headers['X-Audit-Log-Reason'] = _uriquote(reason, safe='/ ')

kwargs['headers'] = headers

# Proxy support
if self.proxy is not None:
kwargs['proxy'] = self.proxy
Expand Down
8 changes: 8 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5632,6 +5632,14 @@ File
.. autoclass:: File
:members:

VoiceMessageFile
~~~~~~~~~~~~~~~~~

.. attributetable:: VoiceMessageFile

.. autoclass:: VoiceMessageFile
:members:

Colour
~~~~~~

Expand Down
Loading