我的机器人应该在主要加入/离开频道以及聊天室中都欢迎会员,这样我们所有人都可以欢迎用户。由于某种原因,存在一个错误,该错误有时不会将欢迎消息发送到聊天室。
错误:
(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之类的不同方法,或者只是以不同的方式对其进行了重新编码以查看其是否有效。到目前为止,这是我的朋友们唯一不了解为什么它提供错误的地方
答案 0 :(得分:0)
您只需使用client
通过ID获取频道
client.channels.fetch("SOME_CHANNEL_ID").then(channel => {
channel.send(welcomeEmbed);
})