[英]client.on(“guildCreate”) running on 504 Gateway Time-out
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.我有一个 discord.js 机器人在 Heroku 上运行,当它从公会中添加或删除时,它会向我服务器中的特定频道发送消息。 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.
这在一周前运行良好,现在当我更新它(通过 GitHub 将更新推送到 Heroku)时,它会发送消息说它已从公会中删除。 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:当它被更新时,正如我之前所说,它会发送带有以下显示为未定义的休假嵌入:
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.更新(22/02/21):这个问题仍然存在,如果它自己关闭并打开几秒钟,它仍然会发送嵌入。 Another Update (23/02/21): There have been errors, this is it:
另一个更新(23/02/21):出现错误,就是这样:
UnhandledPromiseRejectionWarning: Error: 504 Gateway Time-out
Comment if you need the whole error as I'm not sure if the rest is helpful如果您需要整个错误,请发表评论,因为我不确定 rest 是否有帮助
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();
You need to enable intents, you can read more about it here , and list of intents here and there are two Privileged Gateway Intents PRESENCE INTENT
and SERVER MEMBERS INTENT
您需要启用意图,您可以在此处阅读有关它的更多信息,以及此处的意图列表,并且有两个特权网关意图存在
PRESENCE INTENT
和SERVER MEMBERS INTENT
PRESENCE INTENT
:If your bot tracks presence data, you may need the presence intent to receive presence event data.存在
PRESENCE INTENT
:如果您的机器人跟踪存在数据,您可能需要存在意图来接收存在事件数据。
SERVER MEMBERS INTENT
: If your bot tracks server members or downloads the entire member list, you may need the server members intent to receive member events and the member list.SERVER MEMBERS INTENT
:如果您的机器人跟踪服务器成员或下载整个成员列表,您可能需要服务器成员意图来接收成员事件和成员列表。
Privileged Gateway intents can be enabled on discord.com/developers/applications/ -> Settings/Bot.特权网关意图可以在 discord.com/developers/applications/ -> Settings/Bot 上启用。
In your case you will need the intent GUILDS which provides the access to guildDelete
and guildCreate
:在您的情况下,您将需要提供对
guildDelete
和guildCreate
:
const { Client } = require('discord.js');
const client = new Client({ ws: { intents: ['GUILDS'] } });
guildDelete
is not guaranteed to have the full data, only if it was cached you can get it, sometimes the data was cached and it executed with 0 errors, and other times when it wasn't cached fully, so you get that error. guildDelete
不保证有完整的数据,只有当它被缓存时你才能得到它,有时数据被缓存并且它执行时出现 0 个错误,而其他时候它没有被完全缓存,所以你得到那个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.