欢迎消息,“发送”有时会显示为未定义

时间:2021-01-30 13:37:06

标签: javascript discord discord.js

当有人加入我的服务器时,我的机器人会发送一条欢迎消息,它在 90% 的时间内都可以工作,但它会随机使机器人崩溃,任何帮助将不胜感激!

    client.on('guildMemberAdd', guildMember => {

    const guild = client.guilds.cache.get('694107369436741702');
    const memberCount = guild.memberCount;

    const embed = new Discord.MessageEmbed()
        .setColor('#8397A7')
        .setTitle(`Welcome <@${guildMember.user.id}> to Radiant Community!`)
        .setDescription(`Welcome to **Radiant Community!** :hugging: We hope you enjoy your stay and make sure to read <#694124118487990362>  before chatting anywhere, and remember to get your self the role you want to get updates from in <#707274437896175676>  otherwise you might not be notified of updates and announcements! :wink: You are our **${memberCount}th** member! :tada:`)

    guildMember.guild.channels.cache.get('801321793129414676').send(embed)
});

1 个答案:

答案 0 :(得分:0)

它可能不在缓存中,因此您应该先等待它,然后尝试对其调用发送。

let gMember = await guildMember.guild.channels.cache.get('801321793129414676');
gMember.send(embed);