1 回答
TA贡献1797条经验 获得超6个赞
Object.entries()
您可以使用和检查值是否正确Array.prototype.find()
const flag = {
flag1: { value: 'test', points: 20 },
flag2: { value: 'test2', points: 30 },
};
module.exports.run = async (client, message) => {
// get the challenge and value using destructuring
let [cmd, challenge, value] = message.content.slice(4).split(' ');
// find the entry with both names matching the names given
const result = Object.entries(flag).find(
([flag, data]) => flag === challenge && data.value === value
);
// provide an error if nothing is found
if (!result)
return message.channel.send('Not a valid value and/or flag');
// do something with the points
console.log(result[1].points)
};
添加回答
举报