Skip to content

Clear Inventory if the player is offline #109

@aymanos12345

Description

@aymanos12345

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions