1

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.

1
  • why do you tag this as Java? Commented Jun 5, 2018 at 12:48

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I must've accidentally down-voted this comment... but it's been a month now and I can't un-down-vote it...
@Tigerrrrr Try again. It might be possible after it got edited....
@Yunnosch Yeah, seems like it worked, I un downvoted 👍
1

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 :)

Comments

1

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.

Comments

-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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.