【问题标题】:How to check if Key inv_ has the value of Deer Quick.db如何检查 Key inv_ 是否具有 Deer Quick.db 的值
【发布时间】:2021-11-20 02:26:54
【问题描述】:

你好,我正在做一个不和谐的经济机器人,我现在做了一个狩猎命令我想知道如何检测密钥 inv_ 是否具有 deer 的值

为了打猎,我很好地使用了这段代码,到目前为止我只添加了 1 只动物 打猎

if(message.content === `${defaultprefix}hunt`){
  var animalHunt = [1 , 2 , 3 , 4 , 5]
  var animalHunted = animalHunt[Math.floor(Math.random()*animalHunt.length)];
  if(animalHunted === 1){
    db.push(message.author.id + 'inv_', 'Deer')
    message.channel.send("You were hunting and hunted a deer ????")
  }
}

使用 djs v12

【问题讨论】:

    标签: javascript discord.js quick.db


    【解决方案1】:

    您可以使用.get() 函数返回Array(因为您使用了.push(),所以<userID>.inv 上的数据将是一个数组),然后只需搜索其中是否有特定的动物,在你的情况你可以使用这个:

        let userinv = db.get(message.author.id + 'inv_')
        if(userinv.includes('Deer')) return message.channel.send('You do have a Deer ? !')
      else return message.channel.send("You don't") 
    

    如果您想从库存中删除鹿,您可以使用获取数组、更改它并重新设置它。

    // We get the array from the database.
    let userinv = db.get(message.author.id + 'inv_')
    // Remove all the "Deer"
    let newuserinv = userinv.filter(animals => animals !== "Deer")
    // And we set the array back to the database.
    db.set(message.author.id + 'inv_',newuserinv)
    

    【讨论】:

    • 我可以给你discord id,如果我有问题可以给你发消息
    • 现在我想做一个sell cmd 我做的事情现在想现在如何db.delete deer
    • 那行不通。
    • @vaijayantipethe 在这里我更改了答案以支持如何删除 Deer,如果它解决了您的问题,只需单击复选标记,因为它回答了您的问题并为您的新问题创建一个新问题!跨度>
    • .includes 不工作
    猜你喜欢
    • 1970-01-01
    • 2021-09-27
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    • 2023-02-07
    • 2016-07-16
    • 1970-01-01
    相关资源
    最近更新 更多