I attempted to create a Discord Bot that randomly selects a joke from a predefined list, but I believe my implementation is incorrect. My bot does not respond to the command !joke, while other straightforward text commands are functioning properly. Here is my code:
const jokes = ['Joke 1', 'Joke 2', 'Joke 3'];
const randomIndex = Math.floor(Math.random() * jokes.length);
client.on('messageCreate', (msg) => {
const randomIndex = Math.floor(Math.random() * jokes.length);
if (msg.content === '!joke') {
msg.reply(jokes[randomIndex]);
}
});
I utilized client functions and a random number generator in JavaScript to develop this bot, but it does not seem to be responding as expected.