Discord bot not responding when selecting random item from array - what am I missing?

I’m working on a Discord bot that should pick a random funny quote from an array and send it back when someone types a specific command. The bot works fine for my other basic commands but this one isn’t working at all.

const funnyQuotes = ['Quote1','Quote2','Quote3']
const randomIndex = Math.floor(Math.random() * funnyQuotes.length);

client.on('messageCreate', (msg) => {
    const funnyQuotes = ['Quote1','Quote2','Quote3']
    const randomIndex = Math.floor(Math.random() * funnyQuotes.length);
    if (msg.content === '!quote') {
        msg.reply(funnyQuotes[randomIndex]);
    }
});

When I type !quote in the chat, nothing happens. My other simple commands that just reply with text work perfectly. I think there might be something wrong with how I’m using the reply method or maybe the random selection logic. Any ideas what could be causing this issue?

totally agree, enabling the message content intent is crucial! without it, your bot won’t see those messages. check that in your dev portal settings, then it should work fine. let us know if you need more help!

quick sanity check - add console.log(‘bot received message:’, msg.content) at the start of your messageCreate handler. if that doesn’t log anything when you type, it’s def the message content intent issue like others mentioned. also check there aren’t extra spaces around !quote.

Your code’s fine - this is definitely a permissions problem. Check that MESSAGE_CONTENT_INTENT is enabled in your Discord Developer Portal under the Bot section. Without it, your bot can’t read messages in API v14+. Also make sure your bot has “Send Messages” and “Read Message History” permissions in that channel. I had this exact same issue when I upgraded last year - wasted hours debugging code when I just forgot the intents. Your random array and reply setup works great.

Had the same issue with my first Discord bot. Others covered the intent problems, but also check if your bot token’s set right and the bot’s actually online in your server. Sometimes it looks online but isn’t fully connected. Make sure your command prefix is correct too - Discord’s picky about spaces and special characters. Add a console.log inside your messageCreate event to see if it fires when you type messages. No logs? It’s the message content intent. Getting logs but no response? Check your console for error messages that’ll tell you what’s breaking.

Others covered the intent issue, but I’d go a different route entirely. Skip the Discord bot hosting, permissions, and maintenance headaches - just automate it.

I built something similar with Latenode that watches Discord messages via webhooks and auto-responds. No server management, no intent config nightmares, and you can easily expand it to pull quotes from databases or APIs instead of hardcoded arrays.

Best part? Set up triggers for multiple Discord servers at once, add scheduled quote posting, or integrate with external quote APIs. Takes 10 minutes vs hours debugging Discord permissions.

When you want features like user preferences or quote categories later, it’s visual workflow building instead of more code to maintain.

Check it out: https://latenode.com