I am extremely new to to JavaScript, so I decided to give myself a challenge by creating a discord bot. What I am trying to do is detect if the user has item called "Rod", if he does, the bot replies with "You already own this item!" Otherwise, the bot will let the user purchase the item. When I make it delete the "Temporary" in the array, it deletes the entire array, how do I fix this? If there's any way to fix this and "optimize" it better that'd be amazing.
This is a snippet of the code.
Variables are: const db = require('quick.db'); const { MessageEmbed } = require('discord.js');
db.push(message.author.id, "Temporary") //This is so the .includes() function could work.
let checkForItems = db.get(message.author.id)
console.log(checkForItems);
if(args[0] === "Rod"){
//See if the user has "Rod" in their inventory
let a1 = (checkForItems.includes('Rod'));
console.log(help);
if(a1 === false){
if (money.balance < 15000){
message.channel.send(`Insufficent Funds! You have ${money.balance} coins while the item you are trying to buy costs 15000 coins.`)
} else {
console.log("A User has purchased a Rod.")
let items = db.fetch(message.author.id, {items: [] } )
message.channel.send("You have bought 1 Rod.");
db.push(message.author.id, "Rod")
}
} else {
message.channel.send("You already have this item!")
}
}
db.delete(message.author.id, 'Temporary') //This is not working, how do I fix this? Its deleting the entire array.