You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once an extension is loaded there is no way to pick up code changes without restarting the entire bot. load_extension and unload_extension already exist in bot.py, but there is no reload_extension that does both atomically and re-imports the underlying Python module.
The idea is to add bot.reload_extension(name) which unloads the running extension, re-imports its module with importlib.reload, re-instantiates the extension, and loads it back in. This makes the development loop significantly tighter without requiring a full bot restart.
Proposed API
bot.reload_extension("moderation")
# Or trigger it from inside a command@bot.command()asyncdefreload(ctx, name: str):
bot.reload_extension(name)
awaitctx.reply(f"Reloaded {name}.")
The critical detail is that importlib.reload only re-executes the module, it does not re-create the extension object, so reload_extension must also instantiate a fresh Extension from the reloaded module before calling load_extension. This means the framework needs a way to locate the extension's module (the mapping from extension name to module path should be stored at load time). State held inside the old extension instance is lost on reload, which is expected behaviour but should be documented clearly.
Activity