So I have the command -joke
I want the bot to give a random response to that command. How do I add it to this code:
module.exports = {
name: 'joke',
description: "tells a joke",
execute(message, args) {
message.channel.send('Why do we tell actors to break a leg? Because every
play has a cast');
}
}
Use an array to store your jokes.
Assuming your array is called jokes:
const getJoke = () => {
return jokes[Math.floor(Math.random() * jokes.length))];
}
This should then get you a random one from your array. Just send the output of that function to your user
Create an array with jokes:
const jokes = ["Joke1", "Joke2", "Joke3"];
and get a joke from the array at a random index:
const randJoke = jokes[Math.floor(Math.random() * jokes.length)];
then send the random joke in the current text channel:
message.channel.send(randJoke);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.