Hi, for some reason I get this error when I stop my bot using bot.close(). I tried this on a clean bot too and it still persists. Using CTRL+C does not have this issue. Anyone have an idea what might cause this? Can you reproduce this? I'm on Python 3.12.4 and pycord 2.7.1.
bot = discord.Bot(intents=discord.Intents.all(), debug_guilds=[...])
@bot.command()
@discord.default_permissions(administrator=True)
async def stop(ctx: discord.ApplicationContext):
"""Stop the bot."""
await ctx.respond("Stopping the bot...", ephemeral=True)
await bot.close()
bot.run(os.getenv("BOT_TOKEN"))
Traceback (most recent call last):
File "...\main.py", line 27, in <module>
bot.run(os.getenv("BOT_TOKEN"))
File "...\discord\client.py", line 881, in run
return future.result()
^^^^^^^^^^^^^^^
File "...\discord\client.py", line 860, in runner
await self.start(*args, **kwargs)
File "...\discord\client.py", line 824, in start
await self.connect(reconnect=reconnect)
File "...\discord\client.py", line 713, in connect
self.ws = await asyncio.wait_for(coro, timeout=60.0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\asyncio\tasks.py", line 520, in wait_for
return await fut
^^^^^^^^^
File "...\discord\gateway.py", line 346, in from_client
gateway = gateway or await client.http.get_gateway()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\discord\http.py", line 3234, in get_gateway
data = await self.request(Route("GET", "/gateway"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\discord\http.py", line 299, in request
async with self.__session.request(
File "...\aiohttp\client.py", line 1510, in __aenter__
self._resp: _RetType = await self._coro
^^^^^^^^^^^^^^^^
File "...\aiohttp\client.py", line 529, in _request
raise RuntimeError("Session is closed")
RuntimeError: Session is closed