Random answers to a single message on discord bot js

Hi guys,

I’m fairly new to programming in js but managed to get a bot online (please bear with me). So this might be really a dumb and simple question but so far neither youtube, nor google or the github search could help me. Believe me I tried every tutorial I found but my bot crashed every time. I surely am missing something obvious here.

I wanted to make bot for my discord channel that reacts to a certain command like “motivate me” with different phrases (let’s say 8). I can’t seem to get it to work though.

This is the code (I tried it with a math.floor, i tired let replies, the bot always crashed):

const Discord = require(‘discord.js’);
const client = new Discord.Client();

client.on(‘ready’, () => {
console.log(‘I am ready!’);


client.on(‘message’, message => {
msg = message.content.toLowerCase();

if (msg === 'hiya') { 



Apart from this file I only have a package.json and Procfile if that’s vital to know.

Would anyone be so kind to tell this absolute noob what to do? I’m going mad for not being able to figure it out! :smiley:

Sorry, your question is a little unclear. Does the source you posted work, or is it the code that is crashing?

Looking at this, your code looks like it is missing the dotenv requirement:


You also don’t mention having the necessary .env file to store your BOT_TOKEN value.

Sorry for stating this unclearly!
This is the code that actually works.

I have the .env file. Sorry for not mentioning! Will add the requirement.

Thank you for replying!

I managed to get this to work in another way! Thank you!