首页 > 解决方案 > I got error while getting all the list of members from guild

问题描述

I used async for member in guild.fetch_members(limit=None): to get all the members from the chosen guild and I already tried to set the bot's permission to administrator and top of everyone, but still, there is the same problem. I want to get all the lists of members' IDs from a single guild.

Traceback (most recent call last):
  File "discord\client.py", line 312, in _run_event
  File "Stock.py", line 85, in on_message
  File "discord\iterators.py", line 86, in __anext__
  File "discord\iterators.py", line 605, in next
  File "discord\iterators.py", line 627, in fill_members
  File "discord\http.py", line 241, in request
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

标签: pythonpython-3.xdiscord.pydiscord.py-rewrite

解决方案


if you have the guild object you can get all member id in the specific guild by this code

member_id_list = [ member.id for member in guild.members ]

I used guild.members to get all member object in the guild and iterate through it and saved every member id in member_id_list list. read document for more info!

NOTE: make sure that you enabled SERVER MEMBERS INTENT in your discord developer portal! and add this in your code!

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix='&',intents = intents)

because without that your bot can't fetch all members in the guild!


推荐阅读