Skip to content
Advertisement

Can I randomize message replies? (Discord.js)

What I am trying to do is randomize messages, i don’t know how though. I’ve been using the code:

  client.on('message', msg => {
    if (msg.content === '.Ping') {
       msg.reply('Pong!');
    }
  });

I’m wondering if it is possible to make it send random replies when a command is executed on Discord.

Advertisement

Answer

You can defined list of answer in array and random of one those answer

Ex:

 const answer = ['a', 'b' , 'c'];
 client.on('message', msg => {
    if (msg.content === '.Ping') {
       msg.reply(answer[Math.floor(Math.random() * answer.length)]);
    }
  });

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement