1

When I require code and load it into my main code for my Discord bot, it's unable to find variables or sub parts of them even if they're defined in the main code.

Required code:

module.exports.stupid = () => {

bot.on('messageCreate', (msg) => {
    if (msg.content === 'yes'){
        bot.createMessage(msg.channel.id,'yes!!')
    }
});

}

-- Code in main script

const Eris = require('eris');
const axios = require('axios');
const firebase = require('firebase/app');
const FieldValue = require('firebase-admin').firestore.FieldValue
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccount.json');

// Commands
const cm1 = require('./staff.js')

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
})

let db = admin.firestore()

const bot = new Eris('token_removed');
let prefix = ';'
const sprefix = ">"
const botname = "bee"
const version = '0.6.6'
const emoji = '<:bee_logo:730125457638425039>'
const semoji = '<:bshield:729463155587022860>'
const remoji = 'buzz:683498511341191245'

const bee_check = '<:bee_check:729878268811018300>'
const bee_dash = '<:bee_dash:729878268790177862>'
const bee_x = '<:bee_x:729878268848898159>'
const hex = 0xF3DC3E
const gethex = 'F3DC3E'
const server = "Amazon (Linux/UNIX)"
const today = new Date();
const time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();

cm1.stupid()
  • Do you get any errors within these lines ? I'm not sure to understand what is wrong with the few details you gave. – Tenclea Jul 11 '20 at 14:20
  • it errors and about not being able to find the variables from the required file: https://cdn.discordapp.com/attachments/610969665744666664/731577574622232659/unknown.png –  Jul 11 '20 at 18:28

1 Answers1

0

You'll have to edit a few lines in order to make everything work as intended :

  1. Replace your module.exports.stupid = () => { with module.exports.stupid = (client) => {
  2. When calling the function (cm1.stupid()), you need to pass the bot variable as an argument like so: cm1.stupid(client)

Hope this helps !

Tenclea
  • 1,444
  • 2
  • 10
  • 23