I have been trying to make a command handler with prefix, but I'm getting a problem, the bot won't respond and there is no error either
// Index
---// Collections
client.functions = new Collection();
client.commands = new Collection();
client.interactions = new Collection();
---// Handlers
const handlers = fs
.readdirSync("./config/handlers/")
.filter((file) => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./config/commands/");
const interactionFolders = fs.readdirSync("./config/interactions");
const eventFiles = fs
.readdirSync("./config/events/")
.filter((file) => file.endsWith(".js"));
(async () => {
for (file of handlers) {
require(`./config/handlers/${file}`)(client);
}
client.handleCommands(commandFolders);
client.handleInteractions(interactionFolders);
client.handleEvents(eventFiles);
client.login(token);
})();
// The event handler
module.exports = (client) => {
client.handleEvents = async (eventFiles) => {
for (const file of eventFiles) {
const event = require(`../events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
console.log(`[EVENT HANDLER] - ${file} has been loaded.`);
}
};
};
// command handler
const fs = require("fs");
module.exports = (client) => {
client.handleCommands = async (commandFolders) => {
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./config/commands/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
client.commands.set(command.name, command);
console.log(`[COMMANDS HANDLER] - ${file} has been loaded`);
}
}
};
};
// and in the last my messageCreate.js
const prefix = ".";
module.exports = {
name: "messageCreate",
async execute(message, client) {
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!message.user.id === "798928603201929306") return;
console.log(
`${message.user.tag} used ${command} in #${message.channel} triggered an command.`
);
if (
!message.content.startsWith(prefix) ||
message.author.bot ||
message.channel.type === "DM"
)
return;
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args, client);
} catch (error) {
console.error(error);
message.reply("there was an error trying to execute that command!");
}
},
};
// ping command
module.exports = {
name: "ping",
async execute(message, args, client) {
message.channel.send(`Pong ${client.ws.ping}`)
}
} // I haven't tried this yet because I'm getting an error in the messageCreate.js
notes:
1. sorry for the long code block
2. hope I inputted everything for getting enough help/info
3. my discord.js version is v13
4. if you need more info about my files, let me know in the comments