Не воспроизводит аудио discord.py (Python3)
код для проигрывания аудио:
...
async def play(ctx, url: str):
files = f'"{ctx.guild.name}.mp3"'
song_there = os.path.isfile(files)
try:
if song_there:
os.remove(files)
print("Удален старый файл песни")
except PermissionError:
print("Попытка удалить файл песни, но он воспроизводится")
await ctx.send("ОШИБКА: Музыкальная игра")
return
await ctx.send("Подготовка к работе")
voice = get(client.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
print("Загрузка аудио\n")
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
name = file
print(f"Переименованный файл: {file}\n")
os.rename(file, (files))
voice.play(discord.FFmpegPCMAudio(files), after=lambda e: print("Done!"))
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.volume = 0.07
nname = name.rsplit("-", 2)
await ctx.send(f"Playing: {nname[0]}")
print("playing\n")
...
И всё работало нормально, до тех пор, когда я не решил засунуть в него ctx.guild.name для идентификации сервера и всё пошло плохо.
Можете помочь мне исправить свою ошибку, буду очень благодарен.
