Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda