Package: discord-ext-music
discord-ext-musicAn easy-to-use music extension fordiscord.pyKey featuresIt's easy to use and can be used for complex process.Complete playback controls and thread-safe.The audio source can be used indiscord.pyaudio library.NOTE: The audio sources fromdiscord.pycannot be played indiscord-ext-musiclibrary, seeReusable audio sourcesInstallationPython 3.8 or higher required.Stable versionYou can installdiscord-ext-musicstable version directly from PyPI by the following command:pipinstalldiscord-ext-musicor by the cloning repository with latest stable version:gitclone--branchv0.3.0https://github.com/mansuf/discord-ext-music.gitcddiscord-ext-musicDevelopment versionYou also can install development version by cloning the repository, see below:gitclonehttps://github.com/mansuf/discord-ext-music.gitcddiscord-ext-musicOptional packagesThese are optional packages that you are not required to install it, but you get extra benefit
once you install it.scipyandpydubfor equalizer support.miniaudiofor miniaudio music source support.PyAVfor FFmpeg libraries music source support.You can install all additional packages in one command:pipinstalldiscord-ext-music[all]What type of audio formats discord-ext-music can play ?basically, you can play these formats without additional packages:Raw PCMWAVwithminiaudio, you can play these formats:MP3FLACAll formats that vorbis encodedWAVwithPyAV, you can almost play anything that supported byffmpeglibrariesWhat sources that discord-ext-music can play ?Without additional packages or withminiaudioyou can only playlocal file.But, withPyAVyou can almost play any sources that supported byffmpeg protocolsQuick usagefromdiscord.ext.commandsimportBotfromdiscord.ext.musicimportMusicClient,WAVAudio,Trackbot=Bot()@bot.command()asyncdefplay(ctx):voice_user=ctx.message.author.voicemusic_client=awaitvoice_user.channel.connect(cls=MusicClient)track=Track(WAVAudio('audio.wav'),# AudioSource'This is audio'# name)awaitmusic_client.play(track)bot.run('token')Opus encoderWhen you're installing discord-ext-music, opus encoder already shipped with it (because ofdiscord.pyaudio 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 usingPyAVlibrary (by installing av packagepip install av).By default, discord-ext-music auto detect opus encoder. If you havePyAVinstalled, it will usePyAVopus encoder, otherwise it will use native encoder.Alternatively, you can set environment to override opus encoder.For windows:# PyAV opus encodersetOPUS_ENCODER=av# Native opus encodersetOPUS_ENCODER=nativeFor linux / Mac OS:# PyAV opus encoderexportOPUS_ENCODER=av# Native opus encoderexportOPUS_ENCODER=nativeNotesReusable audio sourcesBecause discord-ext-music is specialized for music, all audio sources in discord-ext-music are reusable.
So if you callMusicClient.stop(),MusicClient.next_track(),MusicClient.previous_track(), orMusicClient.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 toRawPCMAudioorWAVAudioit 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 indiscord.pylibrary are not reusable and cannot be played inMusicClient. But, the audio sources in discord-ext-music can be played inVoiceClient.discord-ext-music is not Youtube, Soundcloud, or etc playerTo 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 likeyoutube-dlto extract streamable url and play it under discord-ext-music library.LinksDocumentationPyPI