【发布时间】:2020-06-18 14:11:11
【问题描述】:
我安装了 ffmpeg,youtube-dl,我安装了所有要求,它下载了歌曲重命名但没有任何反应!
@client.command()
async def play(ctx, *url: str):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
print("Removed old song file")
except PermissionError:
print("Trying to delete song file, but it's being played")
await ctx.send("ERROR: Music playing")
return
await ctx.send("Getting everything ready now")
voice = get(client.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': 'bestaudio/best',
'quiet': True,
'outtmpl':"./song.mp3",
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
song_search = " ".join(url)
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
print("Downloading audio now\n")
ydl.download([f"ytsearch1:{song_search}"])
for file in os.listdir("./"):
if file.endswith(".mp3"):
name = file
print(f"Renamed File: {file}\n")
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print(f"{name} has finished playing"))
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.volume = 0.10
nname = name.rsplit("-", 2)
await ctx.send(f"Currently playing: {nname}")
print("playing\n")
【问题讨论】:
-
很难判断问题出在哪里,请尝试在 heroku 上检查您的错误跟踪。
-
我似乎没有任何错误,得到重命名的文件然后什么都没有gyazo.com/b4110a13b393721c0b2a743a8fb3b4aa
-
因为记录了“重命名文件”但不是最后一个
print(playing)这告诉我上面的 5 行代码出了点问题。尝试在它们之间添加打印语句,看看哪个没有被记录。这将查明错误 -
好的,所以我测试了一下,这里似乎是这条线
voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print(f"{name} has finished playing"))我仍然不确定为什么! -
太棒了。看看下面的答案
标签: python heroku ffmpeg bots discord