Skip to content

Adding a feature that will execute a function when the bot goes down via an error such as Keyboard Interruption? #5957

Answered by Rapptz
Sheppsu asked this question in Ideas
Discussion options

You must be logged in to vote

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()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants