Ext-Creators/discord-ext-ipc

'loop' not defined

dank-tagg opened this issue · 1 comments

Description

I started my bot for the first time with ipc.server. It errored because 'bot' object has no attribute 'loop'
This error happened in server.py.
Also, this may be the cause of my bot subclass... but I'm not totally sure.
See additional information for my bot subclass. Also, I didn't find any bot.loop in the discord.py documentation

Actual Behavior

Traceback (most recent call last):
  File "c:\Users\natalie\Groot\main\launcher.py", line 33, in <module>
    bot = GrootBot(**bot_data)
  File "c:\Users\natalie\Groot\main\bot.py", 
line 38, in __init__
    self.ipc = ipc.Server(self, secret_key="akey")
  File "C:\Users\natalie\Python39\lib\site-packages\discord\ext\ipc\server.py", line 68, in __init__
    self.loop = bot.loop
AttributeError: 'GrootBot' object has no attribute 'loop'
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x00000247DC4A44C0>

Expected Behavior

Expected the bot to run smoothly.

Reproduction Steps

Additional Context

# deleted unrelevant imports
from discord.ext import commands, ipc, tasks

class GrootBot(commands.Bot):
    def __init__(self, **kwargs):
        #deleted unrelevant things
        self.ipc = ipc.Server(self, secret_key="GrootBotAdmin")
        
        super().__init__(self.get_prefix, **kwargs)

    #deleted code
    def starter(self):
        """Starts the bot properly"""
        try:
            loop = asyncio.get_event_loop()
            db = loop.run_until_complete(aiosqlite.connect(f"{self.cwd}/data/main.sqlite3"))

        except Exception as e:
            print_exception("Could not connect to database:", e)

        else:
            self.launch_time = datetime.datetime.utcnow()
            self.db = db
            self.loop.run_until_complete(self.after_db())
            self.ipc.start()
            self.run(self.token)
    


    # Events
    async def on_ready(self):
        logging.warning(f"Logged in as {self.user}, SQLite3 database initialized.")
        print(f"CHECK: Bot ready 1/2")
    
    async def on_ipc_ready(self):
        logging.warning(f"IPC is ready to go!")
        print("CHECK: IPC ready 2/2")

    async def on_ipc_error(self, endpoint, error):
        logging.warning(f"{endpoint} raised {error}")```

Checklist

  • I have searched open issues for duplicates.
  • I have shown the entire traceback, if applicable.
  • I have removed any access tokens from display, if applicable.

System Information

Windows 10

lgaan commented

commands.Bot doesn’t have a loop until it’s __init__ has been called. You need to init the superclass before creating the server.