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

159
Vistas
How to use client.on in a JavaScript function?

I am currently using discord.js to develop a discord bot. I wanted to create a function to send a message based on user input.

The code I have is as follows:

function myFunction(keyWord) {
   client.on("messageCreate", myMessage => {
   if (myMessage.content.bot) {
      return
   }
   myMessage.channel.send(keyWord)
   })
}

When I run this function in my code, the code seems to stop at the client.on section. It does not throw an error, it simply does not send the message or run any code beyond the client.on.

I appreciate any help!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

myMessage.content returns a string; you are reading it as an object.

If you want to check if the author is a bot, you would read message.author.bot.

Try the following:

function myFunction(keyWord) {
  client.on('messageCreate', (myMessage) => {
    if (myMessage.author.bot)
      return;

    myMessage.channel.send(keyWord);
  });
}

about 4 years ago · Juan Pablo Isaza 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