0
votes

My goal is to separate my bot into modules, but unfortunately, I failed. I've been trying for a long time and I really need some help in achieving my goal.

This is my bot.js :

client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir('./commands/', (err, files) => {
  if (err) console.error(err);
  console.log(`${files.length} commands will load.`);
  files.forEach(f => {
    let props = require(`./commands/${f}`);
    console.log(`Loaded commands: ${props.help.name}.`);
    client.commands.set(props.help.name, props);
    props.conf.aliases.forEach(alias => {
      client.aliases.set(alias, props.help.name);
    });
  });
});

client.reload = command => {
  return new Promise((resolve, reject) => {
    try {
      delete require.cache[require.resolve(`./commands/${command}`)];
      let cmd = require(`./commands/${command}`);
      client.commands.delete(command);
      client.aliases.forEach((cmd, alias) => {
        if (cmd === command) client.aliases.delete(alias);
      });
      client.commands.set(command, cmd);
      cmd.conf.aliases.forEach(alias => {
        client.aliases.set(alias, cmd.help.name);
      });
      resolve();
    } catch (e) {
      reject(e);
    }
  });
};

client.load = command => {
  return new Promise((resolve, reject) => {
    try {
      let cmd = require(`./commands/${command}`);
      client.commands.set(command, cmd);
      cmd.conf.aliases.forEach(alias => {
        client.aliases.set(alias, cmd.help.name);
      });
      resolve();
    } catch (e) {
      reject(e);
    }
  });
};

client.unload = command => {
  return new Promise((resolve, reject) => {
    try {
      delete require.cache[require.resolve(`./commands/${command}`)];
      let cmd = require(`./commands/${command}`);
      client.commands.delete(command);
      client.aliases.forEach((cmd, alias) => {
        if (cmd === command) client.aliases.delete(alias);
      });
      resolve();
    } catch (e) {
      reject(e);
    }
  });
};

This is my commands/command1.js :

const Discord = require('discord.js');

exports.run = (client, message, args) => {

  msg.channel.send('hello')
}
};

exports.conf = {
  enabled: true,
  guildOnly: false,
  aliases: ['try'],
  permLevel: 0,
};

exports.help = {
  name: 'try',
  description: 'try',
  usage: 'try'
};

When I'm using the commands nothing happens and it says "1 command will load.".

"loaded command: try" in the console.

I get the same output every time I use the command.

1
Does this happen when you are initially setting the commands, or when you reload a command? - user13429955
yes, unfortunately it does. - blour
Which one? That does not answer my question - user13429955

1 Answers

0
votes

I've had this problem before, I don't know what causes it or how to fix it but I to have a "solution". Try changing the command name, For some reason that worked when I had this issue.