所以我一直在使用js和nodejs,我想为Twitter开发机器人,它的工作方式是dm我的推特,而dm将作为推文发布在我的twiiter开发人员帐户上。但是当我尝试节点twitbase.js时,它显示错误rr MODULE_NOT_FOUND
这是我的代码
var Twit = require('twit')
const request = require('request');
// Take data from file auth.js
var auth = require('./auth.js')
// connect Twitter to API
var T = new Twit(auth);
T.get('direct_messages/events/list', function(err, data, response) {
var jsonData = data;
for (var i = 0; i < jsonData['events'].length; i++) {
var counter = jsonData['events'][i]['message_create']['message_data'];
//console.log(counter['text']);
var myVar = counter['text'];
if (/[askworld]/i.test(myVar)){
tweetPost(myVar);
}
//readPost(jsonData['events'][i]['id']);
}
});
// Make Tweet
function tweetPost(msg) {
var tweet = {
status: msg
}
T.post('statuses/update', tweet, function(err, data) {
if (err) {
console.log(err);
} else {
console.log("sukses => " + msg);
}
});
}
// Delete twit DM
function delDM(id) {
var tweet = {
id: id
}
T.delete('direct_messages/events/destroy', tweet, function(err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
});
}
这是我在终端上的错误
muhammads-imac:Autobase muhammadfachruddin$ node twitbase.js
internal/modules/cjs/loader.js:628
throw err;
^
Error: Cannot find module 'twit'
Require stack:
- /Users/muhammadfachruddin/Desktop/Autobase/twitbase.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
at Function.Module._load (internal/modules/cjs/loader.js:527:27)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/Users/muhammadfachruddin/Desktop/Autobase/twitbase.js:1:12)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/muhammadfachruddin/Desktop/Autobase/twitbase.js' ]
}
有人可以帮忙吗?我需要为我的拼贴项目thx做好这项工作 *对不起我的英语不好