I am using discord.js and I have a code where if someone votes for my bot on https://top.gg the bot will send a message, but it got this error
JavaScript
x
2
1
Web process failed to bind to $PORT within 60 seconds of launch
2
Here is my code:
JavaScript
1
19
19
1
const Discord = require('discord.js')
2
const bot = new Discord.Client();
3
4
const DBL = require('dblapi.js');
5
const dbl = new DBL(process.env.DBTOKEN, { webhookPort: 5000, webhookAuth: 'password' }, bot)
6
dbl.webhook.on('ready', hook => {
7
console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
8
});
9
10
dbl.webhook.on('vote', vote => {
11
let embed = new Discord.MessageEmbed()
12
.setTitle('A user just upvoted!')
13
.setDescription(`Thank you **${vote.user.tag}** for voting me!`)
14
.setColor('FF000')
15
.setThumbnail(vote.user.displayAvatarURL())
16
let votechannel = bot.channels.cache.find(x => x.id === '775360008786280468')
17
votechannel.send(embed)
18
})
19
Please help me that would be very appreciated
Advertisement
Answer
Heroku changes the Port that runs Node Application from time to time. Try changing your webhook port to process.env.PORT
. Check the code below.
JavaScript
1
19
19
1
const Discord = require('discord.js')
2
const bot = new Discord.Client();
3
4
const DBL = require('dblapi.js');
5
const dbl = new DBL(process.env.DBTOKEN, { webhookPort: process.env.PORT || 5000, webhookAuth: 'password' }, bot)
6
dbl.webhook.on('ready', hook => {
7
console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
8
});
9
10
dbl.webhook.on('vote', vote => {
11
let embed = new Discord.MessageEmbed()
12
.setTitle('A user just upvoted!')
13
.setDescription(`Thank you **${vote.user.tag}** for voting me!`)
14
.setColor('FF000')
15
.setThumbnail(vote.user.displayAvatarURL())
16
let votechannel = bot.channels.cache.find(x => x.id === '775360008786280468')
17
votechannel.send(embed)
18
})
19