Title: discord.py bot won't play longer music in vc: OSError: [Errno 9] Bad file descriptor
Tags: python;discord;discord.py
Question: I'm trying to make my bot play music in a voicechannel. playing shorter videos works, but when the videos get longer (~5 min), the bot doesn't play them and prints me the following error: ```OSError: [Errno 9] Bad file descriptor```. This is my code:
```elif message.content.casefold().startswith(&quot;rachel play&quot;):
            os.chdir(r&quot;/home/pi/rachel&quot;)
            song_there = os.path.isfile(&quot;song.mp3&quot;)
            try:
                if song_there:
                    os.remove(&quot;song.mp3&quot;)

            except PermissionError:
                await message.send(&quot;Warte&quot;)

            voice = discord.utils.get(self.bot.voice_clients, guild=message.guild)
            parts = message.content.split()
            url = parts[-1]
            channel = message.author.voice.channel
            ydl_opts = {
                'format': 'bestaudio/best',
                'postprocessors': [{
                    'key': 'FFmpegExtractAudio',
                    'preferredcodec': 'mp3',
                    'preferredquality': '192',
                    }]
                }
            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                ydl.download([url])
            for file in os.listdir(&quot;./&quot;):
                if file.endswith(&quot;.mp3&quot;):
                    os.rename(file, &quot;song.mp3&quot;)

            voice.play(discord.FFmpegPCMAudio(&quot;/home/pi/rachel/song.mp3&quot;))
```
Thanks in advance for any help!

Comment: sure can^^
`Exception in voice thread Thread-5
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/discord/player.py", line 603, in run
    self._do_run()
  File "/home/pi/.local/lib/python3.7/site-packages/discord/player.py", line 596, in _do_run
    play_audio(data, encode=not self.source.is_opus())
  File "/home/pi/.local/lib/python3.7/site-packages/discord/voice_client.py", line 638, in send_audio_packet
    self.socket.sendto(packet, (self.endpoint_ip, self.voice_port))
OSError: [Errno 9] Bad file descriptor`
I hope this helps! @Awesomepotato29

Comment: it is stable. I've looked at it and I would also get a notification if it would be unstable. You can also add me on discord if you want (would make responding easier: Spleens#0002) @Awesomepotato29

Comment: @Awesomepotato29 should I maybe try to get a better connection on my raspberry pi then? I don't know, how I could do that, but I think I will figure something out if necessary

Comment: I already rebooted many times, tried different types of code which all lead to the same problem. Do you by chance know anybody with experience on Pis and also with discord.py? Or do you know a community I could ask? I already asked on many servers and no one could really help me. This is really bugging me because I can't understand what really is causing this error.. @Awesomepotato29

Comment: Could you provide the full stack trace, not just the error type?

Comment: Hmm, the error seems to be network-related. Have you made sure your internet connection is stable?

Comment: It seems to me that discord.py is trying to write a packet with the sound you are playing to a socket. For some reason, this returns a bad file descriptor. I suspect this is due to network-related problems, but I'm not entirely clear on the inner workings of discord.py.

Comment: I have no experience with Raspberry Pis, sorry. The best I can do is recommend a reboot.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 8, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:02/03/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><discord><discord.py>', 'Title': "discord.py bot won't play longer music in vc: OSError: [Errno 9] Bad file descriptor", 'ViewCount': 518, 'id': 66031502, 'user_AboutMe': "<p>I'm a german programmer.</p>\n<p>I'm coding on an raspberry pi 3 with python.</p>\n<p>The latest project I'm working on is coding an bot for discord..\nAnd yes that's my hobby:)</p>\n", 'user_AccountId': 17773629.0, 'user_DisplayName': 'Spleens', 'user_Reputation': 25.0, 'user_Views': 5.0, 'user_id': 13058397.0}}