Answer the question
In order to leave comments, you need to log in
How to create your file with functions?
In general, I’m not good at browsing the Internet, apparently, I’ve surfed all over, but I didn’t find what I needed.
I managed to do what I wanted, but not completely.
What I have:
//в main.js
bot.func = require('./functions'); //должно писаться именно так, ибо переменная бот летает по всему коду.
//в /functions/index.js
function getMemoryMember (bot, id) {
//1412351235
}
function getGuildMember (bot, id) {
//1412351235
}
function addExp (bot, id, exp) {
//1412351235
}
function getGuildRole (bot, id) {
//1412351235
}
function declOfNum(n, text_forms) {
//1412351235
}
function getTime (time) {
//1412351235
}
module.exports = {
getMemoryMember: getMemoryMember,
getGuildMember: getGuildMember,
addExp: addExp,
getGuildRole: getGuildRole,
declOfNum: declOfNum,
getTime: getTime
};
//в main.js
bot.func = require('./functions')(bot);
//в /functions/index.js
module.exports = (bot) => {
function getMemoryMember (bot, id) {
//1412351235
}
Answer the question
In order to leave comments, you need to log in
Well, for example, like this, if you do not change the definition of functions:
//в main.js
bot.func = require('./functions')(bot);
//в /functions/index.js
module.exports = (bot) => ({
getMemoryMember: (id) => getMemoryMember(bot, id),
getGuildMember: (id) => getGuildMember(bot, id),
...
declOfNum,
getTime,
});
// в main.js
Object.assign(bot, require('./functions'));
// вместо bot.func.getMemoryMember(bot, id)
bot.getMemoryMember(id);
//в /functions/index.js
function getMemoryMember (id) {
// тут использовать this вместо bot
}
function getGuildMember (id) {
//1412351235
}
...
module.exports = {
getMemoryMember,
getGuildMember,
addExp,
getGuildRole,
declOfNum,
getTime
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question