Java Discord API 命令不打印

Java Discord API commands printing nothing

所以我对这个 JDA 库非常陌生,但我很精通 Java。我似乎无法找出为什么以下代码不起作用。我有一个 Init class 和一个命令 class.

初始化class:

package corp.vjz.bots.discord.testbot;

import javax.security.auth.login.LoginException;

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


public class Initialize {
    
    public static void main(String[] args) throws LoginException {
        
        //starts the discord robot
        JDA jda = JDABuilder.createDefault("NzIyMTMyNjczOTkyMzI3MzEw.Xueodg.EpeszQDFxc1IM21_CZmKMUv7Wys").build();
        
        //sets the status of the discord robot
        jda.getPresence().setStatus(OnlineStatus.ONLINE);
        
        //add a new event listener
        jda.addEventListener(new Commands());
    }
}

这是我的命令class:

package corp.vjz.bots.discord.testbot;

import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;


public class Commands extends ListenerAdapter {
    
    private static String PREFIX = "-";
    
    public void onGuildMsgReceived(GuildMessageReceivedEvent event) {
        
        //parse through message
        String[] args = event.getMessage().getContentRaw().split("\s+");

        if (args[0].equalsIgnoreCase(Commands.PREFIX + "info")) {
            event.getChannel().sendTyping().queue();
            event.getChannel().sendMessage("Wassup! BRO.").queue();
            
        }
    }
}

这应该是“Wassup!兄弟。”每当用户聊天“-info”但实际上没有任何显示。是的,我确实邀请了 discord 机器人并做了 Oauth2 等等,结果很好,只是我不知道为什么它不打印它应该打印的内容。

您没有为 if 命令编写 else 代码;

您没有覆盖 ListenerAdapter 中的方法。引用自the troubleshooting guide

4. You did not override the correct method?
Use @Override and see if it fails. Your method has to use the correct name and parameter list defined in ListenerAdapter. Read More.

因此 ListenerAdapter javadoc 中记录了正确的方法名称,即 onGuildMessageReceived