Hey everyone! I’m stuck with my Discord bot project. I’ve got it online in my server, but it’s not reacting to any commands. I made a custom command !yata that should send a motivational message, but nothing happens when I type it. Here’s a simplified version of my code:
// Main class
public class DiscordBot {
public static void main(String[] args) {
JDA bot = JDABuilder.createDefault("token").build();
bot.addEventListener(new CommandHandler());
}
}
// Command handler
class CommandHandler extends ListenerAdapter {
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getMessage().getContentRaw().equals("!yata")) {
event.getChannel().sendMessage("Keep pushing forward!").queue();
}
}
}
Am I missing something obvious? Any help would be awesome!
I’ve dealt with similar issues before, and one thing that often gets overlooked is the bot’s activity status. Sometimes, if the bot doesn’t have an activity set, it can appear offline even when it’s actually running. Try adding this to your JDABuilder:
.setActivity(Activity.playing(“Responding to commands”))
Also, double-check your bot’s OAuth2 scopes in the Discord Developer Portal. Make sure you’ve included both ‘bot’ and ‘applications.commands’ scopes when you invited the bot to your server. Without these, your bot might be present but unable to interact properly.
Lastly, if you’re testing in a busy server, your command might be getting lost in the chat. Try creating a dedicated testing channel with slower traffic to isolate any potential issues. Hope this helps you troubleshoot!
hey there! have u checked if the bot has the right permissions in ur server? sometimes that can mess things up. also, maybe try adding some debugging prints in ur code to see if the command is even being detected. good luck with ur bot!
Have you considered enabling intents for your bot? Without the proper intents, your bot might not receive message events. Try modifying your JDABuilder like this:
JDA bot = JDABuilder.createDefault("token")
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
.build();
This enables the message content intent, which is crucial for reading message content. Also, ensure you’ve enabled this intent in the Discord Developer Portal under your bot’s settings. If that doesn’t work, try adding some logging statements in your onMessageReceived method to see if it’s being called at all. This could help pinpoint where the issue lies.