Ext-Creators/discord-ext-ipc

Server start no running event loop in d.py 2.0

InterStella0 opened this issue · 2 comments

Description

It seems like in discord.py 2.0, ever since Client.dispatch uses asyncio.create_task, we can't really start the server before the bot is running.

Actual Behavior

Traceback (most recent call last):
  File "C:\Users\sarah\PycharmProjects\bot_manager\main.py", line 14, in <module>
    bot.server.start()
  File "C:\Users\sarah\PycharmProjects\bot_manager\venv\lib\site-packages\discord\ext\ipc\server.py", line 253, in start
    self.bot.dispatch("ipc_ready")
  File "C:\Users\sarah\PycharmProjects\bot_manager\venv\lib\site-packages\discord\ext\commands\bot.py", line 132, in dispatch
    super().dispatch(event_name, *args, **kwargs)
  File "C:\Users\sarah\PycharmProjects\bot_manager\venv\lib\site-packages\discord\client.py", line 383, in dispatch
    self._schedule_event(coro, method, *args, **kwargs)
  File "C:\Users\sarah\PycharmProjects\bot_manager\venv\lib\site-packages\discord\client.py", line 343, in _schedule_event
    return asyncio.create_task(wrapped, name=f'discord.py: {event_name}')
  File "C:\Users\sarah\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 360, in create_task
    loop = events.get_running_loop()
RuntimeError: no running event loop
sys:1: RuntimeWarning: coroutine 'Client._run_event' was never awaited

Expected Behavior

I was expecting the bot to run normally as it is in 1.7.3.

Reproduction Steps

from discord.ext import commands, ipc


class SBot(commands.Bot):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.server = ipc.Server(self, secret_key="my_secret_key")

    async def on_ipc_ready(self):
        print("Ipc is ready")


bot = SBot("bot ")
bot.server.start()
bot.run("...")

Workaround

I'm able to fix it by not using on_ipc_ready event as of now.

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.
lgaan commented

Thanks for bringing this to my attention!

I plan on updating a few library features (this included) at some point. Note this isn't high priority since dpy2.0 is still in its beta testing period.

I'll leave this open as a reference for myself.

This issue has been marked as stale due to its inactivity and will be closed in 14 days.

If you believe the issue should remain open, remove the A:stale label or add a comment.
If you believe the issue will continue to be inactive but should remain open, add the A:backlog label.