网页抓取instagram粉丝数并设置为不和谐频道



我目前正试图将某个用户的Instagram关注者计数设置为每30秒更新一次的不和谐频道。我正面临一个错误,这个错误似乎只有当我将其登录到终端时才有效,而不是实际的不和谐。

我正在使用的包。

下面是我的代码:
const config = require("./config.json");
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })
// Log stats-bot in to the server and set status
bot.on("ready", async () => {
console.log(`${bot.user.username} has logged on.`)
bot.user.setActivity('Half Life 3', { type: 'PLAYING' })
.then(presence => console.log(`Activity set to ${presence.game ? presence.game.name : 'none'}`))
.catch(console.error);
// Get our server
const guild = bot.guilds.get('875154076814438430');
// Get our stats channels
const instaObj = require('instagram-basic-data-scraper-with-username');
const user = 'milliontoken';

const totalUsers = bot.channels.get('875154076814438434');

// Check every 30 seconds for changes
setInterval(function() {
//Get actual counts
instaObj.getFollowers(user).then(res => {
const getFollowers = res.data;
console.log(getFollowers);
});

// Log counts for debugging
console.log("Total Users: " + getFollowers);
// Set channel names
totalUsers.setName("Total Users: " + getFollowers)
.then(newChannel => console.log(`Stat channel renamed to: ${newChannel.name}`))
.catch(console.error);
}, 30000)
});
bot.login(config.token);

程序运行时不能更改常量变量。你已经在interval循环中声明了一个常数getFollowers。你的程序试图改变常量的值,但是不能,因为它不能在运行时改变,并抛出一个错误。

由于你没有包含错误数据,这是我能看到的唯一错误的代码。

// Check every 30 seconds for changes
setInterval(function() {
//Get actual counts
instaObj.getFollowers(user).then(res => {
let getFollowers = res.data; //remove 'const', replace with non-constant declaration syntax
console.log(getFollowers);
});

// Log counts for debugging
console.log("Total Followers: " + getFollowers); //changed from "users" to "followers"
// Set channel names
totalUsers.setName("Total Followers: " + getFollowers)
.then(newChannel => console.log(`Stat channel renamed to: ${newChannel.name}`))
.catch(console.error);
}, 30000)
});

阅读这篇文章——它将澄清关于常量和变量的任何错误信息。

在以后的问题中,请包括控制台的错误日志。它使调试代码变得无比容易。

最新更新