所以我坚持这个错误.我正在用电报bot api制作一个电报机器人,现在我试图设置一个firebae数据库来保存一个组成员的分数 – 所以在重新启动机器人后不会重置分数.谁能告诉我问题是什么?我在这里阅读了许多类似的问题,但这些答案都没有解决我的问题.
bot.js
var TelegramBot = require('node-telegram-bot-api'); var firebase = require('firebase'); var token = 'mytoken'; // Setup polling way var bot = new TelegramBot(token,{polling: true}); var app = firebase.intializeApp({ serviceAccount: "C:/Mayer/scorebot/telegramscorebot.json",databaseURL: "https://blazing-heat-2008.firebaseio.com/" }); /* function Person(name,score) { this.name = name; this.score = score; } var member = new Array(); member[0] = new Person("name1",0); member[1] = new Person("name2",0); member[2] = new Person("name3",0); member[3] = new Person("name4",0); member[4] = new Person("name5",0); */ bot.onText(/\/echo (.+)/,function (msg,match) { var fromId = msg.from.id; if (match[1] == 'test') { var resp = match[1]; bot.sendMessage(fromId,resp); } else { bot.sendMessage(fromId,'error!!');} }); bot.onText(/\/vote (.+)/,match) { var fromId = msg.from.id; for (var i = 0; i <= 4; i++) { if(member[i].name == match[1]){ member[i].score += 1; bot.sendMessage(fromId,member[i].name + ' hat einen score von ' + member[i].score);} } });
的package.json
{ "name": "scorebot","version": "1.0.0","description": "","main": "bot.js","scripts": { "test": "echo \"Error: no test specified\" && exit 1","start": "node bot.js" },"author": "me","license": "ISC","dependencies": { "bower": "1.7.9","firebase": "3.0.2" } }
错误信息
bot.js:8 var app = firebase.intializeApp({ ^ TypeError: firebase.intializeApp is not a function at Object.<anonymous> (C:\Mayer\scorebot\bot.js:8:20) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Function.Module.runMain (module.js:447:10) at startup (node.js:141:18) at node.js:933:3
解决方法
请参阅此处的文档:
https://www.npmjs.com/package/firebase
您需要在浏览器上下文中使用’app’,如此…
const firebase = require('firebase/app'); const app = firebase.initializeApp({ ... });