how to download from youtube in discord py

Solutions on MaxInterview for how to download from youtube in discord py by the best coders in the world

showing results for - "how to download from youtube in discord py"
Lina
08 Apr 2018
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