You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IgApiClient抛出IgNotFoundError:DiscordJS机器人无法找到指定USERID

运行DiscordJS机器人时出现IgNotFoundError:Instagram用户未找到

我在用DiscordJS开发机器人时,控制台抛出了IgNotFoundError,提示USERID变量对应的Instagram用户未找到。我确认代码其他部分没问题,用户ID填写正确,目标账号不是私密账号且有发布帖子。

相关代码

const {IgApiClient} = require('instagram-private-api');
const { Client, GatewayIntentBits } = require('discord.js');

const TOKEN = '';
const USERINSTAGRAM = '';
const PASSINSTAGRAM = '';
const CHANNEL = '';
const USERID = '';

async function main() {
    const ig = new IgApiClient();
    ig.state.generateDevice(USERINSTAGRAM);
    await ig.account.login(USERINSTAGRAM, PASSINSTAGRAM);
    const client = new Client({
        intents: [
            GatewayIntentBits.Guilds,
            GatewayIntentBits.GuildMessages,
            GatewayIntentBits.MessageContent,
            GatewayIntentBits.GuildMembers,
        ],
    });
    await client.login(TOKEN);
    const channel = await client.channels.fetch(CHANNEL);
    let lastPostID;
    const feed = ig.feed.user(USERID);
    const posts = await feed.items();
    if (posts.length > 0) {
        lastPostID = posts[0].id;
    }
    setInterval(async () => {
        const posts = await feed.items();
        if (posts.length > 0 && posts[0].id !== lastPostID) {
            lastPostID = posts[0].id;
            channel.send(`El usuario ha publicado un nuevo post en Instagram: ${posts[0].code}`);
            await sendPost(ig, channel, posts);
        }
    }, 60 * 1000); // 1 minuto 
}

main();

终端错误信息

C:\Users\admin\Desktop\Bot\node_modules\instagram-private-api\dist\core\request.js:103
return new errors_1.IgNotFoundError(response);
^

IgNotFoundError: GET /api/v1/feed/user/xxxxx/ - 404 Not Found;
at Request.handleResponseError (C:\Users\admin\Desktop\Bot\node_modules\instagram-private-api\dist\core\request.js:103:20)
at Request.send (C:\Users\admin\Desktop\Bot\node_modules\instagram-private-api\dist\core\request.js:54:28)
at async UserFeed.request (C:\Users\admin\Desktop\Bot\node_modules\instagram-private-api\dist\feeds\user.feed.js:21:26)
at async UserFeed.items (C:\Users\admin\Desktop\Bot\node_modules\instagram-private-api\dist\feeds\user.feed.js:31:22)
at async main (C:\Users\admin\Desktop\Bot\pruebagit.js:26:19)
Node.js v18.15.0


解决方法
  • 确认用户ID准确性:别把Instagram用户名(@xxx)和用户ID(纯数字串)搞混。可以通过API先根据用户名获取正确ID,替换硬编码的USERID:

    // 登录后添加这段代码获取目标用户ID
    const targetUser = await ig.user.searchExact('目标用户名');
    const targetUserId = targetUser.pk;
    const feed = ig.feed.user(targetUserId);
    
  • 检查登录状态有效性:确保ig.account.login确实成功,没出现隐性失败(比如账号验证、风控限制)。可以加个日志确认:

    await ig.account.login(USERINSTAGRAM, PASSINSTAGRAM);
    console.log('Instagram账号登录成功');
    
  • 更新API版本:旧版instagram-private-api可能因Instagram接口变更出现适配问题,执行npm update instagram-private-api更新到最新版。

  • 验证访问权限:用登录的Instagram账号手动访问目标用户主页,确认没被拉黑、账号本身无风控限制,能正常查看帖子。

内容的提问来源于stack exchange,提问作者Khazius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 17:12:49