首页 > 解决方案 > Heroku一直超时:等待网络时出错:资源暂时不可用

问题描述

我的 index.js 文件:

const Discord = require('discord.js');
const levels = require('discord-xp');
const client = new Discord.Client();
const mongoose = require('./database/mongoose');
const fs = require(`fs`);
require('dotenv').config();
const port = process.env.PORT || 5000;
const host = '0.0.0.0';

const chalk = require('chalk');
const { Player } = require('discord-player');
const Gamedig = require('gamedig');

client.prefix = (`${process.env.PREFIX}`);
client.commands = new Discord.Collection();

client.player = new Player(client);
client.config = require('./config/bot');
client.emotes = client.config.emojis;
client.filters = client.config.filters;

fs.readdirSync('./commands').forEach(dirs => {
    const commands = fs.readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js'));

    for (const file of commands) {
        const command = require(`./commands/${dirs}/${file}`);
        console.log(`Loading command ${file}`);
        client.commands.set(command.name.toLowerCase(), command);
    };
});
const player = fs.readdirSync(`./player`).filter(file => file.endsWith('.js'));
const events = fs.readdirSync('./events').filter(file => file.endsWith('.js'));


for (const file of player) {
    console.log(`Loading discord-player event ${file}`);
    const event = require(`./player/${file}`);
    client.player.on(file.split(".")[0], event.bind(null, client));
};
for (const file of events) {
    console.log(`Loading discord.js event ${file}`);
    const event = require(`./events/${file}`);
    client.on(file.split(".")[0], event.bind(null, client));
};

mongoose.init();
client.login(process.env.TOKEN)

我的档案:

Worker: node index.js

我的 package.json:

{
    "name": "icrp-bot",
    "version": "1.0.0",
    "description": "Made For ICRP ",
    "main": "index.js",
    "scripts": {
      "test": ".test",
      "start": "node index.js"
    },
    "author": "Bombo43453#1901",
    "license": "ISC",
    "dependencies": {
      "axios": "^0.21.1",
      "baseplayer": "^0.2.9",
      "chalk": "^4.1.1",
      "discord-fivem-api": "^1.0.4",
      "discord-player": "^3.4.0",
      "discord-xp": "^1.1.14",
      "discord.js": "^12.5.3",
      "dotenv": "^8.2.0",
      "ffmpeg-static": "^4.3.0",
      "gamedig": "^3.0.1",
      "log-timestamp": "^0.3.0",
      "moment": "^2.29.1",
      "moment-timezone": "^0.5.33",
      "mongoose": "^5.11.14",
      "node-gyp": "^8.0.0",
      "opus": "0.0.0",
      "opusscript": "0.0.8",
      "pm2": "^4.5.6",
      "python": "0.0.4",
      "rebuild": "^0.1.2"
    }
}

完全错误:

2021-04-23T17:18:33.808571+00:00 heroku[Worker.1]: State changed from down to starting
2021-04-23T17:18:43.196477+00:00 heroku[Worker.1]: Starting process with command `node index.js`
2021-04-23T17:18:43.846098+00:00 heroku[Worker.1]: State changed from starting to up
2021-04-23T17:18:43.854420+00:00 heroku[Worker.1]: Idling
2021-04-23T17:18:43.856605+00:00 heroku[Worker.1]: State changed from up to down
2021-04-23T17:18:43.870047+00:00 heroku[Worker.1]: Idling because quota is exhausted
2021-04-23T17:18:50.422071+00:00 app[Worker.1]: Error waiting for network: Resource temporarily unavailable

信息:这是我为 Fivem 服务器制作的简单机器人。我试图用heroku托管它并试图修复它。我尝试添加一个端口 const 和一个 const 主机,但这并没有解决任何问题。我也认为我的问题很小,我在 heroku 上还有 200 个小时,这意味着时间不是问题。我也尝试将端口更改为 8080,但没有任何帮助。如果你有想法请告诉我。

标签: javascriptnode.jsherokudiscord.js

解决方案


我知道你说你还有 200 小时。
Idling because quota is exhausted仅在您用完空闲时间时显示。

您还说您将端口更改为 8080,但请注意,您无法更改 HEROKU上的端口,您将端口作为 env 变量(就像process.env.PORT您在上面所做的那样)并且您无法更改它。

如果您使用的是 worker,这意味着您无法运行 Web 进程,并且 PORT 无论如何也没用。

关于您的最后一个错误,这是来自 Heroku 支持
This is caused by kernel-level issues that can surface occasionally on the backend instances that dynos run on. Unfortunately, there is not really a work around for this issue. Scheduler dynos will crash if this happens and the job will not be executed again until its next scheduled run time. Other dyno types will typically enter a bad state and require a manual restart (you may see "App boot timeout" errors when this happens). 检查这个


推荐阅读