首页 > 解决方案 > discord.py bot 不会在 vc 中播放更长的音乐:OSError: [Errno 9] Bad file descriptor

问题描述

我正在尝试让我的机器人在语音频道中播放音乐。播放较短的视频有效,但是当视频变长(约 5 分钟)时,机器人不会播放它们并向我打印以下错误:OSError: [Errno 9] Bad file descriptor. 这是我的代码:

elif message.content.casefold().startswith("rachel play"):
            os.chdir(r"/home/pi/rachel")
            song_there = os.path.isfile("song.mp3")
            try:
                if song_there:
                    os.remove("song.mp3")

            except PermissionError:
                await message.send("Warte")

            voice = discord.utils.get(self.bot.voice_clients, guild=message.guild)
            parts = message.content.split()
            url = parts[-1]
            channel = message.author.voice.channel
            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("/home/pi/rachel/song.mp3"))

提前感谢您的帮助!

标签: pythondiscorddiscord.py

解决方案


推荐阅读