Skip to content

Extension Reload #98

Description

@PenguinBoi12

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()
async def reload(ctx, name: str):
    bot.reload_extension(name)
    await ctx.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions