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)
};
添加回答
舉報