由于某些人使服务器静音,因此我试图发出一个报告命令,以向所有员工发送消息。这个漫游器仅适用于我的服务器,目的是尝试不违背Discord的API。每当我执行命令时,都会在控制台中弹出:
(节点:17644)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“角色” 在Object.module.exports.run(C:\ Users \ myname \ Desktop \ LDU_Bot \ cmds \ report.js:5:35)
代码如下:
module.exports.run = async (Discord, fs, xp, bot, message, args) =>{
var staffID = "503409681876779032";
//console.log(`Staff: ${staff}`);
for (let i = 0; i < message.guild.members.size; i++) {
if (message.guild.members[i].roles.has(staff)) { //Error on this line
message.guild.members[i].user.send(`This is a test for our report command. DM the bot dev if you are not staff.`);
}
}
}
module.exports.help = {
name: "report"
}
该错误表明问题出在第5行,但是我仍然看不到问题,因为从我所看到的情况来看,这是文档所遵循的。
答案 0 :(得分:1)
var staffID = "503409681876779032";
message.guild.members.forEach( (member) => {
if(member.roles.has(staffID)) {
member.send(`This is a test for our report command. DM the bot dev if you are not staff.`);
}
})