【问题标题】:Discord py how can I join a voice channelDiscord py如何加入语音频道
【发布时间】:2021-02-01 23:16:35
【问题描述】:

如何让我的机器人(在 cog 中)加入用户所在的语音频道? 我有这个代码:

@commands.command(name='join')
async def join(self, ctx):
    channel = ctx.author.channel

    voice = discord.utils.get(ctx.guild.voice_channels, name=channel.name)

    voice_client = discord.utils.get(self.client.voice_clients, guild=ctx.guild)

    if voice_client == None:
        await voice.connect()
    else:
        await voice_client.move_to(channel)

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    您需要使用 ctx.author.voice.channel 而不是 ctx.author.channel

    @commands.command(name='join')
    async def join(self, ctx):
        channel = ctx.message.author.voice.channel
    
        voice = discord.utils.get(ctx.guild.voice_channels, name=channel.name)
    
        voice_client = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
    
        if voice_client == None:
            await voice.connect()
        else:
            await voice_client.move_to(channel)
    

    这应该可以工作

    【讨论】:

    • 没有足够的声誉 sry :/
    猜你喜欢
    • 2020-11-04
    • 2020-11-03
    • 1970-01-01
    • 2022-01-23
    • 2021-01-05
    • 2020-06-26
    • 2020-07-16
    • 2017-06-22
    • 2020-12-21
    相关资源
    最近更新 更多