将用户转移到消息作者的语音通道

时间:2019-05-01 15:10:27

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

试图使我的不和谐机器人将用户转移到消息作者所在的语音通道。我写了!move @john,然后机器人将“ john”移到我的语音通道。

# command to move a user to current channel
@bot.command()
async def move(ctx,member:discord.Member=None):
    channel= discord.utils.get(ctx.guild.voice_channels)
    if not member:
        await ctx.send("Who am I trying to move? Use !move @user")
    await member.move_to(channel)

此刻,它移动用户,但仅移动到服务器中的第一个语音通道。如何将其移动到作者的语音通道?

1 个答案:

答案 0 :(得分:0)

作者所在的VoiceChannel存储在ctx.author.voice.channel中。值得注意的是,.voice.channel可以是None,因此我们需要检查

@bot.command()
async def move(ctx,member:discord.Member=None):
    if ctx.author.voice and ctx.author.voice.channel:
        channel = ctx.author.voice.channel
    else:
        await ctx.send("You are not connected to voice!")
    if not member:
        await ctx.send("Who am I trying to move? Use !move @user")
    await member.move_to(channel)
相关问题