How do I get reference the items so I can delete them in a clearinventory command

694 Views Asked by At

I'm trying to make a clearinventory command so it deletes a players inventory via mention or if there is no mention it deletes your own inventory but I keep getting an error called RangeError: Too many parameter values were provided this is the code :

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

module.exports = {

  name: "clearinventory",

  descrition: "clear a players inventory",

  async run(client, message, run) {

    let target = message.mentions.users.first() || message.author;
    let items = await db.fetch(target.id, {
      items: []
    });

    if (!message.member.hasPermission("ADMINISTRATOR")) return message.channel.send('You can\'t use that!')

    db.delete(items);

    message.channel.send(`${target}\'s inventory was successfully cleared!`)

  }


}

I've tried to specify the items in the variable items and I also tried to specify items in the db.delete(items, 'car') but that didn't work

1

There are 1 best solutions below

0
On BEST ANSWER

I'm looking at this without any context on which line is causing the issue.

db.delete takes a string for the first parameter, this string being the key of the data you set (the target's user ID). In this case, you're passing items which is actually an object with the format { items: [/* items */] } and not a string. I assume you're trying to delete the items of a player's inventory, and in that case you can do either of the two:

  1. Delete the player's information entirely. You can do that by deleting that entry in the database. If you plan on adding more information to the same entry, I suggest going with the second option instead.
    // target.id is a string, so you can just use that here directly.
    db.delete(target.id);
  1. Clear the player's inventory (only) by setting items to an empty array. This takes advantage of quick.db's ability to use the dot notation.
    // <target.id>.items, e.g. 1234567890987543212.items
    db.set(`${target.id}.items`, []);