Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!