#MongoDB Issues (Urgent)

24 messages · Page 1 of 1 (latest)

uncut siren

by the looks of your code, user is null from your db so I would have to assume that there’s no data for that specific user

you should make a check to see if that specific schema has data for the user you’re checking before accessing other properties from it

uncut siren

if (!user) return;

slim gulch
slim gulch
uncut siren `if (!user) return;`

Shouldn't this be stopping the command from going through?

if (interaction.command && interaction.command.category === "Currency") {
    // Check if the user has a currency account
    if (!userfind) {
      // If not, reply with a message and return // and also creates an account
      const newUser = { _id: interaction.user.id, balance: 0, bankBalance: 0 };
      await users.insertOne(newUser);
      await interaction.reply("Oops! Looks like you don't have an account with us! One has been created!");
      return; // THIS HERE!!!!!!
    }
  }
uncut siren
slim gulch
uncut siren

where is bankbalance?

beg.js only checks and updates the balance

which is also where the error comes from

bankbalance isn’t present there

slim gulch

what you talking about?

the beg.js file has nothing to do with bankBalance

there is 2 different types of balances

there is a Balance

and a Bank

uncut siren

yeah? so why are you talking about bankBalance then

slim gulch

balance and bank balance is created if the user doesn't have a balance nor bank balance

uncut siren

okay, but I don’t know what you’re confused about with my original suggestion

slim gulch

I assume if (!user) return; would go in every currency command file?

uncut siren

you should check if there’s data in your database before accessing schema properties

slim gulch

so that this would be executed:

if (interaction.command && interaction.command.category === "Currency") {
// Check if the user has a currency account
if (!userfind) {
// If not, reply with a message and return // and also creates an account
const newUser = { _id: interaction.user.id, balance: 0, bankBalance: 0 };
await users.insertOne(newUser);
await interaction.reply("Oops! Looks like you don't have an account with us! One has been created!");
return; // THIS HERE!!!!!!
}
}

correct?