dolfies / discord.py-self

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

fetch_members don't work with join_guild lurking #420

Closed contusionglory closed 1 year ago

contusionglory commented 2 years ago

Summary

When using the join_guild instead of get_guild the fetch_members returns discord.errors.ClientException: Fetching members failed

Reproduction Steps

Join a guild with lurking Fetch members Print members

Code

This is working:

            guild: discord.Guild = client.get_guild(guildid, lurking=True)
            _good_channels = [
                    channel
                    for channel in guild.channels
                    if channel.type == discord.ChannelType.text
                ]
            _good_channels = sorted(
                    list(islice(_good_channels, 5)),
                    key=lambda x: len(x.members),
                    reverse=True,
                )
            await guild.fetch_members(channels=_good_channels, force_scraping=True)
            for member in guild.members:
                    print(member.id)

This is not working:
```python
            guild: discord.Guild = await client.join_guild(guildid, lurking=True)
            class channel:
                id=559785804910690323
            await guild.fetch_members(channels=[channel], force_scraping=True)
            for member in guild.members:
                    print(member.id)

(i made the class because it dosen't fetch the chats with join_guild)

2022-11-22 18:51:31,202:DEBUG:discord.client: Dispatching event guild_join.
2022-11-22 18:51:31,223:DEBUG:discord.http: PUT https://discord.com/api/v9/guilds/559783350001205248/members/@me with {} has returned 200.
2022-11-22 18:51:31,224:DEBUG:discord.http: PUT https://discord.com/api/v9/guilds/559783350001205248/members/@me has received 2022-11-22 18:51:31,202:DEBUG:discord.client: Dispatching event guild_join.
2022-11-22 18:51:31,223:DEBUG:discord.http: PUT https://discord.com/api/v9/guilds/559783350001205248/members/@me with {} has returned 200.
2022-11-22 18:51:31,224:DEBUG:discord.http: PUT https://discord.com/api/v9/guilds/559783350001205248/members/@me has received { 'id': '559783350001205248', 'name': 'Fortnite Town', 'icon': 'a_2b62d98074cd6c6d700897c40ae82429', 'description': 'Fortnite STW', 'splash': '7fa7a20246a067a31ff8df9f88202126', 'discovery_splash': 'addca91164b857e19926e7ecacf65f34', 'features': ['WELCOME_SCREEN_ENABLED', 'COMMUNITY', 'DISCOVERABLE', 'THREADS_ENABLED', 'PREVIEW_ENABLED', 'NEW_THREAD_PERMISSIONS', 'VANITY_URL', 'APPLICATION_COMMAND_PERMISSIONS_V2', 'THREE_DAY_THREAD_ARCHIVE', 'ENABLED_DISCOVERABLE_BEFORE', 'ANIMATED_ICON', 'NEWS', 'INVITE_SPLASH', 'COMMUNITY_EXP_LARGE_UNGATED'], 'welcome_screen': {     'description': 'An Amazing Fortnite Server, for trading, mission help, and daily giveaways, Come chill in general chat!!',     'welcome_channels': [{     'channel_id': '559785804910690323',     'description': 'Make Sure To Check out Rules!',     'emoji_id': None,     'emoji_name': '📔'     }, {     'channel_id': '655970069884698634',     'description': 'Give Yourself Roles!',     'emoji_id': None,     'emoji_name': '📕'     }, {     'channel_id': '859729647104425984',     'description': 'Check out our Daily Giveaways!',     'emoji_id': None,     'emoji_name': '🎁'     }, {     'channel_id': '579455228537995274',     'description': 'Meet New Friends!',     'emoji_id': None,     'emoji_name': '💬'     }, {     'channel_id': '579456092497510403',     'description': 'Trade with other Players!',     'emoji_id': None,     'emoji_name': '♻️'     }] }, 'emojis': [various emojis], 'stickers': [{     'id': '1003141420091195442',     'name': 'Tipper Seizure',     'tags': 'joy',     'type': 2,     'format_type': 1,     'description': '',     'asset': '',     'available': True,     'guild_id': '559783350001205248' }], 'banner': None, 'owner_id': '347232548360814602', 'application_id': None, 'region': 'us-east', 'afk_channel_id': None, 'afk_timeout': 1800, 'system_channel_id': '676914956347768912', 'widget_enabled': False, 'widget_channel_id': None, 'verification_level': 2, 'roles': [{     'id': '559783350001205248',     'name': '@everyone',     'description': None,     'permissions': '693674297345',     'position': 0,     'color': 0,     'hoist': False,     'managed': False,     'mentionable': False,     'icon': None,     'unicode_emoji': None,     'flags': 0 }, {     'id': '559786343509655553',     'name': 'MEE6',     'description': None,     'permissions': '6475218489',     'position': 24,     'color': 0,     'hoist': False,     'managed': True,     'mentionable': False,     'icon': None,     'unicode_emoji': None,     'flags': 0,     'tags': {     'bot_id': '159985870458322944'     } } }], 'default_message_notifications': 1, 'mfa_level': 1, 'explicit_content_filter': 2, 'max_presences': None, 'max_members': 500000, 'max_stage_video_channel_users': 0, 'max_video_channel_users': 25, 'vanity_url_code': 'fortnite-town-559783350001205248', 'premium_tier': 1, 'premium_subscription_count': 3, 'system_channel_flags': 9, 'preferred_locale': 'en-US', 'rules_channel_id': '559785804910690323', 'safety_alerts_channel_id': None, 'public_updates_channel_id': '579450386033803304', 'hub_type': None, 'premium_progress_bar_enabled': True, 'nsfw': False, 'nsfw_level': 0 }
2022-11-22 18:51:31,476:DEBUG:discord.gateway: Gateway event: {'t': 'THREAD_LIST_SYNC', 's': 5, 'op': 0, 'd': {'threads': [], 'most_recent_messages': [], 'guild_id': '559783350001205248'}}.
2022-11-22 18:51:31,476:DEBUG:discord.client: Dispatching event socket_event_type.
2022-11-22 18:51:31,476:DEBUG:discord.gateway: Parsing event THREAD_LIST_SYNC.
2022-11-22 18:51:31,476:DEBUG:discord.gateway: Gateway event: {'t': 'GUILD_MEMBERS_CHUNK', 's': 6, 'op': 0, 'd': {'presences': [], 'not_found': [], 'nonce': '1044671485605576704', 'members': [my own user], 'guild_id': '559783350001205248', 'chunk_index': 0, 'chunk_count': 1}}.
2022-11-22 18:51:31,476:DEBUG:discord.client: Dispatching event socket_event_type.
2022-11-22 18:51:31,476:DEBUG:discord.gateway: Parsing event GUILD_MEMBERS_CHUNK.
2022-11-22 18:51:31,476:DEBUG:discord.state: Processed a chunk for 1 members in guild ID 559783350001205248.
2022-11-22 18:51:31,476:DEBUG:discord.gateway: Subscribing to guild 559783350001205248 with payload {'guild_id': '559783350001205248', 'channels': {}}
.
2022-11-22 18:51:31,476:DEBUG:discord.client: Dispatching event socket_event_type.
2022-11-22 18:51:31,476:DEBUG:discord.gateway: Parsing event GUILD_MEMBERS_CHUNK.
2022-11-22 18:51:31,476:DEBUG:discord.state: Processed a chunk for 1 members in guild ID 559783350001205248.
2022-11-22 18:51:31,476:DEBUG:discord.gateway: Subscribing to guild 559783350001205248 with payload {'guild_id': '559783350001205248', 'channels': {}}


### Expected Results

Fetching all members

### Actual Results

No user is fetched

### System Information

- Python v3.10.0-final
- discord.py-self v2.0.0-alpha
    - discord.py-self pkg_resources: v2.0.0a2
- aiohttp v3.8.3
- system info: Windows 10 10.0.19044

### Checklist

- [X] I have searched the open issues for duplicates.
- [X] I have shared the entire traceback.
- [X] I am using a user token (and it isn't visible in the code).

### Additional Information

_No response_
dolfies commented 1 year ago

Sorry for the late reply,

The guild returned from the join_guild() method is not the same guild that is added to cache, you must get it from cache first. Additionally, instead of making dunder channel classes, you can use discord.Object(id=xxx).