将 2 JSON 个数组组合成成员角色 (DISCORD.JS)
Combining 2 JSON Arrays into member roles (DISCORD.JS)
我正在尝试从我的配置文件中合并 2 个 JSON 数组以将它们推送到成员角色
JSON 配置
{
"adminRoles": [
"ADMIN",
"LA REINA DE BELLEZA"
],
"moderatorRoles": [
"MODERATOR",
"BOT"
]
}
然后将组合的 2 个数组推入这个
// This command must be limited to mods and admins.
if (!message.member.roles.some(r => [COMBINED_ROLES_HERE].includes(r.name))) {
return message.reply("Sorry, you don't have permissions to use this!");
}
有人能给我指出正确的方向吗?
我试过了
console.log(client.config.adminRoles.concat(client.config.moderatorRoles));
还有 returns
[ "ROLE 1", "ROLE 2" etc... ]
但这不起作用。我也尝试过 .join() 并且可以 return
"ROLE 1", "ROLE 2" etc...
但这也行不通。
const roles = {
"adminRoles": [
"ADMIN",
"LA REINA DE BELLEZA"
],
"moderatorRoles": [
"MODERATOR",
"BOT"
]
}
const message = {
member: {
roles: [
{ name: 'testing 123' }
]
}
};
// then push the combined 2 arrays into this
const combinedRoleNames = Object.keys(roles);
const combineRoles = combinedRoleNames
.map(x => roles[x])
.reduce((acc, curr) => acc.concat(curr), []);
console.log(combinedRoleNames);
console.log(combineRoles);
// if you want to assign to member.roles, uncomment following line
// message.member.roles = combineRoles.map(name => ({ name }));
if (!message.member.roles.some(r => combineRoles.includes(r.name))) {
console.log('sorry');
// return message.reply("Sorry, you don't have permissions to use // this!");
} else {
console.log('found');
}
我正在尝试从我的配置文件中合并 2 个 JSON 数组以将它们推送到成员角色
JSON 配置
{
"adminRoles": [
"ADMIN",
"LA REINA DE BELLEZA"
],
"moderatorRoles": [
"MODERATOR",
"BOT"
]
}
然后将组合的 2 个数组推入这个
// This command must be limited to mods and admins.
if (!message.member.roles.some(r => [COMBINED_ROLES_HERE].includes(r.name))) {
return message.reply("Sorry, you don't have permissions to use this!");
}
有人能给我指出正确的方向吗?
我试过了
console.log(client.config.adminRoles.concat(client.config.moderatorRoles));
还有 returns
[ "ROLE 1", "ROLE 2" etc... ]
但这不起作用。我也尝试过 .join() 并且可以 return
"ROLE 1", "ROLE 2" etc...
但这也行不通。
const roles = {
"adminRoles": [
"ADMIN",
"LA REINA DE BELLEZA"
],
"moderatorRoles": [
"MODERATOR",
"BOT"
]
}
const message = {
member: {
roles: [
{ name: 'testing 123' }
]
}
};
// then push the combined 2 arrays into this
const combinedRoleNames = Object.keys(roles);
const combineRoles = combinedRoleNames
.map(x => roles[x])
.reduce((acc, curr) => acc.concat(curr), []);
console.log(combinedRoleNames);
console.log(combineRoles);
// if you want to assign to member.roles, uncomment following line
// message.member.roles = combineRoles.map(name => ({ name }));
if (!message.member.roles.some(r => combineRoles.includes(r.name))) {
console.log('sorry');
// return message.reply("Sorry, you don't have permissions to use // this!");
} else {
console.log('found');
}