I am making a bot with discord.js and my restart command is not working. By not working I mean, I get this error:
(node:41784) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_timeouts' of undefined
My code is:
const config = require('../../config.json'); module.exports.run = async (bot, message, args) => { if(!config.owners.includes(message.author.id)) { return message.channel.send(`Only the bot owner can execute this command`) } message.channel.send(`Okay, I'll restart...`) .then( bot.destroy ).then( bot.login(config.token) ) }; module.exports.help = { name: "restart", description: "Restarts the bot", usage: "restart", category: "dev" };
If you can, please help
Advertisement
Answer
Try this:
const config = require('../../config.json'); module.exports.run = async (bot, message, args) => { if(!config.owners.includes(message.author.id)) { return message.channel.send(`Only the bot owner can execute this command`) } message.channel.send(`Okay, I'll restart...`) .then(()=>bot.destroy()) // <<<< .then(()=>bot.login(config.token)) // <<<< }; module.exports.help = { name: "restart", description: "Restarts the bot", usage: "restart", category: "dev" };
.then()
takes a function as argument, so you have to wrap the actions into a function.