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

161
Views
¿Puede msg.content ser igual a una variable?

Soy nuevo en escribir discord.js y primero no sé si esta es una pregunta estúpida, pero la pregunta es que quiero hacer un bot para que la primera sección sea un saludo:

 //greetings const random_greeting = () =>{ return Math.floor(Math.random() * 5); } client.on('messageCreate', msg=>{ if(msg.author == client.user) return; let greeting = ['Hi', 'Yo', 'Hello', '👋👋', 'Ok...',] if (msg.content === 'hi'){ msg.reply(greeting[random_greeting()])} if (msg.content === 'hello'){ msg.reply(greeting[random_greeting()])} if (msg.content === 'yo'){ msg.reply(greeting[random_greeting()])} if (msg.content === 'sup'){ msg.reply(greeting[random_greeting()])} if (msg.content === 'wassup'){ msg.reply(greeting[random_greeting()])} if (msg.content === 'yo'){ msg.reply(greeting[random_greeting()])} })

Como puedes ver, necesito escribir:

 if (msg.content === 'hello'){ msg.reply(greeting[random_greeting()])}

y sigo enviándolo como 6 veces, así que mi pregunta, ¿hay alguna forma de hacerlo más corto o más rápido?

He intentado algo como agregar la variable saludorespuesta:

 let greetingAns = ['hi', 'hello']

pero cuando usé

 const random_greeting = () =>{ return Math.floor(Math.random() * 5); } client.on('messageCreate', msg=>{ if(msg.author == client.user) return; let greeting = ['Hi', 'Yo', 'Hello', '👋👋', 'Ok...',] let greetingAns = ['hi', 'hello'] if (msg.content === greetingAns()){ msg.reply(greeting[random_greeting()])}

Creo que debería funcionar pero no es así. Entonces, ¿ msg.content === es una variable?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sí, puede hacer eso y necesitará usar una matriz de cadenas como ya lo hizo. Entonces, para verificar si el contenido del mensaje se encuentra en la matriz, se necesitará el método javascript include () .

Como esto:

 if (greetingAns.includes(msg.content)) { msg.reply(greeting[random_greeting()]); }
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!