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

275
Views
Detect the @ character or emails in discord.js

I want that when writing an email, the member is given a role in discord. But since I don't know how to do it, I tried this, the issue is that if (message.content === "@"){ only works when I put @, I want it to include @, I couldn't do it with If @ in message.content, nor with neither message.content.startswith nor contains

FULL CODE

const Discord = require("discord.js");
const client = new Discord.Client();
const mySecret = process.env['token']

client.on("ready", () => {
    console.log("ready");
 });
 
client.on("message", message => {
  if(message.channel.id === "963510775215968266"){
    if(message.author.bot) return;
    
    if (message.content === "@"){
      message.member.roles.add("963515178174021642");
      message.author.send("Gracias por verificarte");
      message.delete();
    }
    else{
      message.author.send("¿Tienes problemas? Comunicate con un staff.");
      message.delete();
    }
  }
});

 
 client.login(mySecret);

If someone can give me a hand I would really appreciate it, I've been reading different pages for hours and I can't find the solution, or I just don't know how to apply it well

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Use .includes()

const Discord = require("discord.js");
const client = new Discord.Client();
const mySecret = process.env['token']

client.on("ready", () => {
    console.log("ready");
 });
 
client.on("message", message => {
  if(message.channel.id === "963510775215968266"){
    if(message.author.bot) return;
    
    if (message.content.includes("@")){
      message.member.roles.add("963515178174021642");
      message.author.send("Gracias por verificarte");
      message.delete();
    }
    else{
      message.author.send("¿Tienes problemas? Comunicate con un staff.");
      message.delete();
    }
  }
});

 
 client.login(mySecret);
about 4 years ago · Santiago Gelvez Report

0

In Python you can check if a substring is present with the in operator.

In this case you can check for an "@" with:

if "@" in "my.email@example.com":
    print("String contains the @ character")

However, this is not a good way to do it, as any string with an "@" would be considered an E-mail. A better way to check for an email is to use regular expressions or the built-in parseaddr(address) util.

In javascript (as your example) the method you're looking for is String.prototype.includes().

Example:

if ("my.email@example.com".includes("@")) {
  // your logic here
}

But here we have the same problem explained previously, and regex is a much better option (as already answered here)

about 4 years ago · Santiago Gelvez 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!