This plugin implements graceful shutdown for NoneBot2 (see nonebot/nonebot2#2479)
It waits for events to finish processing before shutdown
It also allows you to run some functions before shutdown, similar to on_shutdown
But with higher priority, ensuring execution before bot
disconnects
uv add nonebot-plugin-wait-a-minute
pdm add nonebot-plugin-wait-a-minute
poetry add nonebot-plugin-wait-a-minute
from nonebot import require, on_command
from nonebot.matcher import Matcher
require('nonebot_plugin_wait_a_minute') # require plugin
from nonebot_plugin_wait_a_minute import graceful, on_shutdown_before
# Graceful shutdown
@on_command('foo').handle()
@graceful() # 👈 Add graceful decorator below the handle decorator
# Or, you can use @graceful(block=True) to prevent new handles from running during shutdown wait
async def _(matcher: Matcher):
matcher.send('foo')
# Pre-shutdown hook
@on_shutdown_before
def _():
# Do something()
...
# Or use async
@on_shutdown_before
async def _():
# await Do something()
...
This project is open-sourced under the MIT license