0
私のtwitter botのバグを修正しようとしていますが、基本的にフォルダのすべてのファイル名を持つ配列があり、ランダムに選択して投稿します同じ画像を再び投稿します、どうすれば修正できますか?ランダムファイルを選択してnode.jsで移動
fs.js:640
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT: no such file or directory, open 'D:\memesbot\memestorage\queue\645 (2).jpg'
at Error (native)
at Object.fs.openSync (fs.js:640:18)
at Object.fs.readFileSync (fs.js:508:33)
at Timeout.upload_random_image [as _onTimeout] (D:\memesbot\memes.js:29:23)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
:ここ
は私が
...
var filename = (random_file());
var pfile = ("posted"+random_file());
var imgPATH = path.join(__dirname, '/memestorage/queue/' + filename);
var postedFile = path.join(__dirname, '/memestorage/posted/' + pfile);
fs.rename(imgPATH, postedFile, function(err) {
if (err) console.log('ERROR: ' + err);
});
//image selection and upload
function upload_random_image(){
console.log('Opening file...');
var image_path = imgPATH,
b64content = fs.readFileSync(imgPATH, { encoding: 'base64' });
...
と試みたが、何度も何度も同じ画像を投稿、または時々、このエラーメッセージを表示しますたコード
var fs = require('fs'),
path = require('path'),
Twit = require('twit'),
set = require(path.join(__dirname, 'set.js'));
//array of files
files_memes = require(path.join(__dirname, 'files.js'))
var currentdate = new Date();
var upl = "Subido: "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes()+ " hs.";
var setMin = 10;
var T = new Twit(set);
function random_file(){
var allFiles = (files_memes)//array
return allFiles[Math.floor(Math.random() * allFiles.length)];
}
var filename = (random_file());
var imgPATH = path.join(__dirname, '/memestorage/queue/' + filename);
//image selection and upload
function upload_random_image(){
console.log('Opening file...');
var image_path = imgPATH,
b64content = fs.readFileSync(image_path, { encoding: 'base64' });
console.log('Uploading file...');
T.post('media/upload', { media_data: b64content }, function (err, data, response) {
if (err){
console.log('ERROR');
console.log(err);
}
else{
console.log('File loaded!');
T.post('statuses/update', {
media_ids: new Array(data.media_id_string)
},
function(err, data, response) {
if (err){
console.log('Error!');
console.log(err);
}
else{
console.log('Tweeted!');
console.log(upl);
console.log('Next tweet in ' + setMin + ' min.');
}
}
);
}
});
}
//timer
setTimeout(
upload_random_image,
0
);
setInterval(
upload_random_image,
1000*10
);
です
誰かが私を助けてくれることを祈って、感謝します。
おっと内側の線の下の
移動!それに気付かなかった!今すぐ完璧に動作します –