xVice1337
xVice1337

Reputation: 7

Reload command discord.js

I'm making a discord bot with discord.js, but my reset command isn't working.

       //!reload
       if(command === `${botsettings.prefix}reload`) {
            console.clear();
               bot.destroy()
               bot.login(botsettings.token);
             message.channel.send("Reloaded");
         return;
        }

It doesn't give any error; it restarts and goes back on but the commands don't update!

I tried so many different things I found, but it doesn't work.

I only have one file for all commands.

Upvotes: 1

Views: 18872

Answers (4)

Typical
Typical

Reputation: 56

If you use a nodemon system and a local batch file it will automatically reload the file for every change saved in it, and will output the new file changes.
If you need more help on this, watch a few videos from TheSourceCode on YouTube and you'll see in around 3-4 episodes on him using nodemon.
If you end up hosting it on Heroku, which is frowned upon, but I do, it will automatically reload for every change in your GitHub repository, just make sure to replace your token with process.env.token and make sure you have it set on your Heroku.

Upvotes: 4

MrBackpackBoi
MrBackpackBoi

Reputation: 1

client.destroy();
client.login();

That's not possible since there's a dead socket.

Instead, you're able to make a Shell script and have a background Daemon service the needs that you want.

Upvotes: -1

MyNameIsVati
MyNameIsVati

Reputation: 23

In the code you provided, it seems like your only refreshing the const 'bot' instead of reloading the bot.js file.

I recommend that you use a batch file.

Upvotes: 1

callum siciliano
callum siciliano

Reputation: 89

So i am guessing you have your various files set out (config etc) and one central bot.js file, and you load the bot by using something like

node bot.js

on your host machine, and obviously part of your .js file sets up the bot something like this:

const bot = new Discord.Client();

From what I can tell, your

bot.destroy()

and

bot.login(botsettings.token);

is just refreshing the const 'bot', but what it is not doing is reloading your bot.js file (with the updated commands and code).

What you would need to do, is have it set up to run a batch file or something on your host machine that terminates the entire process bot.js, and then restarts it. As this would then use the new and updated bot.js file.

The only problem is I am still figuring out how to run a batch file from my JS file, as understandably for security that feature isn't built in (other wise most websites that use JS would be vunerable to getting it to run things like format C:\)

I imagine it will involve using WSH in my JS, and I will update here if I do get it going.

I hope this was clear? let me know if you still have a question :)

Upvotes: 1

Related Questions