我正在使用 quick.db 我想在每个项目之间留一点空间,因为如果用户购买了两个项目,这些项目会像“item1,item2”一样彼此相邻有没有办法在它们之间放置空间?
库存命令的代码
let hats = db.get(`${message.author.id}.userHats`)
if(hats === undefined) hats = "none"
let outfits = db.get(`${message.author.id}.userOutfits`)
if(outfits === undefined) outfits = "none"
let pets = db.get(`${message.author.id}.userPets`)
if(pets === undefined) pets = "none"
const embed = new Discord.MessageEmbed()
.setTitle(`${message.author.tag}\'s inventory`)
.addField(`Hats`, `${hats}` || "none")
.addField(`Outfits`, `${outfits}` || "none")
.addField(`Pets`, `${pets}` || "none")
.setTimestamp()
.setColor('#00ffff')
.setFooter(message.member.user.tag, message.author.avatarURL());
message.channel.send(embed)
我如何将项目推入“userHats”
db.push(`${message.author.id}.userHats`, args[1])
这args[1]
是项目名称
在 inv 命令中的项目之间放置空格是否需要不同的存储方式?
编辑:我将数据存储在 sqlite 文件中,如下所示:
{
balance: 2558,
bank: 1898,
skin: 'cyan',
userHats: [ 'plaguedoctor', 'egg' ]
}
我尝试使用.join()
并找到它并给出错误“TypeError:outfits.join is not a function”,因为“outfits”用户没有任何它,他有“帽子”删除“outfits”和“ pets" 使命令有效,因为他只有帽子,有没有办法让它忽略空的或未定义的?我试过if(outfits === undefined) outfits = "none"
了,但它似乎没有工作,并给出了相同的错误更新代码:
let hats = db.get(`${message.author.id}.userHats`)
if(hats === undefined) hats = "none"
let hats2 = hats.join(", ")
let outfits = db.get(`${message.author.id}.userOutfits`)
if(outfits === undefined) outfits = "none"
let outfits2 = outfits.join(", ")
let pets = db.get(`${message.author.id}.userPets`)
if(pets === undefined) pets = "none"
let pets2 = pets.join(", ")