Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.72k stars 460 forks source link

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

Closed msr8 closed 1 year ago

msr8 commented 1 year ago

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

Additional Context

No response

NeloBlivion commented 1 year ago

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.