I'm creating a discord bot command and my goal is to detect when an argument to that command is invalid, eg:
I have these games available: "chess" and "tresenraya"
If I put:
!jugar ajedrez = //se ejecuta el ajedrez
but if I put a game that is not defined, I want the bot to give me a response saying that the argument entered is not valid:
!jugar poker
the bot replies that the argument is invalid since "poker" is not listed
This is what I have of code but it does not work for me, anything that I put in the game even if it is listed tells me that it is invalid
const juegos = ['ajedrez', 'tresenraya']
const elegirjuego = args[0]
if(elegirjuego != juegos) return message.reply('Argumentos inválidos!')
You can use the method
includes
just change a part of your code and that's it