所以我從單個 STAFF 命令(例如if(message.member.roles.cache.has(staff_id)))切換到更靈活的方法 - 如果成員具有幫助者或 mod 或管理員角色等。我使用some了這樣的陣列方法:
const roles = [
"859471924753072188",
"836214627243262002",
"922170188089139261",
"836214626923315221",
"922170903394127873",
"859878718599987200",
"836214626617655296"
]
const isntStaff = roles.some(r => !message.member.roles.cache.has(r))
現在每當我在某些代碼中使用它時,例如在這個代碼中:
...
if (
rudeWords.some(word =>
message
.toString()
.toLowerCase()
.includes(word)
) &&
isntStaff
) {
message.delete({ reason: `Blacklisted Word Detected` });
message.channel
.send({ content: `${message.author}, do not use that word here, thank you.` })
.then(msg => {
setTimeout(() => msg.delete(), 3000)
})
即使我有 helper 或 mod 或 admin 命令,它也不允許我使用這個詞。它也不會在控制臺中記錄任何內容。
uj5u.com熱心網友回復:
您的代碼需要這些角色中的每一個。您正在檢查該陣列中是否有任何不在成員角色快取中的角色。相反,把它!放在外面
const roles = [
"859471924753072188",
"836214627243262002",
"922170188089139261",
"836214626923315221",
"922170903394127873",
"859878718599987200",
"836214626617655296"
]
const isntStaff = !roles.some(r => message.member.roles.cache.has(r))
uj5u.com熱心網友回復:
根據這個Discord.js 指南,還有另一種方法可以做到這一點。
這是您如何執行此操作的示例:
// Check if they have one of many roles
const roles = [
"859471924753072188",
"836214627243262002",
"922170188089139261",
"836214626923315221",
"922170903394127873",
"859878718599987200",
"836214626617655296"
]
if (message.member.roles.cache.some(r => roles.includes(r.id)) ) {
// has one of the roles
}else {
// has none of the roles
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/388221.html
標籤:javascript 节点.js 不和谐 不和谐.js 机器人
