【发布时间】:2019-09-28 00:04:28
【问题描述】:
我知道要填充诸如公会和频道之类的集合,机器人必须已经登录,即它可以在命令文件和内部事件中使用。我所拥有的是一个模块,它将在我的控制不和谐服务器中显示我的日志,我希望能够在我的事件以及我的命令中引用这个模块。
我已经尝试在事件中导入模块,以及其他有意义的选项。
这是我模块中的代码
const Discord = require('discord.js')
const bot = new Discord.Client()
const CC = '../settings/control-center.json'
const CCFile = require(CC)
const GUILD = bot.guilds.get(CCFile.GUILD)
const STARTUP = bot.channels.get(CCFile.STARTUP)
const INFO = bot.channels.get(CCFile.INFO)
const ERRORS = bot.channels.get(CCFile.ERRORS)
const RESTART = bot.channels.get(CCFile.RESTART)
const EXECUTABLES = bot.channels.get(CCFile.EXECUTABLES)
class Control {
/**
* Implement control center logging
* @param {string} message - What to send to the startup channel
* @return {string} The final product being sent to the startup channel
*/
STARTUP(message) {
return STARTUP.send(`${message}`)
}
}
module.exports = Control
我希望能够全局使用这个模块/里面的函数,这样我的代码可以更紧凑。那么我怎样才能让这个代码只在机器人登录后加载呢?
【问题讨论】:
标签: javascript node.js visual-studio-code discord discord.js