
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
discord-ext-autoreload
Advanced tools
A discord.py extension that allows automatic hot-reloading of extensions
A discord.py extension that allows automatic hot-reloading of extensions
When it comes to bot development, reloading extensions at runtime is quite a common practice. However, currently there is no way of automatically hot reloading extensions. This simple extension allows you to conveniently auto-reload extensions.
The features of this extension are:
This extension can easily be installed using pip
:
pip install discord-ext-autoreload
The Reloader
class is used for setting up automatic reloads.
import discord
from discord.ext import commands, autoreload
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
reloader = autoreload.Reloader(ext_directory="cogs")
if __name__ == "__main__":
reloader.start(bot)
bot.run()
In discord.py 2.0 and higher, you would need to call the reloader.start()
method in an async context. The most convenient way of doing this is by
overriding the Bot.setup_hook()
method.
class Bot(commands.Bot):
async def setup_hook(self) -> None:
reloader.start(self)
And done! The Reloader
class will start watching the provided ext_directory
for
changes in loaded extensions and as soon as an extension is updated, It will automatically
be reloaded.
Sometimes, you might want to stop the reloader. You can use the Reloader.stop()
method
to easily do so. For example:
@bot.command()
async def togglereload(ctx):
if reloader.stopped:
reloader.start(bot)
await ctx.send("Enabled")
else:
reloader.stop()
await ctx.send("Disabled")
When auto reloading fails for some reason, the error is properly handled and propagated
to Reloader.on_error
. This function by default logs the error but can be overridden to
implement custom functionality.
import traceback
class Reloader(autoreload.Reloader):
async def on_error(self, extension: str):
print(f"Extension {extension!r} failed to auto reload")
traceback.print_exc()
When an extension is reloaded, the Reloader.on_reload
method is called. This method can
be implemented by a subclass to easily track successful automatic reloads.
Sometimes, you want certain extensions to not be subject of automatic reloading. Fortunately,
this package allows you to exclude certain extensions by passing the exclude_exts
keyword
argument in Reloader
class.
reloader = Reloader(ext_directory="cogs", exclude_exts=["cogs.some_extension"])
FAQs
A discord.py extension that allows automatic hot-reloading of extensions
We found that discord-ext-autoreload demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.