async def download_guild_members( self, guild_id: int, *, after: int = None, limit: int = 1000, get_all: bool = True) -> 'typing.Iterable[dt_member.Member]': """ Downloads the members for a :class:`.Guild` over HTTP. .. warning:: This can take a long time on big guilds. :param guild_id: The ID of the guild to download members for. :param after: The member ID after which to get members for. :param limit: The maximum number of members to return. By default, this is 1000 members. :param get_all: Should *all* members be fetched? :return: An iterable of :class:`.Member`. """ member_data = [] if get_all is True: last_id = 0 while True: next_data = await self.http.get_guild_members( guild_id=guild_id, limit=limit, after=last_id) # no more members to get if not next_data: break member_data.extend(next_data) # if there's less data than limit, we are finished downloading members if len(next_data) < limit: break last_id = member_data[-1]["user"]["id"] else: next_data = await self.http.get_guild_members(guild_id=guild_id, limit=limit, after=after) member_data.extend(next_data) # create the member objects members = [] for datum in member_data: m = dt_member.Member(self, **datum) m.guild_id = guild_id members.append(m) return members
def _handle_member_chunk(self, members: list): """ Handles a chunk of members. :param members: A list of member data dictionaries as returned from Discord. """ if self._chunks_left >= 1: # We have a new chunk, so decrement the number left. self._chunks_left -= 1 for member_data in members: member_id = int(member_data["user"]["id"]) if member_id in self._members: member_obj = self._members[member_id] else: member_obj = dt_member.Member(self._bot, **member_data) self._members[member_obj.id] = member_obj member_obj.nickname = member_data.get("nick", member_obj.nickname) member_obj.guild_id = self.id
async def download_guild_member(self, guild_id: int, member_id: int) -> 'dt_member.Member': """ Downloads a :class:`.Member` over HTTP. .. warning:: The :attr:`.Member.roles` and similar fields will be empty when downloading a Member, unless the guild was in cache. :param guild_id: The ID of the guild which the member is in. :param member_id: The ID of the member to get. :return: The :class:`.Member` object downloaded. """ member_data = await self.http.get_guild_member(guild_id=guild_id, member_id=member_id) member = dt_member.Member(self, **member_data) # this is enough to pick up the cache member.guild_id = guild_id # manual refcounts :ancap: self.state._check_decache_user(member.id) return member