Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法迭代服务器不协调API的成员_Api_Loops_Discord.py - Fatal编程技术网

无法迭代服务器不协调API的成员

无法迭代服务器不协调API的成员,api,loops,discord.py,Api,Loops,Discord.py,当我运行这段代码时,它只返回两次bot名称。服务器有两个成员,我自己和bot。我需要遍历服务器的每个成员。我做错了什么?您只是没有启用意图。成员 intents=discord.intents.default() intents.members=True client=commands.Bot(command_prefix=“:”,intents=intents) 还要确保在中启用它们 参考: 哎呀,我真傻。非常感谢你的回答!!!现在开始工作了 import discord import

当我运行这段代码时,它只返回两次bot名称。服务器有两个成员,我自己和bot。我需要遍历服务器的每个成员。我做错了什么?

您只是没有启用
意图。成员

intents=discord.intents.default()
intents.members=True
client=commands.Bot(command_prefix=“:”,intents=intents)
还要确保在中启用它们

参考:


哎呀,我真傻。非常感谢你的回答!!!现在开始工作了
import discord
import asyncio
from discord.ext import commands

client = commands.Bot(command_prefix=':')
token = ''

@client.event
async def on_ready():
    print('BOT ONLINE')

@client.event
async def on_message(message):
    channel = message.channel
    if message.content.startswith('/'):
        if message.content.startswith("/users"):
            # FOR LOOP IN QUESTION ---------------
            for guild in client.guilds:
                for member in guild.members:
                    print(member)  # or do whatever you wish with the member detail

client.run(token)


print("Bot Finished")