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

273
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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