I have a discord.js bot running on Heroku, when it gets added or removed from a guild it sends a message to a specific channel in my server. This was working fine a week ago, and now when I update it (push update through GitHub to Heroku) it sends the message saying that it was removed from a guild. There is an error:
UnhandledPromiseRejectionWarning: Error: 504 Gateway Time-out
This is the code:
client.on('guildCreate', guild => {
try{
//Check for system channel
if(!guild.systemChannel) return false;
//Sends message to system channel
guild.systemChannel.send('Thank you for adding me to your server. Run ``-setup`` to begin setup.')
//My server and channel
const server = client.guilds.cache.get('guildID')
const channel = server.channels.cache.get('channelID')
//The embed which sends to channel
const joinEmbed = new Discord.MessageEmbed()
.setTitle("Joined")
.setDescription("Optic was added to a server")
.addFields(
{ name: 'Name', value: guild.name, inline: false },
{ name: 'GuildId', value: guild.id,inline: false },
{ name: 'Guild OwnerId', value: guild.ownerID, inline: false },
{ name: 'Member Count', value: guild.memberCount, inline: false },
{ name: 'Total Guilds', value: client.guilds.cache.size, inline: true },
)
channel.send(joinEmbed)
}catch(error){
console.log("There was an error sending join embed to channel")
}
});
client.on('guildDelete', guild => {
try{
//My server and channel:
const server = client.guilds.cache.get('guildID')
const channel = server.channels.cache.get('channelID')
//The embed which sends to channel
const leaveEmbed = new Discord.MessageEmbed()
.setTitle("Removed")
.setDescription("Optic was removed from a server")
.addFields(
{ name: 'Name', value: guild.name, inline: false },
{ name: 'GuildId', value: guild.id,inline: false },
{ name: 'Guild OwnerId', value: guild.ownerID, inline: false },
{ name: 'Member Count', value: guild.memberCount, inline: false },
{ name: 'Total Guilds', value: client.guilds.cache.size, inline: true },
)
channel.send(leaveEmbed)
}catch(error){
console.log("There was an error sending leave embed to channel.")
}
});
When it is updated, as I stated earlier, it sends the leave embed with the following showing as undefined:
- Name
- Guild Owner ID
- Member Count
Any help will be appreciated on what is happening. Thanks :)
Update (22/02/21): This problem still happens, if it were to turn off and on by itself for a few seconds, it will still send the embed. Another Update (23/02/21): There have been errors, this is it:
UnhandledPromiseRejectionWarning: Error: 504 Gateway Time-out
Comment if you need the whole error as I'm not sure if the rest is helpful
Bounty Reason: Draw attention This question has not received enough attention.
Code where I declare the client:
const Discord = require('discord.js');
const client = new Discord.Client();