Python:
@bot.command()
async def монолитмыхотимслышатьтебя (ctx, url :str):
#async def монолитмыхотимслышатьтебя (channel, ctx, url : str):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("Подожди окончания или останови меня")
return
voiceChannel = discord.utils.get(ctx.guild.voice_channels)
#voiceChannel = discord.utils.get(ctx.guild.voice_channels, name=channel)
await voiceChannel.connect()
voice = discord.utils.get(bot.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:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"))
Код:
Package Version
----------------- -----------
aiohttp 3.7.4.post0
async-timeout 3.0.1
attrs 21.4.0
cffi 1.15.0
chardet 4.0.0
discord 1.7.3
discord.py 1.7.3
ffmpeg 1.4
idna 3.3
multidict 6.0.2
pip 21.3.1
pycparser 2.21
PyNaCl 1.5.0
setuptools 58.1.0
typing_extensions 4.0.1
yarl 1.7.2
youtube-dl 2021.12.17