如何直接从YouTube播放音乐

时间:2020-04-05 09:21:17

标签: python discord.py

这是我的代码

@Bot.command(name = 'play')
async def player (ctx,url):
    try:
        await ctx.message.author.voice.channel.connect()
        voice = get(Bot.voice_clients, guild=ctx.guild)
    except discord.ext.commands.errors.CommandInvokeError:
        voice = get(Bot.voice_clients, guild=ctx.guild)
    for file in os.listdir('./'):
        if file == 'song.mp3':
            os.remove('song.mp3')
    with ytdl.YoutubeDL(ytdl_opts) as yt:
        yt.download([url])
    for doc in os.listdir('./'):
        if doc.endswith('mp3'):
            os.rename(doc,'song.mp3')
    voice.play(discord.FFmpegOpusAudio('song.mp3'))

如果我知道视频的网址,我想发现如何直接从youtube播放音乐 这将帮助我优化代码

0 个答案:

没有答案