Discord.py正在所有服务器上的语音通道中获取成员

Discord.py正在所有服务器上的语音通道中获取成员,discord.py,Discord.py,我想打印出连接到Discord bot所连接的语音频道的所有Discord用户的ID。bot对所有不协调具有管理员权限,并可以访问所有频道。我曾尝试使用这段代码来完成它,但我就是无法让它工作。channel.members仅返回空列表。 (我当然检查过是否有人连接到语音频道) 阅读帖子上的评论时,您会说您已经启用了意图,但从您的代码来看,代码中似乎没有启用意图。你必须两者都做。去看医生 import discord from discord.ext import commands, tasks

我想打印出连接到Discord bot所连接的语音频道的所有Discord用户的ID。bot对所有不协调具有管理员权限,并可以访问所有频道。我曾尝试使用这段代码来完成它,但我就是无法让它工作。channel.members仅返回空列表。 (我当然检查过是否有人连接到语音频道)


阅读帖子上的评论时,您会说您已经启用了意图,但从您的代码来看,代码中似乎没有启用意图。你必须两者都做。去看医生

import discord
from discord.ext import commands, tasks
intents = discord.Intents.default()
intents.members = True

global client

prefix = "-"
client = commands.Bot(command_prefix=prefix,intents=intents, case_insensitive=True)

@client.event
async def on_ready():
    print("Ready")
    for guild in client.guilds:
        for channel in guild.voice_channels:
            for member in channel.members:
                print(member.id)

在两个不同行会的VC中测试了两个用户,并且都打印了

您是否启用了intent.members?@ukaszKwieciński是的,但是机器人是否需要验证才能使用它?目前只有27台服务器。此外,Thrown也不例外。一旦机器人到达100个或更多的行会@ukaszKwieciński,它将需要验证。顺便说一句,你还有其他建议吗?我已经在顶部设定了意图,但dumb me ofc忘了将其作为客户端的参数添加。谢谢你的帮助!
import discord
from discord.ext import commands, tasks
intents = discord.Intents.default()
intents.members = True

global client

prefix = "-"
client = commands.Bot(command_prefix=prefix,intents=intents, case_insensitive=True)

@client.event
async def on_ready():
    print("Ready")
    for guild in client.guilds:
        for channel in guild.voice_channels:
            for member in channel.members:
                print(member.id)