Terra_rian
Terra_rian

Reputation: 1

ReferenceError: "bot" is not defined (Eris) - in my commands

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.

Upvotes: 0

Views: 270

Answers (1)

Seize
Seize

Reputation: 57

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

Upvotes: 0

Related Questions