#MongoDB Issues (Urgent)
24 messages · Page 1 of 1 (latest)
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
wdym?
if (!user) return;
so this goes within the beg.js file right?
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!!!!!!
}
}
this should go in beg.js line 30. that code that you showed looks like its in another file which isnt where the error comes from
No. That's what I am trying to globally use to check if whatever commnad is a currency command, and if so a new user is created, so balance and bankbalance.
where is bankbalance?
beg.js only checks and updates the balance
which is also where the error comes from
bankbalance isn’t present there
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
yeah? so why are you talking about bankBalance then
balance and bank balance is created if the user doesn't have a balance nor bank balance
okay, but I don’t know what you’re confused about with my original suggestion
I assume if (!user) return; would go in every currency command file?
you should check if there’s data in your database before accessing schema properties
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?