Seth Foreman
Seth Foreman

Reputation: 23

Trying to send a random messages in a Discord bot (javascript)

Basically what I'm trying to do is whenever the person says %message it sends a random message from the list. However, it's just spitting back a number at me, ranging between 1-6, rather than the actual message.

I've tried to figure out what I'm doing wrong by reading similar threads but I'm not having any luck.

Here is my code:

if(command === 'message')
    const messages = [
        'message1', 'message2', 'message3', 'message4', 'message5', 'message6'
    ];

    const random = Math.floor(Math.random() * messages.length);
    message.reply(random);

Upvotes: 2

Views: 256

Answers (2)

user16165663
user16165663

Reputation:

Random is an integer that you are sending. Try message.reply(messages[random])

Upvotes: 1

Matt C.
Matt C.

Reputation: 3290

What you are doing wrong is just sending the random index rather than sending the values of messages at that random index. Here is the fix:

const messages = ['message1', 'message2', 'message3', 'message4', 'message5', 'message6'];
const random = Math.floor(Math.random() * messages.length);
message.reply(messages[random]); // this is what changed

Upvotes: 2

Related Questions