Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何让我的discord bot从我的计算机播放音频文件_Python 3.x_Voice_Discord.py Rewrite - Fatal编程技术网

Python 3.x 如何让我的discord bot从我的计算机播放音频文件

Python 3.x 如何让我的discord bot从我的计算机播放音频文件,python-3.x,voice,discord.py-rewrite,Python 3.x,Voice,Discord.py Rewrite,我试图让我的机器人在语音聊天中播放音频文件,而不是youtube视频。令人惊讶的是,我在这方面找不到任何有效的帮助 @client.command() 异步def播放(ctx,*参数): 如果len(args)==0: 等待ctx.send(“然后指定某物”) 其他: #server=ctx.message.server #语音客户端=客户端。语音客户端(服务器) voice\u player=wait ctx.message.author.voice.channel.connect() 如果

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


@client.command()
异步def播放(ctx,*参数):
如果len(args)==0:
等待ctx.send(“然后指定某物”)
其他:
#server=ctx.message.server
#语音客户端=客户端。语音客户端(服务器)
voice\u player=wait ctx.message.author.voice.channel.connect()
如果args[0]=“chulp”:
打印(“玩小傻瓜”)
source=discord.ffmpegpcaudio(“核心文件\\Sounds\\chulpy.mp3”)
player=voice\u player.play(来源)
player.start()
我总是会遇到这样的错误:

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

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

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"))
我认为您组合了来自两个不同来源的代码


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

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"))
我认为您组合了来自两个不同来源的代码


play
不会返回任何内容,它应该只是开始播放文件。如果删除
player.start()
行,会发生什么?它不会更改任何内容
play
不会返回任何内容,它应该开始播放文件。如果删除
player.start()
行,会发生什么?它不会改变任何东西它不起作用,它甚至不会打印确认它不起作用,它甚至不会打印确认