Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asyncio.run RuntimeError: Event loop is closed

import robloxapi, asyncio
client = robloxapi.Client(".ROBLOSECURITY Cookie Here") # Removed this for security reasons

async def main():
    user = await client.get_self()

    try:
        role = await user.get_role_in_group(1)
    except robloxapi.utils.errors.NotFound:
        role = None

    if role:    
        print(role.name)
    else:
        print("Not in group")

asyncio.run(main())

This code is raising RuntimeError: Event loop is closed and I don't have a clue why,

I have tried replacing asyncio.run with this

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()

but it gave me the same error

like image 262
Filip Avatar asked Jun 04 '26 13:06

Filip


1 Answers

On Windows do this:

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())
like image 66
j4hangir Avatar answered Jun 07 '26 02:06

j4hangir