dolfies / discord.py-self

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

RuntimeError: Event loop is closed #641

Closed dropalways closed 1 month ago

dropalways commented 6 months ago

Summary

trying to run the example code and it crashes

Reproduction Steps

ran that code

Code

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print(f'Logged on as {self.user}!')

    async def on_message(self, message):
        print(f'Message from {message.author}: {message.content}')

client = MyClient()
client.run('')

Expected Results

the expected result is it suppoed to relay every message

Actual Results

closes

[2024-01-01 14:20:03] [INFO ] discord.client: Logging in using static token. [2024-01-01 14:20:21] [WARNING ] discord.utils: Info API down. Falling back to manual fetching... Traceback (most recent call last): File "c:\Users\higgi\Desktop\projects\always-sb\main.py", line 11, in client.run('') File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 938, in run asyncio.run(runner()) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\runners.py", line 43, in run return loop.run_until_complete(main) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 608, in run_until_complete return future.result() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 927, in runner await self.start(token, reconnect=reconnect) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 857, in start await self.login(token) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 698, in login data = await state.http.static_login(token.strip()) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 991, in static_login await self.startup() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\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\higgi\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\utils.py", line 1446, in _get_info bn = await _get_build_number(session) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\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 Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B3C5F1F310> Traceback (most recent call last): File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon self._check_closed() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B3C5F1F310> Traceback (most recent call last): File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon self._check_closed() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B3C5F1F310> Traceback (most recent call last): File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon self._check_closed() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B3C5F1F310> Traceback (most recent call last): File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon self._check_closed() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B3C5F1F310> Traceback (most recent call last): File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in del self.close() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon self._check_closed() File "C:\Users\higgi\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed

System Information

Checklist

Additional Information

No response

Scyye commented 6 months ago

+1

munishkhatri720 commented 6 months ago

+1

mike777z commented 6 months ago

+1

TutlaMC commented 5 months ago

+1

Wert112 commented 5 months ago

in discord/utils.py change fuction def _get_build_number to this one. Worked for me

async def _get_build_number(session: ClientSession) -> int: 
    default_build_number = 9999
    try:
        login_page_request = await session.get('https://discord.com/login', timeout=7)
        login_page = await login_page_request.text()
        build_url = 'https://discord.com/assets/' + re.compile(r'assets/+([a-z0-9.]+).js').findall(login_page)[-2] + '.js'
        build_request = await session.get(build_url, timeout=7)
        build_file = await build_request.text()
        build_find = re.findall(r'Build Number:\D+"(\d+)"', build_file)
        return int(build_find[0]) if build_find else default_build_number
    except asyncio.TimeoutError:
        _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
        return default_build_number
xi-vii commented 5 months ago

in discord/utils.py change fuction def _get_build_number to this one. Worked for me

async def _get_build_number(session: ClientSession) -> int: 
    default_build_number = 9999
    try:
        login_page_request = await session.get('https://discord.com/login', timeout=7)
        login_page = await login_page_request.text()
        build_url = 'https://discord.com/assets/' + re.compile(r'assets/+([a-z0-9.]+).js').findall(login_page)[-2] + '.js'
        build_request = await session.get(build_url, timeout=7)
        build_file = await build_request.text()
        build_find = re.findall(r'Build Number:\D+"(\d+)"', build_file)
        return int(build_find[0]) if build_find else default_build_number
    except asyncio.TimeoutError:
        _log.critical('Could not fetch client build number. Falling back to hardcoded value...')
        return default_build_number

For me it worked too. Thank you @Wert112

dolfies commented 1 month ago

Fixed the fallback! The API is back up too. Sorry for the wait guys.