В чем разница между message.content и просто строковым вводом? - PullRequest
0 голосов
/ 04 октября 2019

Я пытаюсь воспроизвести введенное видео на YouTube, но оно не работает. При определении URL-адреса вручную в коде я не получаю сообщение об ошибке

КОД:

ydl_opts = {
   'outtmpl': f'/tmp/{id}.%(ext)s',
   'format': 'bestaudio/best',
   'postprocessors': [{
      'key': 'FFmpegExtractAudio',
      'preferredcodec': 'mp3',
      'preferredquality': '48',
   }]
}
with youtube_dl.YoutubeDL(ydl_opts) as ytdl:
   url = "{}".format(str(message.content.lower().split()[1])) # <-- Not    Working
   #url = "https://www.youtube.com/watch?v=8FJhEbhCYo8"# <-- Working
   ytdl.download([url])
   name = ytdl.prepare_filename({'id': id, 'ext':'mp3'})
   audio = discord.FFmpegPCMAudio(name)
   voice_client.play(audio)

ОШИБКА:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "E:\XYZ\XYZ\XYZ\XYZ\XYZ.py", line 32, in on_message
    await startMusic(message)
  File "E:\XYZ\XYZ\Damien\XYZ\XYZ.py", line 157, in startMusic
    ytdl.download([url])
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\site-packages\youtube_dl\YoutubeDL.py", line 2010, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\site-packages\youtube_dl\YoutubeDL.py", line 819, in extract_info
    self.report_error(compat_str(e), e.format_traceback())
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\site-packages\youtube_dl\YoutubeDL.py", line 624, in report_error
    self.trouble(error_message, tb)
  File "C:\Users\XYZ\AppData\Local\Programs\Python\Python37\lib\site-packages\youtube_dl\YoutubeDL.py", line 594, in trouble
    raise DownloadError(message, exc_info)

Команда была: play https://www.youtube.com/watch?v=8FJhEbhCYo8

...