我的不和谐机器人播放来自 youtube 网址的音频时遇到问题


sync def hog():
channel = bot.get_channel(964971002289356893)
url = 'https://www.youtube.com/watch?v=GyRmkAfpCOM'
await asyncio.sleep(1)
voice_channel = bot.get_channel(int(964971002289356893))
vc = await voice_channel.connect()
#vc.play(discord.FFmpegPCMAudio('C:/Users/alexa/Downloads/hogrider.mp3'))
vc.play(discord.FFmpegPCMAudio(source='https://www.youtube.com/watch?v=GyRmkAfpCOM', executable='ffmpeg.exe'))
while vc.is_playing():
await asyncio.sleep(5)
await vc.disconnect()

它可以很好地从我的笔记本电脑的音频文件,但我想播放它从youtube链接。它给了我一个错误:https://www.youtube.com/watch?v=GyRmkAfpCOM:处理输入时发现无效数据

提前谢谢你

也许你应该改变你的代码,但要确保你需要安装ffmpeg。我正在使用这个代码为我的音乐播放器(在我的discord bot上)

async def hog(ctx, url:str):
channel = bot.get_channel(put your channel here)
vc = ctx,.voice_client
await asyncio.sleep(1)
video = search(query=title)
source = video['formats'][0]['url']
vc.play(FFmpegPCMAudio(source, **FFMPEG_OPTIONS))

可以看到search函数被调用

def search(query):
YDL_OPTION = {
'format': 'bestaudio/best',
'noplaylist': True,
'nocheckcertificate': True,
'default_search': 'auto',
'geo_bypass': True,
}
with YoutubeDL(YDL_OPTION) as ydl:
try:
requests.get(query)
except:
info = ydl.extract_info(f"ytsearch:{query}", download=False)['entries'][0]
else:
info = ydl.extract_info(query, download=False)
return info

相关内容

  • 没有找到相关文章