Skip to content Skip to sidebar Skip to footer

Random Message Reply Discord.js 2020

I've been trying to put a random reply but the other answers and tutorials I found didn't exactly work. Most of the tutorials have const messages = [ 'seriously?! You thought I

Solution 1:

As Gabriel Andrade said, you need to put the randomMessage constant inside of the execute function. If you don't, the random message will only be evaluated once when you start the bot.

module.exports = {
    name: 'random',
    description: 'random?',
    execute(message, args){
        // Now the randomMessage will be recalculated every time the command is run
        const randomMessage = messages[Math.floor(Math.random() * messages.length)];
        message.channel.send(randomMessage);
    }
}

Post a Comment for "Random Message Reply Discord.js 2020"