Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How to get bot to reply to an empty message field? Discord.js

Visionarily

New Coder
Hello, 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:

JavaScript:
if (commandName === '8ball') {
  
  const message = args.join(' ').slice(0);
     if (message.length < 10) 
        return message.reply('You need to supply a question.');

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 message.reply or message.send isn't a function. I'm new to Javascript, 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.
 
The message message.reply isn't a function should be clear. message is a variable of your own definition, why do you think it should have a reply function that you can call? What would you have expected that function to do anyway ? I don't see much of your program logic but should it not just be

if (message.length < 10) return 'You need to supply a question.';
 
Last edited by a moderator:
Back
Top Bottom