每次运行它表示表拖缆即使它确实存在IK也不存在。我正在使用的这个代码在另一个文件中用于另一个脚本,现在它不起作用...任何帮助?它的作用是检查Beam.pro中的API条目,并将飘带在线状态与数据库中保存的状态进行比较,如果无法检查数据库,则无法找到它。
const Discord = require('discord.js');
const request = require('request');
const sql = require('sqlite');
sql.open('./streamers.sqlite');
let Config;
//look for config
try {
Config = require('./config.json');
} catch(e) {
console.log('Please create an config.json file in the main directory based off of the config.json.example file!\n' + e.stack);
process.exit();
}
console.log('I am ready for work :)')
const bot = new Discord.Client()
function check() {
for(let i = 0; Config.streamers.length > i; i++) {
sql.get(`SELECT * FROM streamers WHERE streamer ='${Config.streamers[i]}'`).then(row => {
if (!row) {
sql.run('INSERT INTO streamers (streamer, status) VALUES (?, ?)', [Config.streamers[i], false]);
} else {
request('https://beam.pro/api/v1/channels/'+Config.streamers[i],
function(err,res,body){
const data = JSON.parse(body);
if(!data) console.log(`The channel, ${Config.streamers[i]}, is not a valid beam.pro channel!`);
if(data.online === false && row.status == true) {
sql.run(`UPDATE streamers SET status = false WHERE streamer = ${Config.streamers[i]}`);
console.log(`${Config.streamers[i]} is offline!`)
};
if(streamers[i].online === true && data.online == true) return;
if(data.online === true && row.status == false) {
sql.run(`UPDATE streamers SET status = true WHERE streamer = ${Config.streamers[i]}`);
for(let j = 0; j < Config.channelID.length; j++){
const embed = new Discord.RichEmbed()
.setTitle('Beam Alerts')
.setDescription(`${Congif.streamers[i]} is now live!`)
.addField(`Playing For:`, `${data.numFollowers} followers`,true)
.addField(`${Config.streamers[i]} is Playing:`, '${data.type.name}',true)
.setFooter('BaconHawk - NITEHAWK')
.setColor([0,45,255])
.setTimestamp()
bot.channels[Config.channelID[j]].sendEmbed(embed);
}
}
});
}
})
}
}
bot.on('ready', () => setInterval(check, 60*5*1000));
bot.login(Config.bot_token)