-1

I have no clue how to make the bot give out a random response. My commands will have at least 6 random responses and as I said, I have no clue how to code it. I haven't tried anything yet.

module.exports = {
    name: 'random',
    description: "random responses",
    execute(message, args) {
      
    }
}
Jakye
  • 6,440
  • 3
  • 19
  • 38
  • 1
    Does this answer your question? [How can I make a random response in Discord.js](https://stackoverflow.com/questions/63894234/how-can-i-make-a-random-response-in-discord-js) – Jakye Sep 19 '20 at 19:23
  • You need to research and attempt your goal before asking for help – Elitezen Sep 19 '20 at 20:30

1 Answers1

0

You mean, you want to respond anything? You could call Math.random() function, get any number, stringify and just message.reply(x) where x is your random number.

Also you could use random-text-generator module from npm and for example reply with american city or something like: New York, Los Angeles etc. You only need to install this module.

Remember to call random function every time like this:

module.exports = {
    name: 'random',
    description: "random responses",
    execute(message, args) {
    message.reply(Math.random().toString());
    }
}

If you want random response from array like: cities=["New York","Los Angeles","Chicago","Houston","Phoenix","Philadelphia","San Antonio"]

You could do this:

module.exports = {
    name: 'random',
    description: "random responses",
    execute(message, args) {
    let cities=["New York","Los Angeles","Chicago","Houston","Phoenix","Philadelphia","San Antonio"]
    let randomNbr = Math.floor(Math.random() * 6);
    message.reply(cities[randomNbr]);
    }
}
Pan Michal
  • 177
  • 1
  • 3
  • 15