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

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

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 Relatório

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