So i was making a discord bot and decided to implement a simple trivia api, upon returning the results it shows this :
[
{
category: 'Entertainment: Video Games',
type: 'multiple',
difficulty: 'medium',
question: 'What is the main character of Metal Gear Solid 2?',
correct_answer: 'Raiden',
incorrect_answers: [ 'Solidus Snake', 'Big Boss', 'Venom Snake' ]
}
]
since this is my current code
//creates an embed to make it more aestheticaly pleasing
const triviaEmbed = new Discord.MessageEmbed()
.setColor(0x6e7175)
.setTitle('Trivia!')
.addFields({
name: 'Category',
value: triviaValue.results[0].category
}, {
name: 'Type',
value: triviaDisplayType
}, {
name: 'Difficulty',
value: triviaDisplayDifficulty
}, {
name: 'Question',
value: triviaValue.results[0].question
}, {
name: 'Answers',
value: `${triviaValue.results[0].incorrect_answers}, ${triviaValue.results[0].correct_answer}`
})
// sends the embed
message.channel.send(triviaEmbed);
the correct answer will always be the last one, what is the most efficient way to make this process random, the best things i could think of seemed very redundant.