2017-04-04 102 views
0

我正在用Discord.py製作Discord的bot,當用戶請求播放歌曲時,如果播放時間超過特定時間,我會一直遇到此錯誤。歌曲中斷,然後播放器播放隊列中的下一首歌曲。YoutubeDL用Discord.py讀取錯誤

我使用庫中包含的默認state.voice.create_ytdl_player()

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 

我的代碼:

@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: 
      return 

    try: 
     tmp = await self.bot.send_message(ctx.message.channel, "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 self.bot.send_message(ctx.message.channel, fmt.format(type(e).__name__, e)) 
    else: 
     player.volume = 0.6 
     entry = VoiceEntry(ctx.message, player) 
     await self.bot.edit_message(tmp, ':notes: Added ' + str(entry) + ' to the song queue.') 
     await state.songs.put(entry) 

回答

0

做了一些研究之後,我發現,添加before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"create_ytdl_player功能固定的音樂被切斷。

  • -reconnect 1告訴玩家如果連接到視頻失敗時重新連接。與-reconnect_streamed 1相同,除了流。
  • -reconnect_delay_max 5將重新連接超時設置爲5秒。如果重新連接失敗,則中止。