Hello there. I am working on a disord.js bot and I want a command that allows me to shut the bot down and have it automatically. If there was any change in code I would like it to update. I hovever cannot find a way to do this. I am ok downloading a new Node.js application if needed. If someone can find this what would a watch.json look like that doesn’t change at all.
Hey, WilsontheWolf
Here is the easiest way to do that:
process.exit(1);
My restart bot command:
if (message.content === 'restartthebot') {
if (message.author.id !== 'Owners ID') return;
message.channel.send('Restarted.').then(() => {
process.exit(1);
})
};
Thanks and cheers!
Thanks Trying it now
Is your project public? I’m interested in what you’re doing but have no context … would love to take a peek. If not public, no worries.
Thanks!
Patrick
wilsonmusictest is where I have put it in. I am making a discord music bot and sometimes it needs to reboot
That’s really interesting - a kind of use case I wasn’t aware I could handle on glitch (and didn’t know where you meant until I saw it in server.js). Thanks!
Bumb . This only shuts down the bot, doesn’t actually restart it.
You can use the refresh
command in the console to restart your project.
This Should Work:
const Discord = require(‘discord.js’);
const client = new Discord.Client();
const settings = {
token: ‘YOUR - TOKEN - HERE’,
prefix: ‘YOUR - PREFIX - HERE’,
};
client.on(‘message’, message => {
if (message.content === ${settings.prefix}restart
) {
const embed = new Discord.RichEmbed()
.setDescription(Restarted in: **${Math.floor(client.ping)}**ms
);
if (message.author.id !== ‘YOUR-ID-HERE’) {
const NotAllowedEmbed = new Discord.RichEmbed()
.setDescription(You Cannot Restart ${client.user.tag}!
);
message.channel.send(NotAllowedEmbed);
}
message.channel.send(embed)
.then(() => client.destroy())
.then(() => client.login(settings.token));
}
});
use:
.then(() => client.login(YOUR-TOKEN-HERE));
or see my other comment
this would destroy the client but not reload the code. if you have glitch process.exit shuts down the bot and glitch starts back up again. If you want this on a non-glitch bot use pm2