This is my index.js:
//requirements and stuff above...
const client.commands = new Discord.Collection;
const commandDirectory = "./commands";
let modulesCounter = 0;
function recursiveLoadModules(commandDir) {
fs.readdirSync(commandDir).forEach(file => {
const fullPath = "./" + path.join(commandDir, file);
if (file === "deps.js") return;
if (fs.lstatSync(fullPath).isDirectory()) {
recursiveLoadModules(fullPath);
} else if (file.endsWith(".js")) {
const command = require(fullPath);
modulesCounter++;
commandList.push({
name: command.name,
description: command.description || "none",
aliases: command.aliases || "none",
args: command.args || false,
group: command.group || "unassigned",
guildOnly: command.guildOnly || false,
cooldown: command.cooldown || 0,
execute: command.execute,
});
client.commands.set(command.name, command);
client.commandAliases.set(command.aliases, command.name);
}
});
}
recursiveLoadModules(commandDirectory);
console.log("<Information>", "Loading command modules....");
console.log(" " + modulesCounter + " modules loaded.");
client.once("ready", () => {
const options = [
"Log standby...",
"Ready!",
"On standby.\nAn activity will be set if you start a command.",
"The log's ready.",
"Connection established.",
];
const ready = options[Math.floor(Math.random() * options.length)];
console.log(ready);
});
client.once("reconnecting", () => {
console.log("Reconnecting...");
});
client.once("disconnect", () => {
console.log("Connection lost.");
});
client.on("message", async message => {
const args = message.content.slice(prefix.length).split(/ +/);
const commandName = args.shift().toLowerCase();
**const Command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));**
//the rest of the code here....
}
The last line worked just fine at the beginning, but after a moment I saw this error:
//DeprecationWarning - Collection.find: Pass a function instead.
How can I fix this? Thanks.