首页 > 解决方案 > Discord Bot 无法播放 YouTube 视频

问题描述

(顺便说一句,这是一个不和谐的机器人,我的代码运行完美,机器人可以加入语音频道,离开,但是当我要求它播放某些东西时,这就是问题所在。)我收到一个错误不要告诉我代码中的错误在哪里。我得到的错误是 [NULL @ 0x5596fd23d8e0] Unable to find a suitable output format for '5' 5: Invalid argument

这是我认为错误所在的代码部分。

@commands.command()
async def disconnect(self,ctx):
  await ctx.voice_client.disconnect()

@commands.command()
async def play(self,ctx,url):
    ctx.voice_client.stop()
    FFMPEG_OPTIONS = {'before_options': '-reconnect_streamed 1'
    '-reconnect_delay_max 5', 'options': '-vn'}
    YDL_OPTIONS = {'format':"bestaudio"}
    vc = ctx.voice_client

    with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
      info = ydl.extract_info(url, download=False)
      url2 = info['formats'][0]['url']
      source = await discord.FFmpegOpusAudio.from_probe(url2,
      **FFMPEG_OPTIONS)
      vc.play(source)

有没有人有任何想法?我在另一个线程上看到输出错误,但我不明白如何修复输出。

标签: pythondiscord

解决方案


推荐阅读