2

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);
0

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.