const fs = require("fs");
module.exports = (client) => {
fs.readdir("./events/", (err, files) => {
let jsfiles = files.filter(f => f.split(".").pop() === "js");
console.log(`${jsfiles.length} events loaded!`);
jsfiles.forEach((f, i) => {
require(`./events/${f}`);
});
});
fs.readdir('./commands/', (err, file) => {
let jsfile = file.filter(f => f.split('.').pop() === 'js');
console.log(`${jsfile.length} commands loaded!`);
jsfile.forEach((f, i) => {
let pull = require(`./commands/${f}`);
console.log(pull)
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
client.aliases.set(alias, pull.config.name);
});
});
});
};```
#All events working, commands not working
1 messages · Page 1 of 1 (latest)
Handler file ^^
Any of my command files do not even manage to console log
All of my event files are able to call
this is not discordjs related but i can provide support on this
in future reference, you can direct to #useful-servers
It's not? but its using DJS?
but oke ty
not really. its a filesync read issue. client is not erroring here
something like
fs.readdir('./commands/', (err, files) => {
if (err) return console.error;
console.log(`${files.length} commands loaded!`);
files.forEach(file => {
if (!file.endsWith('.js')) return;
let pull = require(`./commands/${file}`);
console.log(pull)
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
client.aliases.set(alias, pull.config.name);
});
});```
you can check if the file is a javascript file with (!file.endsWith('.js'))
Oh true true
Unfortunately, the commands still aren't working
you should not be doing alias handling inside the filesync, but rather check for alias in the command handler properly
Would that have an effect tho?
The problem is
my friend tried to make a new command
it's just easier to not have it there lol
in the command file
it didn't work so he deleted it
then all of the commands don't work
https://github.com/Kaisarion/AverageMod/blob/main/bot.js
Event & command handling
and something in the config changed
So I thought it might be something to do with the token so I regenerated that
are you using slash commands?
ok lemme grab another file
Tysm
module.exports = client => {
readdirSync("./commands/").forEach(dir => {
const commands = readdirSync(`./commands/${dir}/`).filter(file =>
file.endsWith(".js")
);
for (let file of commands) {
let pull = require(`../commands/${dir}/${file}`);
// Check if it has a name first to make sure it exists
if (pull.name) {
client.commands.set(pull.name, pull);
if (pull.aliases && Array.isArray(pull.aliases))
pull.aliases.forEach(alias => client.aliases.set(alias, pull.name));
}
});
Replace mine with urs?
... Problem still exists 😦
updated handler file ```js
const fs = require("fs");
const client = require('./sweats-united.js')
module.exports = (client) => {
const events = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
for (const file of events) {
const eventName = file.split(".")[0];
const event = require(./events/${file});
client.on(eventName, event.bind(null, client));
}
const commands = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
for (const file of commands) {
const commandName = file.split(".")[0];
const command = require(./commands/${file});
console.log(Attempting to load command ${commandName});
client.commands.set(command.name, command);
}}```