147
rated 0 times
[
148]
[
1]
/ answers: 1 / hits: 67486
/ 6 Years ago, sat, february 3, 2018, 12:00:00
I'm making a bot in discord.js. How do I make a command that restarts the bot?
More From » node.js
I'm making a bot in discord.js. How do I make a command that restarts the bot?
You can reset a bot by using the client.destroy()
method, then calling .login
after again. Try something like this:
// set message listener
client.on('message', message => {
switch(message.content.toUpperCase()) {
case '?RESET':
resetBot(message.channel);
break;
// ... other commands
}
});
// Turn bot off (destroy), then turn it back on
function resetBot(channel) {
// send channel a message that you're resetting bot [optional]
channel.send('Resetting...')
.then(msg => client.destroy())
.then(() => client.login(<your bot token here>));
}
If you set a ready listener in your bot, you will see that the ready
event fires twice. I set up a ready listener like this:
client.on('ready', () => {
console.log('I am ready!');
});