即使已经定义了变量,所需的代码也无法找到它们
Posted
技术标签:
【中文标题】即使已经定义了变量,所需的代码也无法找到它们【英文标题】:Variables are unable to be found by required code even if they're defined already 【发布时间】:2020-10-31 15:31:16 【问题描述】:当我需要代码并将其加载到我的 Discord 机器人的主代码中时,它无法找到变量或它们的子部分,即使它们是在主代码中定义的。
所需代码:
module.exports.stupid = () =>
bot.on('messageCreate', (msg) =>
if (msg.content === 'yes')
bot.createMessage(msg.channel.id,'yes!!')
);
-- 主脚本中的代码
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()
【问题讨论】:
您在这些行中有任何错误吗?我不确定您提供的一些细节有什么问题。 它出错并且无法从所需文件中找到变量:cdn.discordapp.com/attachments/610969665744666664/… 【参考方案1】:您必须编辑几行才能使一切按预期工作:
-
将您的
module.exports.stupid = () =>
替换为module.exports.stupid = (client) =>
调用函数(cm1.stupid()
)时,需要将bot
变量作为参数传递,如下所示:cm1.stupid(client)
希望这会有所帮助!
【讨论】:
以上是关于即使已经定义了变量,所需的代码也无法找到它们的主要内容,如果未能解决你的问题,请参考以下文章
将 Python 代码编译成 exe 文件,仅调用所需的 DLL