dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
683 stars 162 forks source link

guild.fetch_members() returns an empty list when scraping is used #296

Closed LostXOR closed 2 years ago

LostXOR commented 2 years ago

Summary

guild.fetch_members() returns an empty list when scraping is used.

Reproduction Steps

Use guild.fetch_members() on any guild where the user does not have mod permissions, or use guild.fetch_members(force_scraping = True) on any guild. Even if the guild has members it will return an empty list. This happens even with guild.fetch_members(channels = guild.channels).

Code

import discord

client = discord.Client()

@client.event
async def on_ready():
    for guild in client.guilds:
        members = await guild.fetch_members(channels = guild.channels, force_scraping = True)
        print(len(members))

client.run("token")

Expected Results

The code prints how many members are in each guild the user is in.

Actual Results

The code prints 0 for every guild.

System Information

Checklist

Additional Information

No response

theAbdoSabbagh commented 2 years ago

As I understand from the expected result, you want to get the len() - aka the count - of every guild's members that the account is in. You can simply avoid fetching members. Just iterate over the guilds and use len() over .members. Example:

for guild in bot.guilds:
  print(len(guild.members))
dolfies commented 2 years ago

Don't do this, use guild.member_count

jonnytracker commented 2 years ago

when you request it several times it works

dolfies commented 2 years ago

when you request it several times it works

Don't do that either 🙃

LostXOR commented 2 years ago

As I understand from the expected result, you want to get the len() - aka the count - of every guild's members that the account is in. You can simply avoid fetching members. Just iterate over the guilds and use len() over .members. Example:

for guild in bot.guilds:
  print(len(guild.members))

I want to get every user in the guild, not the number of users. The length is just how I'm checking if it was successful.

PhilippPR commented 2 years ago

Hi! if you want to get all members of a guild, you could use something like this:

import discord

client = discord.Client()

@client.event
async def on_ready():
    guild1 = bot.get_guild(ENTER_GUILD_ID)
    for member in guild1.members:
        print(member.name) # or some other Stuff

client.run("token")

I hope I didn't screw it up, I couldn't debug this since I'm on a mobile.

jbaumgarten commented 2 years ago

The last code works only if the number of members is less than 1k members. Over it doesn't scrape anything

ZebcoWeb commented 2 years ago

I have the same problem with guild.fetch_members(force_scraping = True), and In addition to this when I use ctx.guild as Guild to fetching, it returns ClientException: Fetching members failed error

dolfies commented 2 years ago

The logs should provide more information.

ZebcoWeb commented 2 years ago

The logs should provide more information.

How to provide more information?

dolfies commented 2 years ago

Sending the logs (please set to debug log level).

ZebcoWeb commented 2 years ago

Sending the logs (please set to debug log level).

How can I do that?

dolfies commented 2 years ago

Sending the logs (please set to debug log level).

How can I do that?

You... log to a file and attach it?

dolfies commented 2 years ago

I'm completely unable to reproduce this and nobody has provided any reproduction code that doesn't have basic errors. Closing for now.

Segeco commented 2 years ago

I'm completely unable to reproduce this and nobody has provided any reproduction code that doesn't have basic errors. Closing for now.

I seem to get discord.errors.ClientException: Fetching members failed.

Code: `import logging logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)

    guild1 = client.get_guild(728174834760155137)
    print(guild1)
    members = await guild1.fetch_members()
    print(len(members))
    #print(str(lenmembersfetched)+' members fetched from ' + serverNames[guild_id])
    for member in guild1.members:
            userList.append(member.id)
            print(member.id)

`

Log is attached. example.log

@dolfies