簡體   English   中英

如何通過DM向具有特定角色的所有成員發送消息?

[英]How do I send a message to all members with a certain role via DMs?

我正在嘗試執行一個報告命令,由於其中一些使服務器靜音,DM將向所有員工發送一條消息。 這個漫游器僅適用於我的服務器,目的是嘗試不違背Discord的API。 每當我執行命令時,這會在控制台中彈出:

(節點:17644)UnhandledPromiseRejectionWarning:TypeError:無法讀取Object.module.exports.run(C:\\ Users \\ myname \\ Desktop \\ LDU_Bot \\ cmds \\ report.js:5:35)中未定義的屬性'roles'

這是代碼:

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行,但是我仍然看不到問題,因為從我所看到的情況來看,這是按照文檔進行的。

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.`); 
        }
    })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM