首页 > 解决方案 > 断开特定用户与频道的连接

问题描述

我正在制作一个discord.py 机器人,并试图断开特定用户与 voiceChannel 的连接。我在文档中看到了方法voice_clientdiscord.guild我试图让所有的voice_clients连接到公会的voice_channels。为了稍后搜索特定的voice_client并使用voice_clients.disconnect()方法断开它。但是没有guild.voice_client返回,也许有更好的方法来做到这一点,或者我错过了什么?

这是我的一部分代码

async def vc(ctx):
    for guild in bot.guilds:
        if guild.id == myguild:
            print(guild.voice_client) #return none
            for vClients in guild.voice_client: #raise error (none is non-iterable)
                await ctx.send("thing")

标签: python-3.xdiscord.py

解决方案


async def kick(ctx: commands.Context, user: discord.Member):
    await ctx.send(f'{user.mention} has been kicked from {user.voice.channel.mention}')
    await user.move_to(None)

推荐阅读