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

523
Vistas
How to detect message content Discord.js?

I am working on a code for a Discord bot for my server, and I'm currently stumped on a magic 8 ball feature, go figure. I'm trying to get it to check if there is a message after the 8 ball command, and if not, send a message to the same channel telling the user to supply it a message to answer.

This is my code:

if (commandName === '8ball') {
          message.author.get(args[0]);
      const message = args.join(' ').slice(0);
      if (message.length < 10) message.channel.reply; 'You need to give me a question to anser, bud.';

      const messages = [
         '8ball messages here'  
      ];
      const pEmbed = new Discord.MessageEmbed()
          .setTimestamp('')
          .setColor(`${bedcolor}`)
          .randomMessage = messages[Math.floor(Math.random() * messages.length)];
      return message.reply(pEmbed);

It returns an error saying it cannot access message before initialization, and is also doesn't embed despite the code being there. I'm new to Javascript and I'm kind of attempting to splice random code together to make it work, so I'm probably doing something very wrong here. I'd appreciate anyone's advice on how to at least make this code function and to learn more about JS so I don't have to 'splice' random code.

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

0

Considering that you are on Discord V13, you would need to do message.channel.send({embeds: [pEmbed]}) for it to function, instead of message.channel.send(pEmbed) its a new feature to the Version 13 addition.

You would also need to do
randomMessage = messages[Math.floor(Math.random() * messages.length)]; and then state .setDescription(`Answer: ${randomMessage}`) as an example

Happy coding! Let me know if you run into issues.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this:

function someFunctionName() {
    var messages = ['...','...']
    return messages[Math.floor(Math.random()*rand.length)];
}

const pEmbed = new Discord.MessageEmbed()
          .setColor(`${bedcolor}`)
          .setDescription(someFunctionName())
      return message.reply(pEmbed);
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