我正在制作一个 discord.js 琐事命令。但我不明白。到目前为止一切正常,我想为答案制作一个转换器。喜欢:答案将是一个数字,而不是一个完整的答案。我到处搜索,但我找不到正确的答案。编码:module.exports.run = async (client, message, args) => { request.get("https://opentdb.com/api.php?amount=1&type=multiple", (err, response, body) => { let res = JSON.parse(body) let results = res.results[0] let answers = results.incorrect_answers; answers.push(results.correct_answer) // Pushes the correct answers in the incorrect answers array. // Entity decode loop var i; for (let i = 0; i < answers.length; i++) { entities.decode(answers[i]) } shuffle(answers) // Shuffles the answers in a random order.' console.log(answers) let embed = new Discord.MessageEmbed() .setAuthor(`${message.author.username} trivia vraag`, message.author.displayAvatarURL()) .setTitle(entities.decode(results.question)) .setDescription(`1) ${answers[0]} \n 2) ${answers[1]} \n 3) ${answers[2]} \n4) ${answers[3]}`) .addField("Prijs", `\n ja wat Corona bacteriën.`, true) .addField(`Difficulty`, `\n ${results.difficulty}`, true) .addField(`Categorie`, `\n ${results.category}`, true) message.channel.send(embed) // console.log(results.question) // console.log(results.correct_answer) })}function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; while (0 !== currentIndex) { randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array;}如果有人可以帮助我,请我需要它哈哈如果你不明白,请查看我添加的图片。我收到的 Discord 消息,我想将完整答案转换为数字。亲切的问候,
1 回答
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
我有点困惑,但我想我明白了,
answers.findIndex(f => f === results.correct_answer);
这将基于 0 索引,因此添加 1。
添加回答
举报
0/150
提交
取消