python - 我的 discrod 音乐机器人中的一些下载错误
问题描述
我正在制作我的音乐机器人,但我在上传视频时遇到了一些问题
@client.command()
async def play(ctx, url : str):
song_there=os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("music is playing right now, use !stop command")
return
voiceChannel=discord.utils.get(ctx.guild.voice_channels,name='General')
await voiceChannel.connect()
voice=discord.utils.get(client.voice_clients,guild=ctx.guild)
ydl_opts={
'format':'bestaudio/best',
'postprocessors':[{
'key':'FFmpegExtractAudio',
'preferredcodec':'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts)as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file,"song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"))
在我的程序中,我有更多代码,但这并不重要。编译后我有这个:
[youtube] 5RGaoLpBASw: Downloading webpage
[download] Destination: F1 Tokyo Drift-5RGaoLpBASw.m4a
[download] 100% of 1.11MiB in 00:00
[ffmpeg] Correcting container in "F1 Tokyo Drift-5RGaoLpBASw.m4a"
ERROR:
Ignoring exception in command play:
和这个:
raise FFmpegPostProcessorError(msg)
youtube_dl.postprocessor.ffmpeg.FFmpegPostProcessorError
和这个:
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR:
最后是这个:
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: DownloadError: ERROR:
但是在我的不和谐服务器上,除了将机器人连接到频道之外,什么都没有发生,但是,带有 .m4a 扩展名的文件出现在我需要播放的程序目录中。
我该如何解决这些错误?
解决方案
推荐阅读
- python - Python按文件名中的数字排序列表
- symfony - 如何在 Symfony 5 中集成 Vue
- android - 在长时间运行的线程之间传递数据(不推荐使用 LocalBroadcastManager)
- python - 如何使用现有列在熊猫中创建新列?
- php - PHP打开和关闭文件,但不向其中写入任何内容
- javascript - 在鼠标悬停时使用 CSS 和 jQuery 停止围绕圆圈旋转项目的问题
- html - 并排放置 div 并在其中添加元素
- php - PHP Array 从 API JSON 中提取或提取所有内容以进行 html 输出
- c# - 在 .Net Core 3 api 中使用 ws 安全肥皂服务
- reactjs - 如何使组件可拖动但只能从拖动图标而不是从其他任何地方拖动?