zfbx / zdiscord

A Discord bot that runs in FiveM for the purpose of whitelisting, moderation and utilties using discord.js
Other
210 stars 79 forks source link

Clear Inventory if the player is offline #109

Open aymanos12345 opened 2 months ago

aymanos12345 commented 2 months ago

I added this to zdiscordAs\server\commands\qb-inventory.js :

const mysql = require('mysql2/promise');

// Database configuration
const dbConfig = {
    host: "", 
    user: "",           
    password: "",        
    database: "" 
};
module.exports = {
    name: "inventory",
    description: "Manage player's in-city items",
    role: "admin",

    options: [{
            type: "SUB_COMMAND",
            name: "wipeinventory",
            description: "Wipe a player's inventory by citizenid",
            options: [
                {
                    name: "citizenid",
                    description: "Player's citizenid",
                    required: true,
                    type: "STRING",
                },
            ],
        },
    ],
 run: async (client, interaction, args) => {
        const amount = args.count || 1;

        // ... (your existing code for 'give', 'take', 'inspect')

        else if (args.wipeinventory) {
            const citizenid = args.citizenid;

            try {
                const connection = await mysql.createConnection(dbConfig);

                const [result] = await connection.execute(
                    "UPDATE `players` SET `inventory` = '[]' WHERE `citizenid` = ?",
                    [citizenid]
                );

                if (result.affectedRows > 0) {
                    client.utils.log.info(`[${interaction.member.displayName}] wiped inventory of player with citizenid: ${citizenid}`);
                    interaction.reply({ content: `Inventory wiped for player with citizenid: ${citizenid} (offline/online)`, ephemeral: false });
                } else {
                    interaction.reply({ content: "No player found with that citizenid.", ephemeral: true });
                }

                await connection.end();

            } catch (error) {
                console.error("Error wiping inventory:", error);
                interaction.reply({ content: "An error occurred while wiping the inventory.", ephemeral: true });
            }
        }
    },
};

and i got this error :

Capture d’écran 2024-06-15 193132

i did yarn cache clean and script doesn't start

zfbx commented 2 months ago

Why did you clear the yarn cache? The change you mentioned shouldn't of had anything to do with the error you're getting

aymanos12345 commented 2 months ago

They told to Run 'yarn cache clan' to fix the problem on cfx i knew that was not right but i tried xD So is there something i can provide to help me with this problem

zfbx commented 2 months ago

you could try and delete the node_modules and yarn.installed file and restart the script to see if it pulls the modules again properly or you could just use this one that was generated a few years ago to fix some people's permissions issues on zap hosting https://cdn.discordapp.com/attachments/862934532110024734/967320705609904148/zdiscord_modules.zip?ex=66732c5c&is=6671dadc&hm=0b52da0d17ab8b6de0ebf1aacf45c88f4314296567b457794dcd589972a7221f&