#All events working, commands not working

1 messages · Page 1 of 1 (latest)

kindred mauve
#
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);
            });
        });
    });
};```
#

Handler file ^^

#

Any of my command files do not even manage to console log

#

All of my event files are able to call

noble galleon
#

this is not discordjs related but i can provide support on this

kindred mauve
#

but oke ty

noble galleon
#

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'))

kindred mauve
noble galleon
kindred mauve
#

Would that have an effect tho?

#

The problem is

#

my friend tried to make a new command

noble galleon
kindred mauve
#

in the command file

#

it didn't work so he deleted it

#

then all of the commands don't work

noble galleon
kindred mauve
#

and something in the config changed

#

So I thought it might be something to do with the token so I regenerated that

noble galleon
#

are you using slash commands?

kindred mauve
#

Nope

#

Just normal prefixed commands

noble galleon
#

ok lemme grab another file

kindred mauve
#

Tysm

noble galleon
#
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));
      }
   });

kindred mauve
#

Replace mine with urs?

noble galleon
#

i mean give it a shot but that wont say {int} commands loaded

#

thatll just load em

kindred mauve
#

ah fair

#

For some reason it won't filter out other types of files

#

like .txt

kindred mauve
#

... 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);
}}```