Python 3.x 打印语音频道中的成员列表

Python 3.x 打印语音频道中的成员列表,python-3.x,windows,discord,discord.py,discord.py-rewrite,Python 3.x,Windows,Discord,Discord.py,Discord.py Rewrite,我正在编写一个discord bot,我需要一个可以踢我频道中所有成员的函数。我写了这段代码: @client.command() async def separaci(ctx): canale = ctx.message.author.voice.channel utenti = canale.members #This return an empty list for utente in utenti: await utente.edit(voice_

我正在编写一个discord bot,我需要一个可以踢我频道中所有成员的函数。我写了这段代码:

@client.command()
async def separaci(ctx):
    canale = ctx.message.author.voice.channel
    utenti = canale.members #This return an empty list
    for utente in utenti:
        await utente.edit(voice_channel = None)

我不知道为什么
canale。成员
返回一个空列表。你能帮助我吗?谢谢:)

您必须启用成员意图,同时确保在

intents=discord.intents.default()
intents.members=True
client=commands.Bot(命令前缀=“”,意图=意图)
@client.command()
异步def separaci(ctx):
频道=ctx.author.voice.channel
members=channel.members

    • 您必须启用成员意图,还必须确保在

      intents=discord.intents.default()
      intents.members=True
      client=commands.Bot(命令前缀=“”,意图=意图)
      @client.command()
      异步def separaci(ctx):
      频道=ctx.author.voice.channel
      members=channel.members
      
      试试这个:

      @client.command()
      异步def separaci(ctx):
      如果ctx.author.voice:#如果作者连接到语音频道
      canale=ctx.message.author.voice.channel
      Unteti=canale.members#返回一个空列表
      对于utenti中的utente:
      等待执行编辑(语音频道=无)
      等待ctx.send(“将所有成员踢出语音频道!”)
      其他:
      等待ctx.send(“您需要进入语音频道!”)
      返回
      

      注:
      • 使用此命令时,您需要处于语音频道中
      • 确保bot有权断开语音频道中存在的成员的连接
      • 确保在您的应用程序中启用了
        成员
        意图
      试试这个:

      @client.command()
      异步def separaci(ctx):
      如果ctx.author.voice:#如果作者连接到语音频道
      canale=ctx.message.author.voice.channel
      Unteti=canale.members#返回一个空列表
      对于utenti中的utente:
      等待执行编辑(语音频道=无)
      等待ctx.send(“将所有成员踢出语音频道!”)
      其他:
      等待ctx.send(“您需要进入语音频道!”)
      返回
      

      注:
      • 使用此命令时,您需要处于语音频道中
      • 确保bot有权断开语音频道中存在的成员的连接
      • 确保在您的应用程序中启用了
        成员
        意图

      这意味着没有人在语音频道,我猜不,我们在语音频道有6个。这意味着没有人在语音频道,我猜不,我们在语音频道有6个。