I want to delete something in quick.db

106 views Asked by At

I was trying to make a discord bot using discord.js and as db i am using quick.db i want to delete a item but when i use my code it's deleting whole array but i want to delete a single thing

const db = quick.db

const emote = require("../../config/emotes.json");

const { MessageEmbed } = require("discord.js");

module.exports = {

    name: 'delete',

    run: async(client, message, args) => {

       db.delete(`item_${message.author.id}`, 'ThiefOutfit')

const embed = new MessageEmbed()

.setDescription("You deleted Thief Outfit")

message.channel.send(embed)

}

}
1

There are 1 answers

1
Mansur Dewan On

This is happening to you because you delete the key associated with whole array that's why

as per documentation There is a option to how you handle An array value. here is the code from documentation

await db.pull("myUser.items", "Health Potion"); // Returns -> { balance: 700, items: [ 'Sword', 'Shield', 'Armor' ] }```
Here another way to handle this:
 1. First you will get the array associated with key
 2. Then filter the array, and remove which one you no need
 3. Then again set new filtered array with the same key.
```let currentArray = await db.get("yourkey")  //[1, 2, 3]
const newArray = currentArray.filter((e) => e == 1)
await db.set("yourkey", newArray)```