node.jsdiscord.jsquick.db

Check if a user has a specific object with quick.db


Hello I am trying to check if someone has an object in his inventory witch quick.db But when I try, whatever the artist is it always says that it's the inventory of the user. Here's the code that I use.

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")
        }


    }

}

I use this to add information to the database

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

Solution

  • The problem is that you are only checking if the database has a specific user id as a key. According to the quick.db docs.

    To check if an artist is stored in an array I would try this.

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