IntelliJ event.getmessage() 和 "event" 已识别

IntelliJ event.getmessage() and "event" reconized

我正在学习有关 discord 机器人的教程,但我的响应代码无法正常工作在底部 event.getAuthor().getName() 中的事件是红色的,这里是我的代码

import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;

import javax.security.auth.login.LoginException;
import java.util.Calendar;

public class Main extends ListenerAdpater {
    public static void main(String[] args)  throws LoginException {;

        JDABuilder builder = new JDABuilder(AccountType.BOT);
                String token = "joccjG9PPN1h5F18rwJBNvtZilmhWGH3";
                        builder.setToken(token);
        builder.addEventListeners(new Main());
        builder.build();

        @Override
       public void onMessageReceived (MessageReceivedEvent event)
                System.out.println("We received a message from " +
                        event.getAuthor().getName() + ": " +
                        event.getMessage().getContentDisplay
        );

        if (event.getMessage().getContentRaw().equals ("I am lonely")) {
            event.getChannel().sendMessage("Who isn't?").queue();
        }
    }
}

我不知道你是否需要这个,但这是我的另一段代码

group 'BlueBot'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
  mavenCentral()
  jcenter()
}

dependencies {
  testCompile group: 'junit', name: 'junit', version: '4.12'
  compile 'net.dv8tion:JDA:4.0.0_62'
}

如果你能帮助我,那将非常有帮助

谢谢

这是您的代码的一个工作示例。

  1. 您拼错了 ListenerAdapter class 名称 (ListenerAdpater)。
  2. 您试图从另一个方法 (public static void main)
  3. 中覆盖 supperclass 方法
  4. 您的 onMessageReceived 缺少大括号。

    import net.dv8tion.jda.api.AccountType;
    import net.dv8tion.jda.api.JDABuilder;
    import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
    import net.dv8tion.jda.api.hooks.ListenerAdapter;
    
    import javax.security.auth.login.LoginException;
    
    
    public class Main extends ListenerAdapter {
        public static void main(String[] args) throws LoginException {
            JDABuilder builder = new JDABuilder(AccountType.BOT);
            String token = "joccjG9PPN1h5F18rwJBNvtZilmhWGH3";
            builder.setToken(token);
            builder.addEventListeners(new Main());
            builder.build();
        }
    
        @Override
        public void onMessageReceived(MessageReceivedEvent event) {
            System.out.println("We received a message from " +
                    event.getAuthor().getName() + ": " +
                    event.getMessage().getContentDisplay()
            );
    
            if (event.getMessage().getContentRaw().equals("I am lonely")) {
                event.getChannel().sendMessage("Who isn't?").queue();
            }
        }
    }