-3

I am currently creating a bot for Discord. So far, I have got the bot up, and have it "Online" in my server. I created a custom command named !yata that displays a motivational message after being input. Is there a reason as to why my bot will not pick up commands? When I type in !yata it does not run the command.

Buki.java

package Buki;

import javax.security.auth.login.LoginException;

import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;

public class Buki {
    public static JDA jda;
    public static String prefix = "!";

    //Main method
    public static void main(String[] args) throws LoginException {
    JDA jda = JDABuilder.createDefault("bot token").build();
    
    jda.addEventListener(new Commands());
            
    }
}

Commands.java

package Buki;

import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class Commands extends ListenerAdapter {

    public void onGuildMessageReceived(MessageReceivedEvent e) {
    String[] message = e.getMessage().getContentRaw().split(" ");
            
        if (message[0].equalsIgnoreCase("!yata")) {
            e.getChannel().sendTyping().queue();
            e.getChannel().sendMessage("The road of a ninja is long!").queue();
        }
        else {
        
        }
        
    }

}
2
  • Find out what it does run by debugging and reading the documentation.
    – clwhisk
    Mar 14, 2022 at 1:20
  • Check the troubleshooting guide
    – Minn
    Mar 14, 2022 at 12:28

2 Answers 2

0

First of all, your codes are so weird!

How could the event be called MessageReceivedEvent, meanwhile, the method called onGuildMessageReceivedEvent, JDA already renamed the methods! and second you didn't use the GatewayIntent.GUILD_MESSAGES, so basically, it going to be like this:


JDABuilder jda = JDABuilder.create(token, GatewayIntent.GUILD_MESSAGES);

and third, think is I see you using JDA, not JDABuilder which is wrong, I recommended you to check what version of JDA you use and use the last one!

-1
public void onGuildMessageReceived(MessageReceivedEvent e)

needed to be changed to

public void onMessageReceivedEvent(MessageReceivedEvent e). 

"Guild" was not required in this method's name.

2
  • So why not do as it suggests? Mar 14, 2022 at 1:34
  • @Scary Wombat I found the fix. I posted the answer so it would be known. I implemented it after finding out.
    – R N
    Mar 14, 2022 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.