Error: Cannot find module './config.json' discord.js


#1

Hello, i was coding my 8ball command module but it don’t load. It gives me this error in the log:
Unable to load command 8ball.js: Error: Cannot find module './config.json'

Here is the code:

const Discord = require("discord.js");
const botconfig = require("./config.json");

function randomIntInc(low, high) {
  return Math.floor(Math.random() * (high - low + 1) + low);
}
module.exports.run = async (client, message, args) => {
  var rnd = randomIntInc(1, 5);
  if (rnd === 1) {
    const embed1 = new Discord.RichEmbed()
      .setDescription(':8ball: 8ball')
      .setColor('RANDOM')
      .addField(args.join(" "), 'Não')
    message.channel.send(embed1);
  } else if (rnd === 2) {
    const embed2 = new Discord.RichEmbed()
      .setDescription(':8ball: 8ball')
      .setColor('RANDOM')
      .addField(args.join(" "), 'Não é provavel')
    message.channel.send(embed2);
  } else if (rnd === 3) {
    const embed3 = new Discord.RichEmbed()
      .setDescription(':8ball: 8ball')
      .setColor('RANDOM')
      .addField(args.join(" "), 'Talvez')
    message.channel.send(embed3);
  } else if (rnd === 4) {
    const embed3 = new Discord.RichEmbed()
      .setDescription(':8ball: 8ball')
      .setColor('RANDOM')
      .addField(args.join(" "), 'Provavelmente')
    message.channel.send(embed3);
  } else if (rnd === 5) {
    const embed3 = new Discord.RichEmbed()
      .setDescription(':8ball: 8ball')
      .setColor('RANDOM')
      .addField(args.join(" "), 'Sim')
    message.channel.send(embed3);
  }

}


exports.conf = {
  enabled: true,
  guildOnly: false,
  aliases: ["8"],
  permLevel: "User"
};

exports.help = {
  name: "8ball",
  category: "Diversão",
  description: "Mostra uma resposta negativa ou positiva a uma questão.",
  usage: "8ball [pergunta]"
};

MOD EDIT: formatting


#2

It sounds like it can’t find a file called config.json at the location you’ve specified. Check there is a file with that name at that relative path. If you’re unsure, let us know the project name and we’ll take a look.


#3

From the looks of the code, you’re using a command handler.

Where you’re defining the botconfig variable, replace it with the following:

const botconfig = require("../config.json");

The reason why it throws this error is because you’re trying to direct it to the folder that your commands are in and the file isn’t there.

For example:
./ - Inside the directory.
../ - Outside the directory.

I hope this helps!


#4

It didn’t worked. Now the log says:
Unable to load command 8ball.js: Error: Cannot find module ‘…/config.json’

Now how do I solve this?

EDIT: Oh. And for some reason, config.json file isn’t in the glitch directory, but the system uses it! How is this possible?


#5

I think the problem is actually that there isn’t a file there, and your project’s not using the file that’s not there.

If you care to share your project name someone might be able to offer some more specific suggestions.


#6

Give me access to your project and I’ll help…


#7

Here is the github repository: https://github.com/TheBigerGamer/guidebot/tree/glitch

EDIT: The config.json still not there!


#8

You should create a config.json since there is none, create one. Somewhere along the way there is something in your code that requires data from the config.json file.

Also if the config isn’t in a folder, try adding another period. So its like so:

../config.json

Edit 2, guess it isn’t really anything discordjs related afterall


#10

I’ve already tryed, but that isn’t working.


#11

Finally I’ve found the problem! My config file was config.js and not config.json.
Thanks for the help anyways.