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

Querying the member_count property on a discord.guild.Guild object gives the error AttributeError("'Guild' object has no attribute '_member_count'") #2136

Closed
3 tasks done
msr8 opened this issue Jun 21, 2023 · 1 comment · Fixed by #2145
Labels
unconfirmed bug A bug report that needs triaging

Comments

@msr8
Copy link

msr8 commented Jun 21, 2023

Summary

Querying the member_count property on a discord.guild.Guild object gives the error AttributeError("'Guild' object has no attribute '_member_count'")

Reproduction Steps

Query the member_count property on a discord guild object, like shown in the code below

Minimal Reproducible Code

from   discord.ext import commands
import discord

from rich import inspect

import json





# Loads the config
with open('config.json') as f:
    config:dict = json.load(f)




intents = discord.Intents.default()
intents.members = True
bot     = commands.Bot(intents=intents)


@bot.event
async def on_ready():
    # Get info of all the guilds
    async for guild in bot.fetch_guilds():
        actual_guild = await bot.fetch_guild(guild.id, with_counts=True)
        inspect(actual_guild)
        print(actual_guild.member_count)
    
    await bot.close()



bot.run(config['token'])

Expected Results

The count of members to be shown

Actual Results

It raised an error. This is the output:

Screenshot 2023-06-21 at 8 06 04 PM

Screenshot 2023-06-21 at 8 06 38 PM

Intents

the default ones and the member one

System Information

- Python v3.11.3-final
- py-cord v2.4.1-final
- aiohttp v3.8.4
- system info: Darwin 21.6.0 Darwin Kernel Version 21.6.0: Mon Dec 19 20:44:01 PST 2022; root:xnu-8020.240.18~2/RELEASE_X86_64

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.

Additional Context

No response

@msr8 msr8 added the unconfirmed bug A bug report that needs triaging label Jun 21, 2023
@NeloBlivion
Copy link
Member

If you use fetch_guild, you should be using Guild.approximate_member_count
That being said, this can still be considered a bug as the attribute should be set regardless.

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

Successfully merging a pull request may close this issue.

2 participants