首页 > 解决方案 > 如何让我的不和谐机器人从我的电脑播放音频文件

问题描述

我试图让我的机器人在语音聊天中播放音频文件,而不是 youtube 视频。令人惊讶的是,我真的找不到任何工作帮助。


@client.command()
async def play(ctx, *args):
    if len(args) == 0:
        await ctx.send("Specify something then")
    else:
        #server = ctx.message.server
        #voice_client = client.voice_client_in(server)

        voice_player = await ctx.message.author.voice.channel.connect()

        if args[0] == "chulp":
            print("Playing chulp")
            source = discord.FFmpegPCMAudio("Core files\\Sounds\\chulpy.mp3")
            player = voice_player.play(source)
            player.start()

我总是收到这个错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'start'

标签: python-3.xvoicediscord.py-rewrite

解决方案


你做错了。你必须这样做——

if args[0] == "chulp":
    print("Playing chulp")
    player = voice_player.create_ffmpeg_player("Core files\\Sounds\\chulpy.mp3")
    player.start()

我不确定,但这也可以-

if args[0] == "chulp":
    print("Playing chulp")
    voice_player.play(discord.FFmpegPCMAudio("Core files\\Sounds\\chulpy.mp3"))

我认为您结合了来自 2 个不同来源的代码。


推荐阅读