【发布时间】:2021-12-03 20:35:18
【问题描述】:
我对 JavaScript 非常陌生,所以我决定通过创建一个不和谐机器人来挑战自己。我想要做的是检测用户是否有名为“Rod”的项目,如果有,机器人会回复“你已经拥有这个项目!”否则,机器人将让用户购买该物品。当我让它删除数组中的“临时”时,它会删除整个数组,我该如何解决这个问题?如果有任何方法可以解决这个问题并“优化”它,那就太棒了。
这是一个sn-p的代码。
变量是: 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.
【问题讨论】:
-
db的定义是什么?请也显示该代码
标签: javascript discord.js quick.db