Python Discord Bot - How to play multiple audio tracks simultaneously

I’m working on a Discord bot and I want it to play a short sound effect while background music is already playing. I can’t seem to get this working properly.

I tried using different methods to handle both audio streams. When I use one function for the background music and another for the sound effect, the second audio just produces weird noise instead of playing correctly.

Here’s what I’m trying to do:

async def sound_effect_command(self, msg):
    channel = msg.author.voice_channel
    audio_client = await self.connect_to_voice(channel)
    audio_client.play_sound('sounds/beep.wav')

Can a Discord bot actually handle playing two different audio files at the same time? If yes, what’s the right approach to make this work?

Discord bots can’t play multiple audio streams at once through the same voice connection. The voice client only handles one audio source, so that’s why you’re hearing weird noise when trying to play a second file.

I hit this same problem building my music bot last year. My fix was a queue system - pause the background music, play the sound effect, then resume. Not perfect since there’s a quick interruption, but it works.

You could also pre-mix your sound effects with silence to get the timing right, then overlay them onto the current track in real-time using audio processing libraries. Uses more CPU but sounds smoother. Either way, you’ve got to handle the audio mixing in your app before sending it to Discord.

totally agree! merging them before playing is key. pydub works great for that, like you said. just make sure to set the right formats so Discord doesn’t get confused. gl with it!

Been dealing with this for months on my bot. Discord’s voice API sucks for concurrent audio - you get one stream per connection, that’s it. I ended up creating a separate buffer that mixes everything before sending to Discord. Use numpy to blend the audio arrays in real-time - keep background music low and layer sound effects on top. More work than just hitting play twice, but way cleaner than constantly pausing and resuming. The pain is getting timing right and preventing your buffer from drifting. Takes tweaking but totally doable if you don’t mind handling the audio processing.