【问题标题】:Cannot read property 'roles' of undefines Discord无法读取未定义 Discord 的属性“角色”
【发布时间】:2020-08-17 09:21:17
【问题描述】:
    const role = message.guild.roles.cache.find(role => role.name === 'MUTED');
    const member = message.mentions.members.first();


if (message.content.startsWith("https://discord.gg/")){
    message.delete (); 
    ruleBreaker = ruleBreaker + 1;

    if (ruleBreaker < 2){
    message.reply ('Dont even try me. I WILL mute you if you send it again.');
    }
    if (ruleBreaker == 2){
        message.reply("you have been muted for 15 munites.")
        member.roles.add(role);
    }

}

我不断收到错误消息“无法读取 undefines Discord 的属性 'roles'”,此代码直接从 https://discordjs.guide/popular-topics/common-questions.html#legend 复制而来。这几天一直盯着这个。不知道怎么回事。

【问题讨论】:

    标签: javascript discord discord.js roles


    【解决方案1】:

    看起来您从“如何将角色添加到公会成员?”中获取此代码,这与我认为您想要的不太一样。在这里,const member 被发送给消息中提到的第一个人,如果没有提及,则未定义。如果您希望它是发送消息的人,只需使用message.author

    【讨论】:

    • 我这样做了,但现在我收到错误“TypeError: Cannot read property 'add' of undefined”
    • 我做了 const 成员 = message.author
    猜你喜欢
    • 1970-01-01
    • 2019-01-25
    • 2020-12-14
    • 2021-11-01
    • 2018-08-17
    • 1970-01-01
    • 2022-01-13
    • 2020-12-29
    • 2020-08-16
    相关资源
    最近更新 更多