简体   繁体   中英

Why am I getting this instead of a string?

This is my code that works so far, as it adds a point and saves it as it should. However, when I try to make the bot say it says "[object Object]haha". How can I fix this? Code:

var davebal = 0;
bot.on('message', (msg) => {
 if (msg.content == '-readdata') {
  let rawdata = fs.readFileSync(msg.author + '.json');
  let student = JSON.parse(rawdata);
  msg.reply(student + 'haha');
  console.log(student);
 }

 if (msg.content == '-add') {
  if (msg.author == '349463140229971989') {
   davebal += 1;
   msg.reply('Az új számlád = ' + davebal);
  }
 }

 if (msg.content == '-savedata') {
  let balance = {
   balancefor: davebal,
  };

  let data = JSON.stringify(balance);
  fs.writeFileSync(msg.author + '.json', data);
 }
});

我相信这是因为 student 是一个对象,我建议从对象中获取一个属性,例如student.name或其他东西,而不仅仅是student

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM