1

I am trying to build a random mission selector for my local group's Warhammer 40k Discord.

So far I can out put any mission when the function is called - but I would like users to be able to select parameters to restrict the output to only those mission which match the criteria.

For example - when they type: !mission Combat Patrol- only Battle Size (mission.size) properites which match Combat Patrol should be randomly selected from. Ideally this would work regardless of how many variables are restricted (eg. !mission Combat Patrol BRB, or !mission BRB Combat Patrol would both limit the array search to mission from mission.size Combat Patrol and mission.source BRB). And, if there is no match the option is ignored (eg !mission NotPresent will still choose from all missions, !mission NotPresent Combat Patrol will only show Combat Patrol missions).

Is this possible?

Thanks in advance!

Here is my code so far:

module.exports = { 
    name: 'mission', 
    description: 'Randomly selects a mission', 

     execute(message, args) { 
       let missionArray = [
           {
               name: "Incisive Attack",
               size: "Combat Patrol",
               type: "Eternal War",
               source: "BRB",
               page: "286"
               
           },
           {
            name: "Outriders Attack",
            size: "Combat Patrol",
            type: "Eternal War",
            source: "BRB",
            page: "287"
            
        },
        //more missions go here
        {
            name: "Pathway to Glory",
            size: "Onslaught",
            type: "Eternal War",
            source: "BRB",
            page: "303",
        }
            ]; 
      
            let mission = missionArray[Math.floor(Math.random() * missionArray.length)];
       

       return message.reply(`I have consulted the mission8Ball and you will play:\n**${mission.name}**\nMission Type: ${mission.type}\nBattle Size: ${mission.size}\nSource: ${mission.source}\nPage: ${mission.page}`); 
     }, 
   }; 
Rik Powell
  • 11
  • 1

0 Answers0