【问题标题】:Print the list of members in a voice channel打印语音频道中的成员列表
【发布时间】:2020-11-18 10:33:10
【问题描述】:

我正在编写一个不和谐的机器人,我需要一个功能来踢我频道中的所有成员。我写了这段代码:

@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.members 返回一个空列表。你能帮助我吗?谢谢你:)

【问题讨论】:

  • 大概是没有人在语音频道里吧
  • 不,我们是 6 在语音频道。

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


【解决方案1】:

试试这个:

@client.command()
async def separaci(ctx):
    if ctx.author.voice: # if the author is connected to a voice channel
        canale = ctx.message.author.voice.channel
        utenti = canale.members #This return an empty list
        for utente in utenti:
            await utente.edit(voice_channel = None)
        await ctx.send("Kicked all the members from the voice channel!")
    else:
         await ctx.send("You need to be in a voice channel!")
         return

注意:

  • 使用此命令时,您需要在语音频道中。
  • 确保机器人有权断开语音通道中的成员。
  • 确保您在 developer portal 中启用了 members 意图。

【讨论】:

    【解决方案2】:

    您必须启用成员意图,并确保在developer portal 中启用它们

    intents = discord.Intents.default()
    intents.members = True 
    
    client = commands.Bot(command_prefix='', intents=intents)
    
    @client.command()
    async def separaci(ctx):
        channel = ctx.author.voice.channel
        members = channel.members
    

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2020-12-21
      • 1970-01-01
      • 2021-01-27
      • 2018-10-07
      • 2021-06-06
      • 2021-01-29
      • 1970-01-01
      • 2020-12-01
      相关资源
      最近更新 更多