我正在尝试创建一个仅适用于某些角色的命令。 我尝试在数组中检查它们,但似乎不起作用。
命令:
const Command = require("../structures/Command.js");
const config = require("../data/config.json");
module.exports = new Command({
name: "test",
description: "test",
async run(message, args, client) {
if (message.author.bot) return;
if (message.member.roles.cache.some(role => role.id === config.adminRoles)) {return message.reply("You have the admin role")} else {message.reply("No")}
}
});
配置.json
{
"token": "token_go_here",
"prefix": "ab!",
"adminRoles": ["931469781234769940","931462231969910794"],
}
最佳答案
您可以使用集合文档中列出的roles.cache.some()
:https://discord.js.org/#/docs/collection/main/class/Collection
if (roles.cache.some(role => config.adminRoles.includes(role.id))) {
// ...
}
关于discord.js - 检查用户是否在角色数组中具有特定角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71625004/