我的 Discord 机器人代码中此错误的来源是什么?

What is the origin of this error in my Discord bot code?

我卡住了,你能帮我找到错误的根源吗?到目前为止我已经尝试过:将这个问题发布到 Whosebug。

但严重的是,它看起来像是 YoutubeDL 中的一个错误;我不确定为什么会这样。代码:

@bot.command()
async def play(ctx, url):
    channel = ctx.author.voice.channel
    voice_client = get(bot.voice_clients , guild = ctx.guild)

    if voice_client == None:
        await ctx.channel.send("Joined")
        await channel.connect()
        voice_client = get(bot.voice_clients , guild = ctx.guild)

    YDL_OPTIONS = {'format : bestaudio', 'noplaylist : True'}
    FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}


    if not voice_client.is_playing():
        with YoutubeDL(YDL_OPTIONS) as ydl:
            info = ydl.extract_info(url, download=False)
        URL = info['formats'][0]['url']
        voice_client.play(discord.FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
        voice_client.is_playing()
    else:
        await ctx.channel.send("Song has already played")
        return

跟踪如下:

Traceback (most recent call last):
  File "C:\Users\Turbo349-PC\Desktop\discord-bot\discord-bot\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "discord-bot.py", line 69, in play
    with YoutubeDL(YDL_OPTIONS) as ydl:
  File "C:\Users\Turbo349-PC\Desktop\discord-bot\discord-bot\lib\site-packages\youtube_dl\YoutubeDL.py", line 356, in __init__
    self._screen_file = [sys.stdout, sys.stderr][params.get('logtostderr', False)]
AttributeError: 'set' object has no attribute 'get'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Turbo349-PC\Desktop\discord-bot\discord-bot\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Turbo349-PC\Desktop\discord-bot\discord-bot\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Turbo349-PC\Desktop\discord-bot\discord-bot\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'set' object has no attribute 'get'

在此先感谢您的帮助!

您的 YDL_OPTIONS 格式错误:您提供的不是 dict,而是 set,因为您将冒号放在了字符串中。

您想要的不是 {'format : bestaudio', 'noplaylist : True'} -- 略有不同,但至关重要的是完全不同的数据结构 -- YDL_OPTIONS = {"format": "bestaudio", "noplaylist": True}.