【问题标题】:welcome message, "send" sometimes comes up as undefined欢迎信息,“发送”有时显示为未定义
【发布时间】:2021-05-04 04:56:57
【问题描述】:

当有人加入我的服务器时,我的机器人会发送这条欢迎消息,它在 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)
});

【问题讨论】:

  • 能否请您显示完整的错误?你确定不是“无法读取未定义的属性发送”而不是“发送未定义”?
  • 补充@Lioness100 的推测,很可能缓存的公会是未定义的,因为公会没有被缓存。
  • 您好!这是我可以输入的错误:` /home/container/bot3/index.js:84 guildMember.guild.channels.cache.get('801321793129414676').send(embed) ^ TypeError: Cannot read property在 Client. (/home/container/bot3/index.js:84:63) 在 Object.module.exports [as GUILD_MEMBER_ADD] 的 Client.emit (events.js:314:20) '发送'未定义(/home/container/bot3/node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_ADD.js:16:14) 在WebSocketManager.handlePacket`

标签: javascript discord discord.js


【解决方案1】:

它可能不在缓存中,所以你应该先等待它,然后尝试调用它。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    • 2019-04-04
    • 2021-10-07
    • 2021-08-17
    • 2020-09-07
    • 2021-09-23
    • 2020-09-10
    相关资源
    最近更新 更多