问题描述
所以我正在创建一个不和谐机器人,它会随机挑选 5 首歌曲,使用 youtube-dl 下载并播放它们。代码:
# Function to play music
async def radio(count,voiceClient,textChannel):
randomSong = songs[random.randint(0,len(songs)-1)]
# Open a temporary directory to stop downloaded files being saved
with tempfile.TemporaryDirectory() as tempDir:
# Use youtube-dl to get the Metadata
ydlOptions = {
"format": "bestaudio/best","outtmpl": f"{tempDir}/%(id)s.%(ext)s",}
with YoutubedL(ydlOptions) as ydl:
realLinkRaw = ydl.extract_info(randomSong,download=True)
videoID = realLinkRaw["id"]
videoExtension = realLinkRaw["ext"]
# Test if its the first song so a message can be displayed
if count == 0:
# First song so output a message describing it
title = realLinkRaw["title"]
await textChannel.send(f"Up next,{title}")
# Play the song
tempFileName = f"{tempDir}/{videoID}.{videoExtension}"
voiceClient.play(FFmpegPCMAudio(tempFileName))
# Wait for the duration of the song before repeating
await asyncio.sleep(realLinkRaw["duration"])
# Function to loop continuously and run the main program
async def mainProg(voiceClient,textChannel):
# Create infinite loop to run main program
while True:
# Output a random radio message
await textChannel.send(radioLines[random.randint(0,len(radioLines)-1)])
# Play 5 random songs
for count in range(5):
await radio(count,textChannel)
但是,目前在播放完第一首歌曲后,出现此错误:
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\jacka\\AppData\\Local\\Temp\\tmpzodsgvvw\\SH_pDjcQx2w.m4a'
整个回溯: https://pastebin.com/2HVJvS5m
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)