0

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);
Cryopt
  • 29
  • 6
  • According to quick.db [docs](https://quickdb.js.org/overview/docs#has) and [source code](https://github.com/lorencerri/quick.db/blob/master/src/methods/has.js). The second argument of `.has()` method should be object instead of string. – Skulaurun Mrusal Jul 11 '21 at 13:30
  • and how can i define my string as an object – Cryopt Jul 11 '21 at 13:32
  • 1
    Could you provide us the code where you actually add these into the database. Without this we can't really provide you with an accurate solution. – Tyler2P Jul 11 '21 at 13:43

1 Answers1

1

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")
}
Skulaurun Mrusal
  • 2,792
  • 1
  • 15
  • 29