gpt4 book ai didi

python-3.x - discord.ext.commands.errors.CommandInvokeError : Command raised an exception: KeyError: 'url'

转载 作者:行者123 更新时间:2023-12-04 23:10:34 25 4
gpt4 key购买 nike

所以我的不和谐机器人得到了视频,但由于某种原因无法播放。我希望我的机器人无需下载也无需 url 即可播放音乐。到目前为止,如果我输入一个网址,它就可以工作。但是当我给它一个歌曲的名字(这里是 117)时,它无法播放音频。
这是代码:

@bot.command(name='play', help='Plays audio in connected voice channel')
async def play(ctx, q):
YDL_OPTIONS = {'default_search': 'auto', 'format': 'bestaudio', 'noplaylist':'True'}
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
voice = ctx.message.guild.voice_client


with YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(q, download=False)
a = info['url']
voice.play(FFmpegPCMAudio(a, **FFMPEG_OPTIONS))
这是错误:
[download] Downloading playlist: 117
[youtube:search] query "117": Downloading page 1
[youtube:search] playlist 117: Downloading 1 videos
[download] Downloading video 1 of 1
[youtube] PUrsOQanozo: Downloading webpage
[youtube] Downloading just video PUrsOQanozo because of --no-playlist
[download] Finished downloading playlist: 117
Ignoring exception in command play:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "E:\sa.py", line 49, in play
a = info['url']
KeyError: 'url'

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

Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\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: KeyError: 'url'

最佳答案

尝试这个:

a = info['entries'][0]['formats'][0]['url']

关于python-3.x - discord.ext.commands.errors.CommandInvokeError : Command raised an exception: KeyError: 'url' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70040979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com