Discord.py: [Commands] Bot.logout() throws an exception

Created on 11 Aug 2020  路  6Comments  路  Source: Rapptz/discord.py

Summary

While I was reporting another bug, I saw that 1.4 was released, thanks for that.

I simply trying to shut down the bot via command after updating form 1.3.4 to 1.4.1 but an error occurs.

Note: However, it is not clear to me why I cannot find the exact position while debugging and the programm is terminating unfinished.

Reproduction Steps

import logging
from discord.ext.commands import Bot
from discord.ext.commands import Context

logging.basicConfig(level=logging.INFO)

if __name__ == '__main__':
    b = Bot('!')

    @b.command()
    async def quit(ctx: Context):
        await ctx.send('Bye.')
        await ctx.bot.logout()
        return

    b.run(<Token>)

Expected Results

A normal shutdown of the bot and that it is immediately offline in discord.

Actual Results

INFO:discord.gateway:Websocket closed with 1000, cannot reconnect.
INFO:discord.client:Cleaning up tasks.
INFO:discord.client:Closing the event loop.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000019AB4C88310>
Traceback (most recent call last):
  File "<Path>\Anaconda3\envs\env\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "<Path>\Anaconda3\envs\env\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "<Path>\Anaconda3\envs\env\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "<Path>\Anaconda3\envs\env\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Checklist

  • [x] I have searched the open issues for duplicates.
  • [x] I have shown the entire traceback, if possible.
  • [x] I have removed my token from display, if visible.

System Information

discord.py-1.4.1
python-3.8.3
aiohttp-3.6.2
Windows10

Most helpful comment

Sorry that issue is not relevant is this case, this is actually an Anaconda bug where anaconda wants the main thread and can't have it and so the event loop breaks.

This has been an issue for quite some time, though I can only however find stackoverflow posts relating to Jupyter Notebooks with this issue.

All 6 comments

Duplicate of #5209.

Thx, I missed it, since it is closed

Sorry that issue is not relevant is this case, this is actually an Anaconda bug where anaconda wants the main thread and can't have it and so the event loop breaks.

This has been an issue for quite some time, though I can only however find stackoverflow posts relating to Jupyter Notebooks with this issue.

No Problem. Should this issue be closed?

Anaconda and Jupyter both use the ipython kernel, which as of version 7 has its own intrinsic asyncio event loop support. The problem is that the run() method in discord.py handles the creation and teardown of the event loop for you, assuming you are using the standard python interpreter. There ARE ways to configure ipython to work around this, as well as not using bot.run() in discord.py, but the easiest one is to just run your bot with said standard python interpreter.

I would say, yeah, this should probably be closed as on the discord.py side, it's intended behavior.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Spyder-exe picture Spyder-exe  路  3Comments

TunaHobby picture TunaHobby  路  3Comments

synbitz picture synbitz  路  3Comments

danshat picture danshat  路  3Comments

ghost picture ghost  路  3Comments