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

问题描述 投票:0回答:1

试图使我的不和谐机器人将用户移动到消息作者所在的语音通道。例如。我写!move @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)

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

python-3.x discord discord.py discord.py-rewrite
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.