Is there a Function that runs before the bot gets closed

Is there a Function that runs before the bot gets closed

Ex.

@bot.event()
async def on_close(ctx):
    export_files()

I’m making a bot that reads all the new messages and adds them to the author’s list of words and when the command .get_word_count gets called all of the words that the author has sent will be shown

im: 98
under: 1
the: 1
water: 1
please: 1
help: 1
me: 1
test: 124136624745687697698608

the reason I’m storing the data is that it’s more efficient to store and start a new read rather than going through all of the channels and get the word counts

Answer

The on_disconnect event. However, do note that it might trigger when no connection was already established, if establishing one fails.

Hoewever I haven’t really understood what your use case is and what you need on_disconnect for. There might be a better way.