【发布时间】:2020-10-02 18:38:48
【问题描述】:
假设我的机器人在主加入/离开频道和聊天室都欢迎成员,这样我们都可以欢迎用户。由于某种原因,存在一个错误,有时它不会将欢迎消息发送到聊天室。
错误:(node:194) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null
欢迎活动:
client.on('guildMemberAdd', async (member) => {
const welcomeEmbed = new Discord.RichEmbed()
.setAuthor(member.user.tag, member.user.avatarURL)
.setColor(`GREEN`)
.setDescription(`Welcome **${member.user.username}** to member.guild.name! Consider reading <# {HIDDEN}> to have a basic understand of what we do and do not allow.
Come hang out with us in <#{HIDDEN}> and have a good time!`)
.setFooter(`Member ID: ${member.id}`)
member.guild.channels.find(channel => channel.id === 'HIDDEN').send(welcomeEmbed);
const welcomeEmbed2 = new Discord.RichEmbed()
.setAuthor("New Member Joined!", member.user.avatarURL)
.setDescription(`**${member.user.tag} has joined the server!**`)
.setColor('GREEN')
member.guild.channels.find(channel => channel.id === 'HIDDEN').send(welcomeEmbed2); // This is the one providing the error sometimes
});
我尝试了不同的方法,例如 .then 或者只是以不同的方式重新编码,看看它是否会起作用。到目前为止,这是我的朋友们唯一不明白为什么它会提供错误的原因
【问题讨论】:
-
如果您通过 id 获取频道,为什么不直接使用
<Collection>.get(id_here)?无论如何,错误可能是您在不同的公会中有机器人,当发生这种情况时,这些公会无法找到具有相同 id 的频道(因为它当然是唯一的) -
机器人在一台服务器上。不过,我会试试收藏功能。
标签: discord.js