【问题标题】:heroku and nodejs erorr (Web process failed to bind to $PORT within 60 seconds of launch)heroku 和 node js 错误(Web 进程在启动后 60 秒内无法绑定到 $PORT)
【发布时间】:2021-02-22 00:11:08
【问题描述】:

我正在使用 discord.js,并且我有一个代码,如果有人在 https://top.gg 上为我的机器人投票,机器人将发送一条消息,但出现此错误

Web process failed to bind to $PORT within 60 seconds of launch

这是我的代码:

const Discord = require('discord.js')
const bot = new Discord.Client();

const DBL = require('dblapi.js');
const dbl = new DBL(process.env.DBTOKEN, { webhookPort: 5000, webhookAuth: 'password' }, bot)
dbl.webhook.on('ready', hook => {
    console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
  });

dbl.webhook.on('vote', vote => {
  let embed = new Discord.MessageEmbed()
  .setTitle('A user just upvoted!')
  .setDescription(`Thank you **${vote.user.tag}** for voting me!`)
  .setColor('FF000')
  .setThumbnail(vote.user.displayAvatarURL())
  let votechannel = bot.channels.cache.find(x => x.id === '775360008786280468')
  votechannel.send(embed)
})

请帮助我,将不胜感激

【问题讨论】:

    标签: javascript node.js heroku discord discord.js


    【解决方案1】:

    Heroku 会不时更改运行节点应用程序的端口。尝试将您的 webhook 端口更改为 process.env.PORT。检查下面的代码。

    const Discord = require('discord.js')
    const bot = new Discord.Client();
    
    const DBL = require('dblapi.js');
    const dbl = new DBL(process.env.DBTOKEN, { webhookPort: process.env.PORT || 5000, webhookAuth: 'password' }, bot)
    dbl.webhook.on('ready', hook => {
        console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
      });
    
    dbl.webhook.on('vote', vote => {
      let embed = new Discord.MessageEmbed()
      .setTitle('A user just upvoted!')
      .setDescription(`Thank you **${vote.user.tag}** for voting me!`)
      .setColor('FF000')
      .setThumbnail(vote.user.displayAvatarURL())
      let votechannel = bot.channels.cache.find(x => x.id === '775360008786280468')
      votechannel.send(embed)
    })
    

    【讨论】:

      【解决方案2】:

      Heroku 实际上会通过 PORT 环境变量告诉您​​应该将 Web 服务器绑定到哪个端口,您可以在节点上的 process.env.PORT 访问它。

      将您的 webhookPort5000 更改为该变量,它应该可以工作 :)

      【讨论】:

        猜你喜欢
        • 2020-02-10
        • 1970-01-01
        • 2021-02-19
        • 2013-03-19
        • 1970-01-01
        • 2019-12-07
        • 2016-03-08
        • 1970-01-01
        相关资源
        最近更新 更多