Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
Discord Bot JS - Mail Verification Input

I'm trying to check the input email that the user provides to my discord bot.

What I want to do is to make sure that the format of the email is correct.

-> $email ok@gmail.com

not $email gdfughdfzug

client.on('messageCreate', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;
    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift();
    var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;


    //recuperation email
     if (command === 'email') {
        if (!args.length) {
           return message.channel.send(`Merci de fournire votre email.\nExemple: monEmail@gmail.com !`);           
        }
        if(String(args).value.match(mailformat))
        {
            alert("Valid email address!");
            return message.channel.send(`Merci de nous avoir fournie votre email: ${args}`);    
        }
        
    }


});

In my args variable, I get the parameter after the $email.

But when I run the robot and try to see if it works, I get this error

TypeError : Impossible to read the properties of undefined (read 'match')
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Well you didn't post how you get the arguments from the message. If it's made the same as most bots then it should be an array of strings. I guess you need to check only the first string argument which in this case is the email.

Then you can access it by index 0. And check if the mail is valid like this:

if (args[0].match(mailformat))
    ...
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda