The bot randomly crashes and gives out this error. I've programmed it to auto restart whenever something goes wrong, and log the error, as its technically meant to not shut down.
client.on("message", message => {
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "bal") {
if (message.author.bot) return;
const data = sql.prepare(`SELECT bal FROM ${args}`).get();
message.channel.send(`You have ${data.bal}`)
}
if (command == "give") {
if(message.member.roles.find(r => r.name === "Economy Manager") || message.member.roles.find(r => r.name === "Economy Manager ")){
//Get their current balance
const grab = sql.prepare(`SELECT bal FROM ${args[1]} WHERE rowid = 1;`).get();
//Grab the value from the first input after the second. Ex: eco tgive 5 Juliana
const pointsToAdd = parseInt(args[0]);
//Add the two values from the database and the args[0] input
const result = +grab.bal + +pointsToAdd;
//Replace the curret value from column bal in table ${args[1]}, with the ${result}
sql.prepare(`UPDATE ${args[1]} SET bal = ${result} WHERE rowid = 1;`).run();
message.channel.send(`You now have ${result}`)
//sql.prepare(`INSERT OR REPLACE INTO ${args[1]} (bal) VALUES (${result});)`).run();
}
}
if (command == "take") {
if(message.member.roles.find(r => r.name === "Economy Manager") || message.member.roles.find(r => r.name === "Economy Manager ")){
//Get their current balance
const grab = sql.prepare(`SELECT bal FROM ${args[1]} WHERE rowid = 1;`).get();
//Grab the value from the first input after the second. Ex: eco tgive 5 Juliana
const pointsToAdd = parseInt(args[0]);
//Add the two values from the database and the args[0] input
const result = +grab.bal - +pointsToAdd;
//Replace the curret value from column bal in table ${args[1]}, with the ${result}
sql.prepare(`UPDATE ${args[1]} SET bal = ${result} WHERE rowid = 1;`).run();
message.channel.send(`You now have ${result}`)
//sql.prepare(`INSERT OR REPLACE INTO ${args[1]} (bal) VALUES (${result});)`).run();
}
}
if(message.member.roles.find(r => r.name === "Economy Manager") || message.member.roles.find(r => r.name === "Economy Manager ")){
if (command == "delete") {
sql.prepare(`DROP TABLE IF EXISTS ${args}`).run();
message.channel.send(`Account ${args} has been deleted`);
}
}
});
The code used to auto restart is the following:
process.on('uncaughtException', (error, promise) => {
client.destroy()
console.log(error)
client.login(config.token);
});
process.on('uncaughtRejection', (error, promise) => {
console.log(error)
client.destroy()
client.login(config.token);
});
I also seem to be getting an "unhandled promise rejection"...