(节点:5318)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“角色”

时间:2020-01-18 16:44:11

标签: node.js discord.js

机器人自动崩溃并发出此错误。我已将其编程为在出现问题时自动重新启动,并记录错误,因为从技术上讲,它不会关闭。

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`);
  }
}
  });

用于自动重启的代码如下:

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);
});

我似乎也收到了“未处理的承诺拒绝” ...

0 个答案:

没有答案