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

521
Views
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 answers
Answer question

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 Report

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