#Hot reloading commands?
29 messages · Page 1 of 1 (latest)
What does a hot reload mean
In discord.py you could update commands without restarting your entire bot, like you could have your bot playing music while you are working on the bot itself.
basically recognizing the changes of a file and implementing the changes
@gritty cliff while the program is still running
it is possible
how
Unlike discord.py, discord.js does not provide a built-in command handler. You have to implement your own command handler that would do whatever you want it to do
as far as i remember, our guide does have an example command handler which you need in order to be able to reload a command. From there you need to implement file watching on your own (if you want the actual hot-reload, as hot-reload does not necessarily mean any reload)
Sapphire, the framework for discord.js does this along with many other features #useful-servers
where does it say that it does that?
plugin hmr
sure, but that's a very unintuitive name, and while it is mentioned in the docs if you know what to look for, it doesn't really say anything about what it is on the docs page for it
@sterile marlin you can use fs.watch and implement your own "hot reload"
just delete require cache before trying to load the cmd files again
that might be a bit expensive in the long run
which method
If you are using sapphire then you can just install the plugin, set it up and be done with it
I was referring to the methods they suggested, I wanted to know what would be expensive in the long run, and I am using vanilla d.js.
oh i was referring to the sapphire hmr readme documentation not having sufficient content, i worded it a bit shittly
@sterile marlin basically you use fs.watch to listen to file changes and when there is a change you delete the cache of that file and import it again.
This example uses a helper command handler function to make life easier
function hotReload(dir) {
if (typeof dir !== "string") throw new Error();
fs.watch(dir, () => {
delete require.cache[require.resolve(dir)]
commandHandler(dir)
})
}
alright thanks
fs.watch is pretty bad since it often fires same event twice
Does it?
How can i make this possible in docker?
exactly same way you would do it outside of docker