【问题标题】:Moving a user to the message author's voice channel将用户移动到消息作者的语音频道
【发布时间】:2019-09-20 03:32:40
【问题描述】:

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

目前它将用户移动到服务器中的第一个语音通道。怎样才能把它移到作者的语音频道?

【问题讨论】:

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


    【解决方案1】:

    作者所在的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)
    

    【讨论】:

      猜你喜欢
      • 2019-11-17
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      • 2021-02-28
      • 2019-01-12
      • 2018-10-07
      • 1970-01-01
      • 2021-03-13
      相关资源
      最近更新 更多