У меня установлен 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")