0

I am in the process of creating a Discord bot, and I have gotten pretty far. However, I keep getting this error when I try to connect my bot:

ReferenceError: bot is not defined

My main file's code is here. I have defined the constant variable bot to require the Eris library.

However, when I try to run the code, my command code throws the error mentioned above. I have tried to use multiple versions of module.exports but nothing seems to work. My command's code is located here.

  • In the future, please include all relevant code in your post and [**don't** just include a link to a code hosting site](https://meta.stackexchange.com/a/94027/316262). Your post should stand alone from any other resource; [consider what would happen](https://en.wikipedia.org/wiki/Link_rot) if that site went down in the future! – 0xLogN Apr 07 '21 at 00:04

1 Answers1

0

The bot constant will only exist in the main file, so you'll need a way to pass it over to the commands file. You could export a function from the commands file with bot as a parameter

const Permissions = require('eris').Constants.Permissions;

module.exports = function(bot){
    // paste in the rest of the commands code
};

And then run the function in the main file

require('../src/commands/loader')(bot);
Dharman
  • 30,962
  • 25
  • 85
  • 135
Seize
  • 59
  • 7