When i run $restart in my discord server, it replies "restarting" but doesnt restart, it just prints $restart on my console (which is another script i have in my index.js to print commands) though the console doesnt close and re-open. it doesnt even close. Does this mean it has restarted or am i doing something wrong? Here is my index.js for that part:
else if (command === '$restart') {
return message.reply({
embeds: [
new MessageEmbed()
.setColor('GREEN')
.setDescription('Restarting')
]
})
.then(()=>client.destroy()) // <<<<
.then(()=>client.login('cooltokenhere')) // <<<<
}
})
client.login('cooltokenhere')
CodePudding user response:
I'd recommend to use pm2 for restarting your bot, to use it you need to install it first using npm i -g pm2
, and also you need to install child_process
module using npm i child_process
, after that you can restart your bot using this code:
const child = require('child_process')
child.exec("pm2 restart index", (err, res) => {
if(err) return console.log(err)
})
But please note you have to start your bot using pm2 start index.js
first!