Skip to main content

An easy-to-use music extension for discord.py

Project description

pypi-total-downloads python-ver pypi-release-ver

discord-ext-music

An easy-to-use music extension for discord.py

Key features

Installation

Python 3.8 or higher required.

Stable version

You can install discord-ext-music stable version directly from PyPI by the following command:

pip install discord-ext-music

or by the cloning repository with latest stable version:

git clone --branch v0.3.0 https://github.com/mansuf/discord-ext-music.git
cd discord-ext-music

Development version

You also can install development version by cloning the repository, see below:

git clone https://github.com/mansuf/discord-ext-music.git
cd discord-ext-music

Optional packages

These are optional packages that you are not required to install it, but you get extra benefit once you install it.

  • scipy and pydub for equalizer support.
  • miniaudio for miniaudio music source support.
  • PyAV for FFmpeg libraries music source support.

You can install all additional packages in one command:

pip install discord-ext-music[all]

What type of audio formats discord-ext-music can play ?

basically, you can play these formats without additional packages:

  • Raw PCM
  • WAV

with miniaudio, you can play these formats:

  • MP3
  • FLAC
  • All formats that vorbis encoded
  • WAV

with PyAV, you can almost play anything that supported by ffmpeg libraries

What sources that discord-ext-music can play ?

Without additional packages or with miniaudio you can only play local file.

But, with PyAV you can almost play any sources that supported by ffmpeg protocols

Quick usage

from discord.ext.commands import Bot
from discord.ext.music import MusicClient, WAVAudio, Track

bot = Bot()

@bot.command()
async def play(ctx):
    voice_user = ctx.message.author.voice
    music_client = await voice_user.channel.connect(cls=MusicClient)
    track = Track(
        WAVAudio('audio.wav'), # AudioSource
        'This is audio' # name
    )
    await music_client.play(track)

bot.run('token')

Opus encoder

When you're installing discord-ext-music, opus encoder already shipped with it (because of discord.py audio library). This is called native opus encoder good for compatibility and stability. But, if you want to have much better performance and low CPU usage you can use alternative opus encoder using PyAV library (by installing av package pip install av).

By default, discord-ext-music auto detect opus encoder. If you have PyAV installed, it will use PyAV opus encoder, otherwise it will use native encoder.

Alternatively, you can set environment to override opus encoder.

For windows:

# PyAV opus encoder
set OPUS_ENCODER=av

# Native opus encoder
set OPUS_ENCODER=native

For linux / Mac OS:

# PyAV opus encoder
export OPUS_ENCODER=av

# Native opus encoder
export OPUS_ENCODER=native

Notes

Reusable audio sources

Because discord-ext-music is specialized for music, all audio sources in discord-ext-music are reusable. So if you call MusicClient.stop(), MusicClient.next_track(), MusicClient.previous_track(), or MusicClient.play_track_from_pos() the audio source will be recreated with same configurations (NOTE: Some audio sources are not reusable, for example: if you pass unseekable stream to RawPCMAudio or WAVAudio it will become non-reusable). And if the audio ended, the audio sources will not cleaned up, it will stay there until you removed it from playlist or reused by the library. Meanwhile, all audio sources in discord.py library are not reusable and cannot be played in MusicClient. But, the audio sources in discord-ext-music can be played in VoiceClient.

discord-ext-music is not Youtube, Soundcloud, or etc player

To be clear, discord-ext-music is just music extension with: playlist integrated with voice client, equalizer (if you install scipy and pydub), audio playback with thread-safe controls, and audio source that play streamable url. If you want to play youtube stream you must install additional packages like youtube-dl to extract streamable url and play it under discord-ext-music library.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord-ext-music-0.3.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discord_ext_music-0.3.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file discord-ext-music-0.3.0.tar.gz.

File metadata

  • Download URL: discord-ext-music-0.3.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for discord-ext-music-0.3.0.tar.gz
Algorithm Hash digest
SHA256 47c3b65a787e8410f67faf86e9a44eca7b0cd9083c291d897b5b28f9fee318b5
MD5 33f0318a3d625735100c00130f799223
BLAKE2b-256 a25d1623de1a61ea3ec94d6c4b2fa9e2afa9765c97b89f9a217bcafb28b5cd8a

See more details on using hashes here.

File details

Details for the file discord_ext_music-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: discord_ext_music-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for discord_ext_music-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a604cf155248cf76029b1fc324ed31c98f5b27a55214fb4a6253394828c8d100
MD5 cbb7f4cb627934479925ba4f0edc2280
BLAKE2b-256 21550caf96fa2f847747e62d914235b08a5dbff294a1722d2a7eb9060155d1ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page