I have a weird issue with my Discord bot. When I type >test command for the first time, the bot replies with “working” as expected. However, if I try to use the same command again, nothing happens. The bot just ignores my message completely. It seems like the bot stops listening to messages after responding once. What could be causing this behavior and how can I fix it?
Found your problem. You’re using bot.once('message', ...) instead of bot.on('message', ...). The once method only fires one time, then stops listening.
Change this:
bot.once('message', msg => {
To this:
bot.on('message', msg => {
That’ll fix it. But heads up - Discord bots get messy quick once you add more features, error handling, and integrations.
I’ve had way better luck with automation platforms for Discord bots. You get visual workflows, built-in error handling, and easier maintenance. Plus connecting to other services doesn’t require writing tons of code.
You can set up triggers that respond to Discord messages, run them through different logic branches, and connect to databases or APIs automatically. Makes everything more reliable and scalable.
You’re using bot.once() instead of bot.on() for the message event. That’s your problem. The once method only fires once, so your bot dies after the first command.
I made this exact mistake when I started with Discord.js. Wasted an hour debugging it. You’ll also want to add basic validation so the bot doesn’t respond to itself or messages without your prefix. Weird stuff happens otherwise.
Just add if (msg.author.bot) return; and if (!msg.content.startsWith(cmdPrefix)) return; at the start of your message handler. Trust me - bots responding to themselves can create infinite loops.
It’s definitely the once vs on issue. I made this exact mistake on my first bot and spent way too long debugging it. once only fires one time, then removes itself from the event queue.
Also, add a prefix check before processing messages. Right now your bot tries to parse every message it sees, which kills performance and causes weird behavior. Just throw if (!msg.content.startsWith(cmdPrefix)) return; at the top of your handler.
Your switch statement is missing a default case too - any command that isn’t ‘test’ just fails silently. I’d add some basic logging so you can see what commands people are trying.
Indeed, the issue is with the once event listener as mentioned previously. I encountered the same problem last year and spent countless hours debugging before realizing the mistake. Once you switch to on, consider implementing error handling around your switch statement. My bot used to crash without any notifications on edge cases, and it was a tough lesson learned. Additionally, make sure to check if the message begins with your designated prefix before processing it. During development, I recommend adding console logging within your message handler; this way, you can see precisely when it triggers, making debugging far more manageable.
Yeah, once vs on - that’s your problem right there. Your bot stops listening after the first message.
Honest truth? Discord bots are a pain to maintain. I’ve built tons and they always turn into a mess. Event handlers, error cases, rate limits - it becomes a nightmare real quick.
I switched to automation platforms and never went back. Visual workflows show you exactly what happens when someone messages. No more debugging listeners or dealing with crashes.
You set up Discord triggers that parse commands, route through different logic, and connect to databases/APIs without writing connection code. Built-in retry logic and error handling too.
Way cleaner than wrestling with JavaScript. What used to take hours now takes 10 minutes.
The problem is bot.once('message', ...) - that only runs once. Switch it to bot.on('message', ...) and your bot will keep responding. I made this same mistake my first week with Discord.js and felt like an idiot. Your code processes every message in channels where the bot has access, even ones without your prefix. That’s wasted processing. I always check the prefix first thing in the handler to avoid this. Your switch statement’s missing a break in the ‘test’ case. JavaScript won’t care, but it’s good practice to add breaks even on the last case for when you add more later.
yeah, it’s the once issue everyone mentioned. had the same problem when i started with bots. you’re also missing error handling - what happens if someone just sends > with nothing after? it’ll crash. add a check for empty commands before your switch statement.