【发布时间】:2018-06-08 10:09:10
【问题描述】:
我正在尝试构建一个 Telegram 机器人,我正在使用以下 npm 包:https://www.npmjs.com/package/node-telegram-bot-api
我的项目结构如下:
在我的app.js 文件中,我这样做:const bot = new TelegramBot(token, {polling: true});。我想与index.js 文件共享这个bot 实例,以便在index.js 文件中我可以执行以下操作:
bot.onText(/\/time (.+)/, (msg, match) => {
});
我不确定如何实现这一点,我能想到的唯一方法是通过在 app.js 文件上使用 module.exports 来做到这一点,但我不确定这是否是正确的做法.
-编辑-
在我想做的app.js文件中:
require('./plugins/time')
require('./plugins/weather')
然后输入node app.js 运行机器人。
【问题讨论】:
标签: javascript node.js plugins ecmascript-6 ecmascript-5