#Hot reloading commands?

29 messages · Page 1 of 1 (latest)

sterile marlin
#

Is it possible to hot reload command files? In discord.py it is possible to hot reload them but I am not so sure with discord.js.

gritty cliff
#

What does a hot reload mean

sterile marlin
#

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

sterile marlin
sterile marlin
#

how

lean flax
#

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)

safe kernel
lean flax
#

where does it say that it does that?

last blaze
#

plugin hmr

safe kernel
lean flax
#

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

mental agate
#

@sterile marlin you can use fs.watch and implement your own "hot reload"

vital temple
#

just delete require cache before trying to load the cmd files again

safe kernel
#

that might be a bit expensive in the long run

sterile marlin
#

which method

safe kernel
sterile marlin
#

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.

safe kernel
mental agate
#

@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)
    })
}
sterile marlin
#

alright thanks

latent cobalt
#

fs.watch is pretty bad since it often fires same event twice

shell lance
#

How can i make this possible in docker?

lean flax
#

exactly same way you would do it outside of docker

shell lance
#

What about rebuilded image?

#

My bot is written in ts and then is compiled.