ChinemeremChigbo / discord-mutual-friends-and-servers

Provides lists of Discord server members that are your friends, members you have mutual friends with, and members you have mutual servers with.
17 stars 0 forks source link

Discord API problem? #1

Open Ishiroo opened 2 months ago

Ishiroo commented 2 months ago

I ran the program by going into the directory where I put the folder, and I got the message telling me logging in with discord token, but then:

D:>cd D:\discord-mutual-friends-and-servers-main

D:\discord-mutual-friends-and-servers-main>python main.py [2024-04-17 08:09:13] [INFO ] discord.client: Logging in using static token. INFO:discord.client:Logging in using static token. [2024-04-17 08:09:30] [WARNING ] discord.utils: Info API down. Falling back to manual fetching... WARNING:discord.utils:Info API down. Falling back to manual fetching... Traceback (most recent call last): File "D:\discord-mutual-friends-and-servers-main\main.py", line 407, in client.run(token) File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\client.py", line 938, in run asyncio.run(runner()) File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\client.py", line 927, in runner await self.start(token, reconnect=reconnect) File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\client.py", line 857, in start await self.login(token) File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\client.py", line 698, in login data = await state.http.static_login(token.strip()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\http.py", line 991, in static_login await self.startup() File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\http.py", line 562, in startup self.super_properties, self.encoded_superproperties = sp, = await utils._get_info(session) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\utils.py", line 1446, in _get_info bn = await _get_build_number(session) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\utils.py", line 1474, in _get_build_number build_url = 'https://discord.com/assets/' + re.compile(r'assets/+([a-z0-9]+).js').findall(login_page)[-2] + '.js'


IndexError: list index out of range

D:\discord-mutual-friends-and-servers-main>

--------

Any idea to why this happens? I have put in the token in the .env file, like so TOKEN="DDDDDDDDDDDDDDDDDDDDDDDDDDD".
ChinemeremChigbo commented 2 months ago

Hey @Ishiroo thanks for pointing this out! This is a problem with the current upstream dependency discord.py-self. The fix for your issue is here: https://github.com/dolfies/discord.py-self/issues/619

image

I have made this fix in our repo with this commit: https://github.com/ChinemeremChigbo/discord-mutual-friends-and-servers/commit/5e591db1e43bb7aca34bfa15a57b61a738df59ff

If you pull the latest version of this repo the problem should be fixed. If not, please let me know!

Ishiroo commented 2 months ago

Thank you for the response! I changed and downloaded the requirements.txt, but I am not sure what to do with the screenshot.

I am getting this message: "C:\Users\ishir\OneDrive\Desktop\discord-mutual-friends-and-servers-main>python main.py [2024-04-17 23:33:07] [INFO ] discord.client: Logging in using static token. INFO:discord.client:Logging in using static token. [2024-04-17 23:33:12] [INFO ] discord.utils: Info API temporarily down. Falling back to manual retrieval... INFO:discord.utils:Info API temporarily down. Falling back to manual retrieval... [2024-04-17 23:33:12] [CRITICAL] discord.utils: Could not retrieve client build number. Falling back to hardcoded value... CRITICAL:discord.utils:Could not retrieve client build number. Falling back to hardcoded value... [2024-04-17 23:33:12] [INFO ] discord.http: Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36, build number 9999. INFO:discord.http:Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36, build number 9999. [2024-04-17 23:33:15] [INFO ] discord.gateway: Connected to Gateway (Session ID: 681c9d83e91bea612a7f2544cb55af3a). INFO:discord.gateway:Connected to Gateway (Session ID: 681c9d83e91bea612a7f2544cb55af3a). [2024-04-17 23:33:19] [ERROR ] discord.client: Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\client.py", line 637, in _run_event await coro(*args, *kwargs) File "C:\Users\ishir\OneDrive\Desktop\discord-mutual-friends-and-servers-main\main.py", line 42, in on_ready server_info = await self.get_server_info( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\OneDrive\Desktop\discord-mutual-friends-and-servers-main\main.py", line 217, in get_server_info fetch_server_members = set(await server.fetch_members()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\guild.py", line 4973, in fetch_members members = await state.scrape_guild(self, cache=cache, force_scraping=force_scraping, delay=delay, channels=channels) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\state.py", line 2922, in scrape_guild raise ClientException('Failed to automatically choose channels; please specify them manually') discord.errors.ClientException: Failed to automatically choose channels; please specify them manually ERROR:discord.client:Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\client.py", line 637, in _run_event await coro(args, **kwargs) File "C:\Users\ishir\OneDrive\Desktop\discord-mutual-friends-and-servers-main\main.py", line 42, in on_ready server_info = await self.get_server_info( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\OneDrive\Desktop\discord-mutual-friends-and-servers-main\main.py", line 217, in get_server_info fetch_server_members = set(await server.fetch_members()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\guild.py", line 4973, in fetch_members members = await state.scrape_guild(self, cache=cache, force_scraping=force_scraping, delay=delay, channels=channels) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ishir\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\state.py", line 2922, in scrape_guild raise ClientException('Failed to automatically choose channels; please specify them manually') discord.errors.ClientException: Failed to automatically choose channels; please specify them manually"

It could be that I did something wrong, I haven't changed the main.py code.

This is how my folder looks. image

ChinemeremChigbo commented 2 months ago

Hey again @Ishiroo I appreciate you following up. The error you're receiving is because the dependency discord.py-self is trying to find a Discord channel from which to scrape members but is not succeeding.

Context:

Currently we use 2 methods to get server members and combine their results to try and maximize the number of server members found:

https://github.com/ChinemeremChigbo/discord-mutual-friends-and-servers/blob/a217e0fe992d1b7b3c8e327893f935d09af05e35/main.py#L223-L229

The first method tries to scrape members directly from the Discord member sidebar. The members in the sidebar change depending on which channel you're in, so the discord.py-self tries (but does not succeed) in finding a channel to scrape the server members from.

Solution:

To deal with this I have added code to detect if the first method has failed and rely on the members found by the second method: https://github.com/ChinemeremChigbo/discord-mutual-friends-and-servers/commit/4b4b228a9a021400b2f568a8a800f07cc887d20c

Please pull the latest version of this repo and let me know if that fixes the issue you're having.

ChinemeremChigbo commented 1 month ago

Hey again @Ishiroo I appreciate you following up. The error you're receiving is because the dependency discord.py-self is trying to find a Discord channel from which to scrape members but is not succeeding.

Context:

Currently we use 2 methods to get server members and combine their results to try and maximize the number of server members found:

https://github.com/ChinemeremChigbo/discord-mutual-friends-and-servers/blob/a217e0fe992d1b7b3c8e327893f935d09af05e35/main.py#L223-L229

The first method tries to scrape members directly from the Discord member sidebar. The members in the sidebar change depending on which channel you're in, so the discord.py-self tries (but does not succeed) in finding a channel to scrape the server members from.

Solution:

To deal with this I have added code to detect if the first method has failed and rely on the members found by the second method: 4b4b228

Please pull the latest version of this repo and let me know if that fixes the issue you're having.

Originally, your error included the following line:discord.errors.ClientException: Failed to automatically choose channels; please specify them manually. We now added the ability to specify channels manually in this commit: https://github.com/ChinemeremChigbo/discord-mutual-friends-and-servers/commit/87e1b748c0dbe4620365e9243ba9eb8ef0d3c02d . You can specify channels using the -cflag like python3 main.py --include_channels 'general' 'help'. Please let me know if that fixes your issues!