1import discord
2from discord.ext import commands
3import youtube_dl
4
5client = commands.Bot(command_prefix = '!', intents=intents)
6
7@client.command(pass_context = True)
8async def download(ctx, url:str):
9
10 ydl_opts = {
11 'format': 'bestaudio/best',
12 'preferredcodec': [{
13 'key': 'FFmpegExtractAudio',
14 'preferredcodec': 'webm',
15 'preferredquality': '192',
16 }],
17 }
18
19 with youtube_dl.YoutubeDL(ydl_opts) as ydl:
20 ydl.download([url])
21
22client.run(TOKEN)
23