【问题标题】:Check if a user has a specific object with quick.db使用 quick.db 检查用户是否有特定对象
【发布时间】:2021-09-20 23:39:09
【问题描述】:

您好,我正在尝试检查某人的库存女巫 quick.db 中是否有对象 但是当我尝试时,无论艺术家是什么,它总是说这是用户的库存。这是我使用的代码。

const db = require('quick.db');
let discord = require('discord.js');

module.exports = {
    name : 'test',
    description : "commande test",
    async execute(message, args) {

        const artist = message.content.slice(7).trim();

        if(!artist){
            message.channel.send("Spécifier l'artiste")
        }



        if(db.has(message.author.id, artist)){
            message.channel.send("Artiste Present")
        }
        else{
            message.channel.send("Non présent")
        }


    }

}

我用它来向数据库添加信息

if (reaction.count == 2){
   db.push(user.id, name_artist);

【问题讨论】:

  • 根据 quick.db docssource code.has() 方法的第二个参数应该是对象而不是字符串。
  • 以及如何将我的字符串定义为对象
  • 您能否向我们提供您实际将这些添加到数据库中的代码。没有这个,我们就无法真正为您提供准确的解决方案。
  • 好的,我编辑了问题

标签: node.js discord.js quick.db


【解决方案1】:

问题是您只检查数据库是否具有特定的用户 ID 作为键。根据 quick.db docs.

要检查艺术家是否存储在数组中,我会试试这个。

if (db.get(message.author.id).includes(artist)) {
    message.channel.send("Artiste Present")
}
else {
    message.channel.send("Non présent")
}

【讨论】:

    猜你喜欢
    • 2021-01-02
    • 2021-09-27
    • 2012-05-22
    • 2017-06-23
    • 2010-12-22
    • 2019-06-16
    • 2013-05-11
    • 2021-10-10
    相关资源
    最近更新 更多