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

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

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

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