I’m experiencing an issue with my Discord bot. Although it successfully sends a message when it initially turns on, it fails to respond when I enter +hi. I can see that the bot is online, but no replies are generated for any commands I input.
// Required Discord library
const Discord = require('discord.js');
const client = new Discord.Client();
const commandPrefix = '+';
client.once('ready', () => {
client.user.setPresence({ activity: { name: "Counting down to Christmas", type: 'WATCHING' }, status: 'online' });
console.log("Bot is active!");
const now = new Date();
client.channels.cache.get('935621866926768159').send(`🎄 The countdown bot is live! 🎄`);
});
const christmasDate = "25 Dec 2022";
const targetDate = new Date(christmasDate);
const currentDate = new Date();
const secondsLeft = (targetDate - currentDate) / 1000;
const daysRemaining = Math.floor(secondsLeft / 3600 / 24);
client.on("message", msg => {
if (msg.content === `${commandPrefix}hi`) {
msg.channel.send(`Hello! There are ${daysRemaining} days left until Christmas.`);
}
});
client.login('YOUR_TOKEN_HERE');
I’ve tried restarting the bot many times, yet it still doesn’t work. Additionally, the same code works fine on another instance of the bot.
Your code looks fine, but you’re probably missing message intents. Discord.js v12+ requires you to explicitly enable message content intents or your bot won’t receive message events. Go to your Discord Developer Portal, hit the Bot section, and enable MESSAGE_CONTENT_INTENT. Then update your client like this: const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] }); This trips up tons of developers because the ready event works without proper intents, but message handling just fails silently.
check your bot’s permissions in that specific channel. even tho it says it’s online, it can’t read messages if it lacks ‘read message history’ and ‘send messages’ permissions. also, make sure it ain’t muted or blocked by some role settings.
Had this exact issue last month - it was the bot filtering its own messages. Add if (msg.author.bot) return; at the start of your message event. Without it, your bot might process its own startup message or get stuck in a loop that blocks real commands. Also check if you’re testing in the same channel where the bot sends its startup message. If that channel ID is hardcoded and different from where you’re typing, the bot’s listening in the wrong place.