python - 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"))
提前感谢您的帮助!
解决方案
推荐阅读
- firebase - Vaadin Flow 中的 Firebase 身份验证
- angular - 将单例与数据一起用于段中
- python - 如何使用 event.type?
- python - For循环中的函数未返回正确的值
- r - 使用 lubridate 转换日期字符串,但不调整夏令时
- javascript - 更改纸张颜色 Material-UI
- javascript - 如何在 passport.js 中访问 req.user 数据成员
- excel - 如何选择所有值的范围,直到第 3 行下的末尾?
- c++ - C++ 创建一个长度为变量的数组会生成随机大小的数组
- raft - RAFT 上是否丢弃了消息?