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

274
Views
Detecta el carácter @ o correos electrónicos en discord.js

Quiero que al escribir un correo electrónico, al miembro se le asigne un rol en discordia. Pero como no sé cómo hacerlo, probé esto, el problema es que if (message.content === "@"){ solo funciona cuando pongo @ , quiero que incluya @ , no podría No lo hagas con If @ in message.content , ni tampoco con message.content.startswith ni contains

CÓDIGO COMPLETO

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

si alguien me puede dar una mano se lo agradeceria mucho, llevo horas leyendo diferentes paginas y no encuentro la solucion, o simplemente no se como aplicarla bien

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

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

En Python, puede verificar si una subcadena está presente con el operador in .

En este caso, puede verificar si hay una "@" con:

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

Sin embargo, esta no es una buena forma de hacerlo, ya que cualquier cadena con una "@" se consideraría un correo electrónico. Una mejor manera de buscar un correo electrónico es usar expresiones regulares o la utilidad integrada parseaddr(address) .

En javascript (como su ejemplo), el método que está buscando es String.prototype.includes() .

Ejemplo:

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

Pero aquí tenemos el mismo problema explicado anteriormente, y regex es una opción mucho mejor (como ya se respondió aquí )

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!