播放音乐时遇到问题 Discord.py

Troubles with playing music Discord.py

我尝试使用 youtube_dl 发出播放音乐的命令。我的 discord.py 版本是 1.5.1
这是我的代码:

@bot.command()
async def play(ctx, url: str):
    await ctx.message.delete()
    song_there = os.path.isfile("song.mp3")
    try:
        if song_there:
            os.remove("song.mp3")
    except PermissionError:
        await ctx.send("Wait for the current playing music end or use the 'stop' command")
        return
    await ctx.send("Getting everything ready, playing audio soon")
    print("Someone wants to play music let me get that ready for them...")
    voice = 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"))
    voice.volume = 100
    voice.is_playing()

但我得到了这个输出:

TypeError: request() got an unexpected keyword argument 'guild'

错误在这一行voice = get(bot.voice_clients, guild=ctx.guild)
提前致谢

每个公会只能有 1 个语音客户端,所以只需:

voice = ctx.guild.voice_client
# or
voice = ctx.voice_client

参考:

考虑使用 DiscordUtils 模块。它有一个 class 叫做 DiscordUtils.Music