Warning: Property commands is not defined in type module:"discord.js".Client

Viewed 101

My code works but I get this warning, is there a better practice to define the property commands for the Discord.js client?

Warning: Property commands is not defined in type module:"discord.js".Client   
const Discord = require('discord.js');

const client = new Discord.Client();
const Enmap = require("enmap");
client.commands = new Enmap();

const init = async () => {
    fs.readdir("./commands/",(err,files) =>{
        if (err) return console.error(err);
        files.forEach(file => {
            if (!file.endsWith(".js")) return;
            const command = require(`./commands/${file}`);
            let commandName = file.split(".")[0];
            console.log(`Attempting to load command ${commandName}`);
            client.commands.set(commandName,command)
        });
    });
};
1 Answers

You can't define the commands property. You can find client in the documentation here: client. The code works because you set client.commands to an Enmap, but without that, client.commands would crash the code.

Related