'Rock Paper Scissor Array Not Working Discord.js V12
I am trying to build an RPS game in my Discord bot. I want to add the functionality that if the word you choose does not exist in the list, it will return a message. This is my code so far:
async execute(message, args, cmd, client, Discord, profileData) {
if (!args.length)
return message.channel.send('To keep it fair, also send your pick!'); //If you don't
//send a second
//argument.
const list = ['rock', 'paper', 'scissor']; // What the bot accepts.
const rps = ['Rock! - ⛰', 'Paper! - 📄', 'Scissor! - ✂']; // Where the bot can
// randomly pick from
const random = rps[Math.floor(Math.random() * rps.length)];
for (var i = 0; i < list.length; i++) {
if (message.content.includes(list[i])) {
// If it does exits,
// just execute the
// command.
message.channel.send(random);
break;
} else {
message.channel.send(`\`${args}\` is not a valid option.`); //Return if the
//argument you are
//sending does not exist
//in the list.
break;
}
}
},
I thought this would work, and already did many other variants of this one. But still, even though for example paper is in the list, it still sends me ".. is not a valid option". It only works with rock. So what I want here is that if you send anything other than the values inside the array, it returns.
To make it short, I have two questions:
- How can I fix this issue?
- If I capitalize the values in the list (
Rock), will it still work if I sendrock?
Here is the link to my problem: https://imgur.com/rhESIZM
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
