📜  如何在 discord.py 中从 youtube 下载 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:21.752000             🧑  作者: Mango

代码示例1
import discord
from discord.ext import commands
import youtube_dl

client = commands.Bot(command_prefix = '!', intents=intents)

@client.command(pass_context = True)
async def download(ctx, url:str):

  ydl_opts = {
              'format': 'bestaudio/best',
              'preferredcodec': [{
                  'key': 'FFmpegExtractAudio',
                  'preferredcodec': 'webm',
                  'preferredquality': '192',
          }],
          }
  
  with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([url])

client.run(TOKEN)