-
I went into the source code and tried doing this myself to find some nice results. I assume it would not work when something happens such as whatever's running the bot gets forcefully closed. However, it worked with KeyboardInterruption and I wonder if anyone else would find this useful in their bots. death_func = kwargs.pop('death', None)
async def runner():
try:
await self.start(*args, **kwargs)
finally:
if death_func is not None:
await death_func()
if not self.is_closed():
await self.close() The only changes are with the death_func variable, and the two lines that involve executing it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You don't need to modify any source to do this. Just use standard Python functions. Your best bet is to do this before the bot is closed, so something like this: from discord.ext import commands
class MyBot(commands.Bot):
async def my_finalizer(self):
# do whatever here
pass
async def close(self):
await self.my_finalizer()
await super().close() |
Beta Was this translation helpful? Give feedback.
You don't need to modify any source to do this. Just use standard Python functions. Your best bet is to do this before the bot is closed, so something like this: