Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: _member_count in Guild #6652

Closed
ioistired opened this issue Apr 6, 2021 · 3 comments
Closed

AttributeError: _member_count in Guild #6652

ioistired opened this issue Apr 6, 2021 · 3 comments
Labels
unconfirmed bug A bug report that needs triaging

Comments

@ioistired
Copy link
Contributor

Summary

Guild._member_count is sometimes unset

Reproduction Steps

I'm summing my guilds' member count in on_shard_ready. My bot got disconnected from the internet, and after I got a new DHCP lease, I got this exception

Minimal Reproducible Code

# the actual code i'm using saves this to a database but this is easier to test
async def on_shard_ready(self, shard_id):
    member_count = sum(guild.member_count for guild in self.guilds if guild.shard_id == shard_id)
    print(f'Member count for shard {shard_id}: {member_count}')

Expected Results

Member count is printed after a reconnect

Actual Results

Ignoring exception in on_shard_ready
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "bot.py", line 74, in on_shard_ready
    member_count = sum(guild.member_count for guild in guilds)
  File "bot.py", line 74, in <genexpr>
    member_count = sum(guild.member_count for guild in guilds)
  File "/usr/local/lib/python3.8/site-packages/discord/guild.py", line 741, in member_count
    return self._member_count
AttributeError: _member_count

Intents

guilds, messages, guild_reactions, emojis

System Information

Checklist

I have searched the open issues for duplicates.
I have shown the entire traceback, if possible.
I have removed my token from display, if visible.

I'm not sure if the reconnect is related to this issue, but I haven't gotten it on a "cold' boot. Apparently this is supposed to be fixed by 9f47d7f.

@ioistired ioistired added the unconfirmed bug A bug report that needs triaging label Apr 6, 2021
@apple502j
Copy link
Contributor

Are you sure the guild is not unavailable? Most of the attributes cannot be accessed for unavailable guilds.

@Rapptz
Copy link
Owner

Rapptz commented Apr 7, 2021

on_shard_ready is called when a specific shard is ready, however the remaining shard guilds are still loading. The other guilds are still in the Bot.guilds mapping so there's a chance they're not fully available when you access them and the library is waiting for the GUILD_CREATE stream.

@ioistired
Copy link
Contributor Author

The code I'm using only looks at guilds in the current shard. Here's a bit more context for that traceback:

		guilds = [guild for guild in self.guilds if guild.shard_id == shard_id]
		guild_count = len(guilds)
		member_count = sum(guild.member_count for guild in guilds)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

3 participants