#Cast to Number failed for value "NaN" (type number) at path "cash"

17 messages · Page 1 of 1 (latest)

sonic ruinBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by staff
cobalt grail
#

cash is not a number, and since you seem to be getting it from your MongoDB database, you need to check what it actually is. At least that's how I understood your code.

#

Show the full error anyway

#

Log cash's value when you first retrieve it from the database

#

When you assign a value to targetData, log targetData.cash

#

Did you actually write this code?

#
let targetData;
      try {
        targetData = await profileModel.findOne({ userId: target.id });

After that, add console.log(targetData.cash);

#

Yes, because your error is a MongoDB error saying that cash is NaN

#

Add a console.log every time you access cash

#

Yes, every time you access targetData.cash

#

So for some reason past that it's undefined

#

And therefore when you try to perform operations with it past that it fails

#

The error says it fails at a comparison operator but unless I'm blind you're not comparing it anywhere

#

You declared robbedAmount inside the try block so it won't be accessible outside that

#

Oh yeah I didn't notice that 🤦‍♂️

#

Honestly I haven't worked with MongoDB before but findOneAndUpdate would suggest that it finds the document/value, updates it and returns the updated document/value

cobalt grail
#

You should just make the command send the trade offer privately (for instance in a DM) with a button to accept which is disabled after say, 5 minutes