Nanomotion Nanomotion -4 years ago 246
Python Question

YoutubeDL Read Error with

I'm making a bot for Discord using, and I keep running into this error when the user requests to play a song, if it is longer than a certain time. The song cuts off and then the player plays the next song in the queue.

I'm using the default

included with the library.

The error:

[tls @ 0000000000eb9ca0] Unable to read from socket
[matroska,webm @ 0000000000eb7620] Read error
[tls @ 0000000000eb9ca0] Unable to read from socket
Last message repeated 1 times
[tls @ 0000000000eb9ca0] Failed to send close message
WARNING: unable to extract uploader nickname
WARNING: unable to extract uploader nickname

My code:

@commands.command(pass_context=True, no_pm=True)
async def play(self, ctx, *, song : str):
state = self.get_voice_state(ctx.message.server)
opts = {
'default_search': 'auto',
'quiet': True,

if state.voice is None:
success = await ctx.invoke(self.summon)
if not success:

tmp = await, "Searching for `" + song + "`...")
player = await state.voice.create_ytdl_player(song, ytdl_options=opts, after=state.toggle_next)
except Exception as e:
print(debugging.ERROR + "ERROR in 'play' command: " + str(e))
fmt = ':warning: An error occurred while processing this request: ```py\n{}: {}\n```'
await, fmt.format(type(e).__name__, e))
player.volume = 0.6
entry = VoiceEntry(ctx.message, player)
await, ':notes: Added ' + str(entry) + ' to the song queue.')
await state.songs.put(entry)

Answer Source

After doing some research, I found that adding before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5" to the create_ytdl_player function fixed the music being cutoff.

  • -reconnect 1 tells the player to reconnect if the connection to the video fails. Same with -reconnect_streamed 1, except with a stream.
  • -reconnect_delay_max 5 sets the re-connection timeout to 5 seconds. If the re-connection fails, then it aborts.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download