I’m working on a Discord bot that should pick a random quote from an array and send it back when someone uses a command. The bot works fine with other basic commands but it’s not responding to this specific one. I think there might be an issue with how I’m handling the random selection or the reply method.
I expected the bot to respond with a random quote when I type the command, but nothing happens. Other simple commands work perfectly. Any ideas what I’m doing wrong here?
The code logic looks fine for random selection, so something else is wrong. First, check if your bot has message content intent enabled in the Discord Developer Portal - bots need this to read message content. Without it, msg.content stays empty and your command won’t work. Also make sure the bot can send messages in that channel. Add a console.log right before the if statement to see what msg.content actually shows when you send the command. I hit this exact problem when Discord changed their intent requirements and wasted hours debugging before I realized the bot couldn’t read messages.
your code looks good, but first check if the bot’s actually online. add console.log(‘bot is ready’) to your ready event to confirm. also make sure you don’t have multiple messageCreate listeners running - that’ll cause problems. the random selection part works fine tho!
Check if your bot’s filtering out its own messages or other bots. You’ll want if (msg.author.bot) return; at the top of your messageCreate handler to avoid loops, but make sure you’re not blocking your test messages by accident. Also verify the bot has Send Messages permission in that specific channel - I’ve seen tons of cases where bots work fine in DMs but fail in servers because of role restrictions. Try DMing the bot first to figure out if it’s permissions or your code that’s broken.