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);
}
}
我不断收到错误消息,“无法读取未定义Discord的属性'roles”,并且此代码直接从https://discordjs.guide/popular-topics/common-questions.html#legend复制而来。一直盯着这几天。我不知道怎么了。
答案 0 :(得分:0)
您似乎从“如何为公会成员添加角色?”中获取了这段代码,但并没有达到我想的那样。在这里,const member
被发送给消息中提到的第一个人,如果没有提及,则未定义。如果您希望它成为发送消息的人,只需使用message.author
。