【问题标题】:Web scraping instagram follower count and set it as discord channel网络抓取 instagram 关注者数量并将其设置为不和谐频道
【发布时间】:2021-08-25 09:08:14
【问题描述】:

我目前正在尝试将某个用户的 Instagram 关注者计数设置为每 30 秒更新一次的不和谐频道。我遇到了一个包错误,它似乎只在我将它记录到终端时才有效,而不是实际的不和谐。

Package I am using.

到目前为止,这是我的代码:

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);

【问题讨论】:

    标签: javascript node.js web-scraping discord discord.js


    【解决方案1】:

    程序运行时不能更改常量变量。您已经在间隔循环中声明了一个常量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)
    
    });
    

    Read this - 它将清除有关常量和变量的任何错误信息。

    在以后的问题中,请包含来自控制台的错误日志。它使您的代码调试变得无比轻松。

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 2016-09-11
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      相关资源
      最近更新 更多