我正在将我制作的三个js模块导入程序中,但是每当我运行其中的任何一个时,它们始终会运行最后导入的文件的导出功能。
x = require("./modules/x/x");
y = require("./modules/y/y");
z = require("./modules/z/z");
在每个文件中都有一个导出为:
的函数module.exports = { runX/Y/Z }
我希望runX可以运行x.runX,runY可以运行y.runY,runZ可以运行z.runZ。 但是,实际运行的功能是最后导入的那个。
模块内部的代码看起来像这样
const juergenJSON = require("./juergen.json");
noArg = async channel => {
};
oneArg = async (arg1, channel) => {};
twoArg = async (arg1, arg2, channel) => {};
runJuergen = options => {
const juergen = options;
juergen.twoArgs
? twoArg(juergen.arg1, juergen.arg2, juergen.channel)
: juergen.oneArgs
? oneArg(juergen.arg1, juergen.channel)
: noArg(juergen.channel);
};
module.exports = { runJuergen };
他们这样称呼
const { Client } = require("discord.js");
const auth = require("./auth.json");
let reddit = require("./modules/reddit/reddit.js");
let juergen = require("./modules/juergen/juergen.js");
let joe = require("./modules/joe/joe.js");
// Create an instance of a Discord client
const client = new Client();
/**
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
* received from Discord
*/
client.on("ready", () => {
console.log("Bot Loaded");
});
client.on("message", message => {
let name;
let arg1;
let arg2;
const temp = message.content.split(" ");
const channel = message.channel;
name = temp[0].substr(1);
arg1 = temp[1];
arg2 = temp[2];
let oneArgs;
let twoArgs;
arg1 && true ? (oneArgs = true) : (oneArgs = false);
arg1 && arg2 ? (twoArgs = true) : (twoArgs = false);
const options = {
name: name,
arg1: arg1,
arg2: arg2,
oneArgs: oneArgs,
twoArgs: twoArgs,
channel: channel
};
switch (name.toLowerCase()) {
case "reddit":
console.log("hello");
reddit.runReddit(options);
break;
case "juergen":
juergen.runJuergen(options);
break;
case "joe":
joe.runJoe(options);
break;
case "max":
tea(arg1, message);
break;
break;
}
});
我知道这里有一些类似的帖子,但是我很难理解它们,因此非常感谢针对我的情况的回复。
答案 0 :(得分:0)
在switch语句中在本地将每个const定义为其大小写