Discord.py: Can't close discord connection

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

Summary

Thank you everyone for releasing discord.py version 1.4 (final), you are amazing. However, with this new version, I am enable to close the discord connection with my bot. Here is a minimal reproducible example:

File: main.py

import discord, asyncio
from discord.ext import commands

bot = commands.Bot("!")

if __name__ == "__main__":
    bot.load_extension("cogs.owner")
    bot.run(TOKEN)

File: cogs/owner.py

import discord, asyncio
from discord.ext import commands

class Owner(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    @commands.is_owner()
    async def shutdown(self, ctx):
        await self.bot.close()

def setup(bot):
    bot.add_cog(Owner(bot))

Now when I run the shutdown command, the whole program just freezes (it doesn't terminate) and the fans on my computer start to spin faster. The bot still appears online but is not responding. This is weird, as everything worked alright before the update.

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.
bug

Most helpful comment

@Gobot1234 I have used it in DEBUG mode (using my discord.log file), and I found something very weird. After executing the command, I found this line: :DEBUG:discord.gateway: Received WSMessage(type=<WSMsgType.CLOSING: 256>, data=None, extra=None). Then, it was followed by the line: :DEBUG:discord.gateway: Received WSMessage(type=<WSMsgType.CLOSED: 257>, data=None, extra=None) being repeated over 7,000 times.

All 5 comments

I think it might be beneficial if you could get the logs for this. (make sure to remove any identifiable info)
https://discordpy.readthedocs.io/en/latest/logging.html

@Gobot1234 I have used it in DEBUG mode (using my discord.log file), and I found something very weird. After executing the command, I found this line: :DEBUG:discord.gateway: Received WSMessage(type=<WSMsgType.CLOSING: 256>, data=None, extra=None). Then, it was followed by the line: :DEBUG:discord.gateway: Received WSMessage(type=<WSMsgType.CLOSED: 257>, data=None, extra=None) being repeated over 7,000 times.

I couldn't reproduce this locally but I believe that https://github.com/Rapptz/discord.py/commit/5dd8e372e4a5aa3749d85f8fd2f7eb4d779512cb should fix it.

git clone https://github.com/Rapptz/discord.py
cd discord.py
python3 -m pip install -U .[voice]

If the program terminates then that's the extent of what I can do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nicba1010 picture Nicba1010  路  3Comments

reuscam picture reuscam  路  3Comments

Rimmy50 picture Rimmy50  路  3Comments

j0hnmeow picture j0hnmeow  路  3Comments

Be4Vision picture Be4Vision  路  3Comments