N
N
neekosha2020-12-19 13:56:52
Node.js
neekosha, 2020-12-19 13:56:52

How to send random messages?

I am making a bot that will send a random joke to the chat on command. For example, the !joke command - the bot sends a random one of several jokes that I will ask.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lord_Dantes, 2020-12-19
@Lord_Dantes

Freelancing with this approach to the task

!
! [WINX] KID$AMORT#7911, 2020-12-20
@kidsamort

if (command === 'ping') {
    let arr = new Array();
    arr = []; // создаем масив в который будем записывать что то

    for (i=0; i<15; i++){
      arr.push(i); // цикл для записи в масив 15 элементов
    }

    var rand = Math.round(Math.random()*arr.length); // создаем рандомномный индекс для элементов

    message.channel.send(arr[rand]); // вывод его в чат

my first code on discord.js and on js in principle, so don't kick too much))

A
Alexander, 2021-01-04
@BigTooth

Or you can not invent a bicycle and do this:

const randomJokes = [
        'шутка1',
        'шутка2'
        //и тд.
      ];
      const randomIndex = Math.floor(Math.random() * randomJokes.length);
      const joke = randomJokes[randomIndex];
      message.channel.send(joke);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question