Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.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 如何让我的discord机器人在加入语音频道(如airhorn solutions机器人)时正确播放音频文件?_Python_Python 3.x_Discord.py - Fatal编程技术网

Python 如何让我的discord机器人在加入语音频道(如airhorn solutions机器人)时正确播放音频文件?

Python 如何让我的discord机器人在加入语音频道(如airhorn solutions机器人)时正确播放音频文件?,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,这就是我目前让机器人加入语音频道的方式,我如何让它在加入时播放音频文件?我几乎没有经验,到目前为止,整个机器人都是通过提问和大量谷歌搜索来编码的。非常感谢您的帮助,谢谢 您必须创建StreamPlayer并使用播放器操作来播放音频。下面是我编写的用discord机器人播放呜呜祖拉的示例代码: @client.command(pass_context=True) async def joinvoice(ctx): """Joins user's voice channel""" a

这就是我目前让机器人加入语音频道的方式,我如何让它在加入时播放音频文件?我几乎没有经验,到目前为止,整个机器人都是通过提问和大量谷歌搜索来编码的。非常感谢您的帮助,谢谢

您必须创建StreamPlayer并使用播放器操作来播放音频。下面是我编写的用discord机器人播放呜呜祖拉的示例代码:

@client.command(pass_context=True)
async def joinvoice(ctx):
    """Joins user's voice channel"""
    author = ctx.message.author
    voice_channel = author.voice_channel
    vc = await client.join_voice_channel(voice_channel)
@client.command(
    name='vuvuzela',
    description='Plays an awful vuvuzela in the voice channel',
    pass_context=True,
)
async def vuvuzela(context):
    # grab the user who sent the command
    user = context.message.author
    voice_channel = user.voice.voice_channel
    channel = None
    if voice_channel != None:
        channel = voice_channel.name
        await client.say('User is in channel: ' + channel)
        vc = await client.join_voice_channel(voice_channel)
        player = vc.create_ffmpeg_player('vuvuzela.mp3', after=lambda: print('done'))
        player.start()
        while not player.is_done():
            await asyncio.sleep(1)
        player.stop()
        await vc.disconnect()
    else:
        await client.say('User is not in a channel.')