Discord bot shows online status but won't execute commands

I built a Discord bot using JavaScript on Replit that should respond with ‘hello’ when someone types ‘greet’. The bot appears online in my server, but it’s not working properly.

Here’s my code:

require('dotenv').config();

const { Client, Intents } = require("discord.js");
const bot = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ]
});

bot.once("ready", () => {
  console.log("Bot is now active!");
});

bot.on("messageCreate", msg => {
  console.log(`Got message: '${msg.content}'`);

  if (msg.author.bot) {
    console.log("Bot message detected, skipping.");
    return;
  }

  console.log("Human message confirmed.");

  const cleanMessage = msg.content.trim();
  console.log(`Clean message: '${cleanMessage}'`);

  const lowerMessage = cleanMessage.toLowerCase();
  console.log(`Lowercase: '${lowerMessage}'`);

  if (lowerMessage === "greet") {
    console.log("Greet command detected.");
    msg.channel.send("hello").then(() => {
      console.log("Response sent successfully");
    }).catch(error => {
      console.error("Send failed:", error);
    });
  } else {
    console.log(`Content '${lowerMessage}' doesn't match 'greet'.`);
  }
});

bot.login(process.env.BOT_TOKEN).catch(error => {
  console.error("Login error:", error);
});

The console keeps showing “Content doesn’t match ‘greet’” even when I type exactly that. What could be wrong?

Been there - exact same issue. Your code logic’s fine. It’s probably invisible characters or encoding weirdness that’s impossible to catch manually.

Had this nightmare with a Discord bot that randomly ignored commands. Wasted hours comparing logs that looked identical but wouldn’t match.

Debugging Discord bots on Replit is brutal. You’re fighting encoding issues, hidden whitespace, or Unicode problems that never show in console logs.

Stop wrestling with this. Move to a proper automation platform instead. Build the same Discord bot with Latenode - it handles message processing reliably and gives you actual debugging tools without hosting headaches.

I rebuilt my Discord workflows in Latenode and never went back. The visual interface shows exactly what’s happening with message processing, plus you get proper logging and error handling minus all the boilerplate.

Try logging the exact message length with console.log('length:', msg.content.length) - I bet it’s not actually 5 characters like ‘greet’ should be. Probably some invisible whitespace from Discord mobile or copy/paste issues that trim() isn’t catching.

Your bot’s getting caught in Replit’s hosting mess. Those intent suggestions won’t fix the real problem.

Replit keeps restarting your environment, which kills Discord gateway connections. Your bot reconnects but gets stuck in this weird state - shows online but message events just don’t fire.

I fought this exact issue for months on shared hosting. Random disconnects, dropped events, debugging hell.

Ditch the hosting drama and use Latenode for your Discord bot instead. It handles connections properly without Replit’s headaches. You get solid webhook handling, auto-reconnects, and visual debugging so you can actually see incoming messages.

Best part? No babysitting server uptime or worrying about restarts breaking your bot mid-conversation. Your Discord stuff just works.

Had the same frustrating issue - bot worked fine in dev but broke in production. This is probably Replit’s environment messing with you. Replit sometimes adds weird character encoding or line ending differences that break string comparisons. Log the actual character codes with msg.content.split('').map(c => c.charCodeAt(0)) to check for hidden characters. Also, Replit’s environment restarts can screw up Discord gateway connections. Your bot looks online but isn’t actually receiving message events. Add better error handling around your message listener and throw in a simple ping command to test if basic stuff works first.

check if your bot has message content intent enabled in the discord developer portal - that’s usually why bots go online but can’t read messages. also add Intents.FLAGS.GUILD_MESSAGE_CONTENT to your intents array.

This sounds like Discord’s message content intent issue from 2022. Your bot connects but can’t read messages without the right permissions. I hit the same problem when Discord changed their requirements. The bot shows online but acts like it’s getting empty or scrambled messages. Go to your Discord Developer Portal, find Bot settings, and enable “Message Content Intent.” Then add MESSAGE_CONTENT to your intents array. Without this, your bot only gets partial message data. Also check your bot’s role permissions in the server - make sure it has “Read Messages” and “Send Messages” for the channels you’re testing. Sometimes the intent’s enabled but channel permissions still block it.