【问题标题】:Troubles with playing music Discord.py播放音乐的问题 Discord.py
【发布时间】:2021-04-09 16:45:02
【问题描述】:

我尝试使用 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)
提前致谢

【问题讨论】:

    标签: python discord discord.py discord.py-rewrite


    【解决方案1】:

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

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

    参考:

    【讨论】:

      【解决方案2】:

      考虑使用DiscordUtils 模块。它有一个名为 DiscordUtils.Music 的类

      【讨论】:

        猜你喜欢
        • 2021-02-06
        • 2021-05-05
        • 2020-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-21
        • 1970-01-01
        相关资源
        最近更新 更多