@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)
这就是我目前如何让机器人加入语音通道,如何加入它时播放音频文件?我有近乎0的经验,到目前为止整个机器人已经通过提问和大量的谷歌搜索进行编码。非常感谢任何帮助,谢谢!
答案 0 :(得分:1)
您必须创建一个StreamPlayer并使用播放器操作来播放音频。这是我编写的一些示例代码,用于使用不和谐的bot播放vuvuzela:
@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.')