I literally only learned js to make a discord bot and i need help

basically im trying to make a bot that uses different sentences depending on the number that is generated with the Math.random method. here is the script,

case 'bedtime':
            if(args[1] === 'story'){
                var random = Math.floor(Math.random() * 3) + 1
                if(random = 3)message.channel.sendMessage('text 1')
                if(random = 2) message.channel.sendMessage('text 2')
                if(random = 1) message.channel.sendMessage('text 3')
                message.channel.sendMessage('not a correct command!')

I know it doesnt look right but i’ve tried many different ways and it still wont work.

The above line will send a random integer from 1 through 3 to the sendMessage method. Then you turn around and have the if statements to send another message?

You are confusing the assignment operator with the equality operator. See if you can do some research to understand the difference.


Randell is 100% correct. This was my biggest issue when I started JS too… also making Discord/Twitch bot :wink:

I should also note that if you are using Discord,js sendMessage() is deprecated and to use send() ref: https://discord.js.org/#/docs/main/stable/class/ClientUser?scrollTo=sendMessage

thank you, it was a rookies mistake haha