Hello guys so I’m experiencing this problem with Discord bot making in JavaScript.
I’m following a tutorial from Fusion Terror.
The error I’m experiencing is that it’s saying handleCommands.js is not a function, it works for him but not for me.
Full error:
~@~: workspace/project_name$ node .
/home/username/workspace/project_name/src/bot.js:26
client.handleCommands();
^
TypeError: client.handleCommands is not a function
at Object <anonymous> (/home/username/workspace/project_name/src/bot.js:6:8)
at Module._compile (node:internal/modules/cjs/loader:1469:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
at Module.load (node:internal/modules/cjs/loader:1288:32)
at Module._load (node:internal/modules/cjs/loader:1104:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49
Node.js v20.17.0
All the files and folders:
file and folder organization
bot.js code:
require("dotenv").config();
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents:
(GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent),
});
const { token } = process.env;
const fs = require("fs");
client.commands = new Collection();
client.commandArary = [];
const functionFolders = fs.readdirSync(`./src/functions`);
for (const folder of functionFolders) {
const functionFiles = fs
.readdirSync(`./src/functions/${folder}`)
.filter((file) => file.endsWith(`.js`));
for (const file of functionFiles)
require(`./functions/${folder}/${file}`)(client);
}
client.handleEvents();
client.handleCommands();
client.login(token);
handleCommand.js code:
const fs = require("fs");
module.exports = (client) => {
client.commandHandler = async () => {
const commandsFolder = fs.readdirSync(`./src/commands`);
for (const folder of commandsFolder) {
const commandFiles = fs
.readdirSync(`./src/commands/${folder}`)
.filter((file) => file.endsWith(`.js`));
const { commands, commandsArray } = client;
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
commands.set(command.data.name, command);
commandsArray.push(command.data.toJSON());
console.log(
`Command ${command.data.name} has been regtistered through the command handler succesfully.`
);
}
}
};
};
Thanks in advance!
Well I tried re-writing the code which at the moment I thought would help, whilst it didn’t and the same error occured