首页 > 解决方案 > 我的 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 扩展名的文件出现在我需要播放的程序目录中。

我该如何解决这些错误?

标签: pythonffmpegdiscordbotsyoutube-dl

解决方案


推荐阅读