为了账号安全,请及时绑定邮箱和手机立即绑定

heroku 和 nodejs erorr(Web 进程未能在启动后 60 秒内绑定到 $PORT)

heroku 和 nodejs erorr(Web 进程未能在启动后 60 秒内绑定到 $PORT)

潇潇雨雨 2023-07-20 17:10:52
我正在使用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)})请帮助我,我将不胜感激
查看完整描述

2 回答

?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

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)

})


查看完整回答
反对 回复 2023-07-20
?
POPMUISE

TA贡献1765条经验 获得超5个赞

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

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


查看完整回答
反对 回复 2023-07-20
  • 2 回答
  • 0 关注
  • 122 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信